Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ammar92 committed Sep 18, 2024
1 parent b874930 commit 3464ea3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 2 additions & 1 deletion boefjes/boefjes/sql/plugin_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ def update_boefje(self, boefje_id: str, data: dict) -> None:
if instance.static:
raise NotAllowed(f"Plugin with id '{boefje_id}' is static, so updating it is not allowed")

field_mapping = {"boefje_schema": "schema"} # since Boefje.boefje_schema is the same as BoefjeInDB.schema
for key, value in data.items():
setattr(instance, key, value)
setattr(instance, field_mapping.get(key, key), value)

self.session.add(instance)

Expand Down
12 changes: 9 additions & 3 deletions boefjes/tests/integration/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,9 @@ def test_update_boefje_schema(test_client, organisation):
boefje = Boefje(id="test_plugin", name="My test boefje", description="123")
test_client.post(f"/v1/organisations/{organisation.id}/plugins", content=boefje.model_dump_json())

r = test_client.patch(f"/v1/organisations/{organisation.id}/boefjes/{boefje.id}", json={"boefje_schema": {"$schema": 3}})
r = test_client.patch(
f"/v1/organisations/{organisation.id}/boefjes/{boefje.id}", json={"boefje_schema": {"$schema": 3}}
)
assert r.status_code == 400

valid_schema = {
Expand All @@ -151,7 +153,9 @@ def test_update_boefje_schema(test_client, organisation):
},
"required": [],
}
r = test_client.patch(f"/v1/organisations/{organisation.id}/boefjes/{boefje.id}", json={"boefje_schema": valid_schema})
r = test_client.patch(
f"/v1/organisations/{organisation.id}/boefjes/{boefje.id}", json={"boefje_schema": valid_schema}
)
assert r.status_code == 204

schema = test_client.get(f"/v1/organisations/{organisation.id}/plugins/{boefje.id}/schema.json").json()
Expand All @@ -160,7 +164,9 @@ def test_update_boefje_schema(test_client, organisation):
api_boefje = test_client.get(f"/v1/organisations/{organisation.id}/plugins/{boefje.id}").json()
assert api_boefje["boefje_schema"] == valid_schema

r = test_client.patch(f"/v1/organisations/{organisation.id}/boefjes/dns-records", json={"boefje_schema": valid_schema})
r = test_client.patch(
f"/v1/organisations/{organisation.id}/boefjes/dns-records", json={"boefje_schema": valid_schema}
)
assert r.status_code == 404


Expand Down

0 comments on commit 3464ea3

Please sign in to comment.