simple api tests
This commit is contained in:
1 parent
fbbfee8873
commit
f8e615304c
3 files changed
+45
-4
No files matched your search
@@ -24,11 +24,11 @@ def make_automation_router(automations: AutomationManager) -> APIRouter:
|
||||
),
|
||||
)
|
||||
|
||||
@router.post("/")
|
||||
@router.post("")
|
||||
def upsert_auto(body: UpdateAutoRequest):
|
||||
automations.update(body.index, body.data)
|
||||
|
||||
@router.delete("/")
|
||||
@router.delete("")
|
||||
def delete_auto(body: DeleteAutoRequest):
|
||||
try:
|
||||
automations.delete(body.index)
|
||||
|
||||
@@ -84,11 +84,43 @@ class automation_update_tests(BaseTestCase):
|
||||
resp = self.client.post(
|
||||
"/automations",
|
||||
json={
|
||||
"index": 32,
|
||||
"index": 33,
|
||||
"data": AutomationData(metadata=AutomationMetdata(id="testme")).dict(),
|
||||
},
|
||||
)
|
||||
resp = self.client.post("/automations/list", json={"limit": 1, "offset": 32})
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
resp = self.client.post("/automations/list", json={"limit": 1, "offset": 31})
|
||||
data = resp.json()
|
||||
self.assertEqual(data["totalItems"], 32)
|
||||
self.assertEqual(data["data"][0]["metadata"]["id"], "testme")
|
||||
|
||||
def test_update_some(self):
|
||||
resp = self.client.post("/automations/list", json={"limit": 1, "offset": 20})
|
||||
original_auto = resp.json()["data"][0]
|
||||
resp = self.client.post(
|
||||
"/automations",
|
||||
json={
|
||||
"index": 20,
|
||||
"data": AutomationData(metadata=AutomationMetdata(id="testme")).dict(),
|
||||
},
|
||||
)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
resp = self.client.post("/automations/list", json={"limit": 1, "offset": 20})
|
||||
new_auto = resp.json()["data"][0]
|
||||
self.assertNotEqual(original_auto, new_auto)
|
||||
self.assertEqual(AutomationData(metadata=AutomationMetdata(id="testme")).dict(), new_auto)
|
||||
|
||||
|
||||
class automation_delete_tests(BaseTestCase):
|
||||
def test_delete_some(self):
|
||||
resp = self.client.post("/automations/list", json={"limit": 1, "offset": 0})
|
||||
self.assertEqual(resp.json()["totalItems"], 31)
|
||||
resp = self.client.delete(
|
||||
"/automations",
|
||||
json={
|
||||
"index": 20,
|
||||
},
|
||||
)
|
||||
self.assertEqual(resp.status_code, 200)
|
||||
resp = self.client.post("/automations/list", json={"limit": 1, "offset": 0})
|
||||
self.assertEqual(resp.json()["totalItems"], 30)
|
||||
@@ -48,6 +48,15 @@ class manager_tests(TestCase):
|
||||
self.assertIsNotNone(auto)
|
||||
self.assertEqual(auto.metadata.id, "test1") # type: ignore
|
||||
|
||||
def test_create_automation_with_example_folder(self):
|
||||
_, _, manager = get_example_automation_loader()
|
||||
self.assertEqual(manager.get_total_items(), 31)
|
||||
manager.update(32, AutomationData(metadata=AutomationMetdata(id="test1")))
|
||||
auto = manager.get(31)
|
||||
self.assertIsNotNone(auto)
|
||||
self.assertEqual(manager.get_total_items(), 32)
|
||||
self.assertEqual(auto.metadata.id, "test1") # type: ignore
|
||||
|
||||
def test_update_automation(self):
|
||||
_, _, manager = get_dummy_automation_loader(
|
||||
[
|
||||
|
||||
Reference in new issue
Block a user