add auth check

This commit is contained in:
2026-08-03 11:16:49 +08:00
parent 6330b99860
commit 92780cedef
18 changed files with 381 additions and 242 deletions
+10 -34
View File
@@ -87,33 +87,23 @@ class IdentificationConfigTests(unittest.TestCase):
def test_download_requests_customer_config_and_validates_it(self):
calls = []
class FakeResponse:
def __init__(self, body=None, text=None):
self.body = body
self.text = text
def raise_for_status(self):
return None
def json(self):
return self.body
requests_module = types.ModuleType("requests")
requests_module.RequestException = Exception
def post(url, json, timeout):
calls.append(("post", url, json, timeout))
return FakeResponse({"success": True, "url": "https://temp/config"})
def device_post(payload, timeout):
calls.append(("device_post", payload, timeout))
return {"success": True, "url": "https://temp/config"}
def get(url, timeout):
calls.append(("get", url, timeout))
return FakeResponse(text=config_csv(VALID_CONFIG))
return types.SimpleNamespace(
text=config_csv(VALID_CONFIG),
raise_for_status=lambda: None
)
requests_module.post = post
requests_module.get = get
api_module = types.ModuleType("api")
api_module.data_record_url = "https://cloud/data_record"
api_module.the_folder = "客户A"
api_module.device_post = device_post
with patch.dict(sys.modules, {
"requests": requests_module,
@@ -122,28 +112,14 @@ class IdentificationConfigTests(unittest.TestCase):
result = download_identification_config(timeout=7)
self.assertEqual(result["repeat"], 2)
self.assertEqual(calls[0], (
"post",
"https://cloud/data_record",
{"type": "getIdentificationConfig", "deviceId": "客户A"},
7,
))
self.assertEqual(calls[0], ("device_post", {"type": "getIdentificationConfig"}, 7))
self.assertEqual(calls[1], ("get", "https://temp/config", 7))
def test_download_reports_cloud_rejection(self):
class FakeResponse:
def raise_for_status(self):
return None
def json(self):
return {"success": False, "errMsg": "配置不存在"}
requests_module = types.ModuleType("requests")
requests_module.RequestException = Exception
requests_module.post = lambda *args, **kwargs: FakeResponse()
api_module = types.ModuleType("api")
api_module.data_record_url = "https://cloud/data_record"
api_module.the_folder = "客户A"
api_module.device_post = lambda *args, **kwargs: {"success": False, "errMsg": "配置不存在"}
with patch.dict(sys.modules, {
"requests": requests_module,