Skip to content

Commit

Permalink
refactor(API): store query params app_platform & app_page in source f…
Browse files Browse the repository at this point in the history
…ield (#658)
  • Loading branch information
raphodn authored Dec 30, 2024
1 parent eee0b9c commit 96215f4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
4 changes: 4 additions & 0 deletions open_prices/api/locations/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ def test_location_create_with_app_name(self):
("?app_name=", ""),
("?app_name=test app&app_version=", "test app"),
("?app_name=mobile&app_version=1.0", "mobile (1.0)"),
(
"?app_name=web&app_version=&app_page=/prices/add/multiple",
"web - /prices/add/multiple",
),
]
):
with self.subTest(INPUT_OUPUT=(params, result)):
Expand Down
4 changes: 4 additions & 0 deletions open_prices/api/prices/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,10 @@ def test_price_create_with_app_name(self):
("?app_name=", ""),
("?app_name=test app&app_version=", "test app"),
("?app_name=mobile&app_version=1.0", "mobile (1.0)"),
(
"?app_name=web&app_version=&app_page=/prices/add/multiple",
"web - /prices/add/multiple",
),
]:
with self.subTest(INPUT_OUPUT=(params, result)):
response = self.client.post(
Expand Down
4 changes: 4 additions & 0 deletions open_prices/api/proofs/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,10 @@ def test_proof_create_with_app_name(self):
("?app_name=", ""),
("?app_name=test app&app_version=", "test app"),
("?app_name=mobile&app_version=1.0", "mobile (1.0)"),
(
"?app_name=web&app_version=&app_page=/prices/add/multiple",
"web - /prices/add/multiple",
),
]:
with self.subTest(INPUT_OUPUT=(params, result)):
# with empty app_name
Expand Down
8 changes: 7 additions & 1 deletion open_prices/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def get_object_or_drf_404(model, **kwargs):
def get_source_from_request(request):
app_name = request.GET.get("app_name", "API")
app_version = request.GET.get("app_version", "")
app_platform = request.GET.get("app_platform", "")
app_page = request.GET.get("app_page", "")
if app_version:
return f"{app_name} ({app_version})"
app_name += f" ({app_version})"
if app_platform:
app_name += f" ({app_platform})"
if app_page:
app_name += f" - {app_page}"
return app_name

0 comments on commit 96215f4

Please sign in to comment.