Skip to content

Commit

Permalink
Fix is_hidden patch error
Browse files Browse the repository at this point in the history
  • Loading branch information
DaymasS committed Aug 11, 2024
1 parent 67d0b3c commit 00e5a34
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion services_backend/routes/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ def update_button(
raise HTTPException(status_code=404, detail="Category does not exist")
if not button:
raise HTTPException(status_code=404, detail="Button does not exist")
if not any(button_inp.model_dump().values()):
if all(value is None for value in button_inp.model_dump().values()):
raise HTTPException(status_code=400, detail="Empty schema")
if button.category_id != category_id:
raise HTTPException(status_code=404, detail="Button is not this category")
Expand Down
15 changes: 15 additions & 0 deletions tests/api/button.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,21 @@ def test_patch_to_hide_success(client, db_button, db_category):
assert res.json()["view"] == "hidden"


def test_patch_to_unhide_success(client, db_button, db_category):
body = {"is_hidden": True}
res = client.patch(f"/category/{db_category.id}/button/{db_button.id}", data=json.dumps(body))
assert res.status_code == status.HTTP_200_OK
res_body = res.json()
assert res_body["is_hidden"] == True
body["is_hidden"] = False
res = client.patch(f"/category/{db_category.id}/button/{db_button.id}", data=json.dumps(body))
assert res.status_code == status.HTTP_200_OK
res_body = res.json()
assert res_body["name"] == db_button.name
assert res_body["is_hidden"] == False
assert res_body["link"] == db_button.link


def test_delete_hidden_success(client, dbsession, db_button, db_category):
db_button.is_hidden = True
dbsession.commit()
Expand Down

0 comments on commit 00e5a34

Please sign in to comment.