Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update website after changing tag value #250

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions folksonomy/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ async def product_tag_update(response: Response,
detail=re.sub(r'.*@@ (.*) @@\n.*$', r'\1', e.pgerror)[:-1],
)
if cur.rowcount == 1:
return "ok"
# Return the updated tag instead of just "ok"
return product_tag
Comment on lines +472 to +473
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a change in the API we must ensure no depending app will crash because of this…

One way to avoid this is to add a parameter to ask for the product_tag as return value, and return "ok" otherwise.

It might be that mobile app only use the response http status code, in which case it is ok, but please ask them first (opening an issue in their github repository).

elif cur.rowcount == 0: # non existing key
raise HTTPException(
status_code=404,
Expand All @@ -492,7 +493,7 @@ async def product_tag_delete(response: Response,
check_owner_user(user, owner, allow_anonymous=False)
k, v = sanitize_data(k, None)
try:
# Setting version to 0, this is seen as a reset,
# Setting version to 0, this is seen as a reset,
# while maintaining history in folksonomy_versions
cur, timing = await db.db_exec(
"""
Expand Down Expand Up @@ -629,4 +630,4 @@ async def pong(response: Response):
"""
cur, timing = await db.db_exec("SELECT current_timestamp AT TIME ZONE 'GMT'",())
pong = await cur.fetchone()
return {"ping": "pong @ %s" % pong[0]}
return {"ping": "pong @ %s" % pong[0]}
9 changes: 7 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,15 +578,20 @@ def test_put_invalid(with_sample):

@pytest.mark.asyncio
async def test_put(with_sample):
with TestClient(app) as client:
headers = {"Authorization": "Bearer foo__Utest-token"}
response = client.put("/product", headers=headers, json={
"product": BARCODE_1, "k": "color", "v": "purple", "version": 2})
"product": BARCODE_1, "k": "color", "v": "purple", "version": 2})
assert response.status_code == 200, f'valid new version should return 200, got {response.status_code} {response.text}'
updated_tag = response.json()
assert updated_tag["v"] == "purple", f'updated value should be "purple", got {updated_tag["v"]}'
await check_tag(BARCODE_1, "color", v="purple", version=2)
# and again
response = client.put("/product", headers=headers, json={
"product": BARCODE_1, "k": "color", "v": "brown", "version": 3})
"product": BARCODE_1, "k": "color", "v": "brown", "version": 3})
assert response.status_code == 200, f'valid new version should return 200, got {response.status_code} {response.text}'
updated_tag = response.json()
assert updated_tag["v"] == "brown", f'updated value should be "brown", got {updated_tag["v"]}'
await check_tag(BARCODE_1, "color", v="brown", version=3)


Expand Down
Loading