fix(api): validate nested report fields
This commit is contained in:
1 parent
92171731ae
commit
0aec421ad2
6 files changed
+48
-6
No files matched your search
@@ -117,6 +117,24 @@ class ApiTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(ApiError, "не более 50 котят"):
|
||||
calculate_payload(payload)
|
||||
|
||||
def test_api_rejects_boolean_and_malformed_nested_report_values(self):
|
||||
coaching = {
|
||||
"mode": "coaching", "date": "15.08", "skill": "ЛУ", "start": "11:00", "end": "11:20",
|
||||
"escort_name": "Белка", "escort_id": 1, "kitten_name": "Первый", "kitten_id": 2,
|
||||
"extra_kittens": [{"name": "Второй", "id": True}],
|
||||
}
|
||||
with self.assertRaisesRegex(ApiError, "ID дополнительного котёнка"):
|
||||
calculate_payload(coaching)
|
||||
inspection = {
|
||||
"mode": "inspection", "character_name": "Белка", "character_id": 1,
|
||||
"place": "дупло", "inspections": 1, "resources": [["паутина", True]],
|
||||
}
|
||||
with self.assertRaisesRegex(ApiError, "Количество ресурса"):
|
||||
calculate_payload(inspection)
|
||||
inspection["resources"] = "паутина=1"
|
||||
with self.assertRaisesRegex(ApiError, "resources должно быть списком"):
|
||||
calculate_payload(inspection)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -248,6 +248,8 @@ class ReportTests(unittest.TestCase):
|
||||
def test_inspection_rejects_negative_resources(self):
|
||||
with self.assertRaises(ValueError):
|
||||
InspectionReport("Белка", 1, "дупло", 1, (("вьюнок", -1),))
|
||||
with self.assertRaises(ValueError):
|
||||
InspectionReport("Белка", 1, "дупло", 1, (("вьюнок", True),))
|
||||
|
||||
def test_inspection_resource_aliases_and_typos(self):
|
||||
report = InspectionReport(
|
||||
|
||||
Reference in new issue
Block a user