Page MenuHomePhabricator

AQS 2.0 - Geo Analytics: [Editors_by_country] Request call to the endpoint with invalid activity level return wrong json response
Closed, ResolvedPublicBUG REPORT

Description

Scenario 2:

Testing the endpoint with an invalid activity level

Prod:

import requests

prod_url = 'https://wikimedia.org/api/rest_v1/metrics/editors/by-country/en.wikipedia/50..99-edits/2020/12'

header = {"accept": "application/json",
          "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/104.0.0.0 Safari/537.36"}

response = requests.get(prod_url, headers=header)

print(response.status_code)
print(response.json())

This returns 400 status code and the json:

{'type': 'https://mediawiki.org/wiki/HyperSwitch/errors/bad_request', 'title': 'Invalid parameters', 'method': 'get', 'detail': "data.params['activity-level'] should be equal to one of the allowed values: [5..99-edits, 100..-edits]", 'uri': '/wikimedia.org/v1/metrics/editors/by-country/en.wikipedia/50..99-edits/2020/12'}

Local:

This returns 400 status code and the json error:

Traceback (most recent call last):
  File "/Users/emekachukwukere/PycharmProjects/pythonProject1/venv/lib/python3.9/site-packages/requests/models.py", line 971, in json
    return complexjson.loads(self.text, **kwargs)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/emekachukwukere/PycharmProjects/pythonProject1/editors/test_local_editors_by_country.py", line 14, in <module>
    print(response.json())
  File "/Users/emekachukwukere/PycharmProjects/pythonProject1/venv/lib/python3.9/site-packages/requests/models.py", line 975, in json
    raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Event Timeline

Fixed , added activity level validation . New expected response should be
{"detail":"Activity-level should be equal to one of the allowed values: [5..99-edits, 100..-edits]","method":"get","status":400,"title":"Bad Request","type":"about:blank","uri":"/metrics/editors/by-country/en.wikipedia/50..99-edits/2020/12"}

SGupta-WMF changed the task status from Open to In Progress.Jul 20 2023, 10:02 AM
SGupta-WMF assigned this task to EChukwukere-WMF.
SGupta-WMF edited projects, added AQS2.0 (Sprint 10); removed AQS2.0.

This is now fixed. Invalid activity level returns the below:

{
   "detail":"Activity-level should be equal to one of the allowed values: [5..99-edits, 100..-edits]",
   "method":"get",
   "status":400,
   "title":"Bad Request",
   "type":"about:blank",
   "uri":"/metrics/editors/by-country/en.wikipedia/100..-edits1/2020/12"
}
Sfaci renamed this task from [Editors_by_country] Request call to the endpoint with invalid activity level return wrong json response to AQS 2.0 - Geo Analytics: [Editors_by_country] Request call to the endpoint with invalid activity level return wrong json response.Aug 23 2023, 1:15 PM
VirginiaPoundstone moved this task from DONE to RESOLVED on the AQS2.0 board.