add auth check
This commit is contained in:
@@ -16,26 +16,12 @@ class DeviceHeartbeatTests(unittest.TestCase):
|
||||
def test_sends_current_device_id_to_server(self):
|
||||
calls = []
|
||||
requests_module = types.ModuleType("requests")
|
||||
|
||||
class Response:
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
def json(self):
|
||||
return {"success": True, "lastSeenAt": "2026-07-28T00:00:00.000Z"}
|
||||
|
||||
def post(url, json, timeout):
|
||||
calls.append((url, json, timeout))
|
||||
return Response()
|
||||
|
||||
requests_module.post = post
|
||||
api_module = types.ModuleType("api")
|
||||
api_module.data_record_url = "https://server.example"
|
||||
api_module.the_folder = "company/line"
|
||||
api_module.device_post = lambda payload, timeout=5: (
|
||||
calls.append((payload, timeout)) or {"success": True, "lastSeenAt": "2026-07-28T00:00:00.000Z"}
|
||||
)
|
||||
with patch.dict(sys.modules, {"requests": requests_module, "api": api_module}):
|
||||
timestamp = HEARTBEAT.heartbeat_device(timeout=7)
|
||||
|
||||
self.assertEqual(timestamp, "2026-07-28T00:00:00.000Z")
|
||||
self.assertEqual(calls, [("https://server.example", {
|
||||
"type": "deviceHeartbeat", "deviceId": "company/line"
|
||||
}, 7)])
|
||||
self.assertEqual(calls, [({"type": "deviceHeartbeat"}, 7)])
|
||||
Reference in New Issue
Block a user