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 to return OK/200 and an empty result set when no data found #752

Merged
merged 1 commit into from
Jan 4, 2024
Merged
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
2 changes: 2 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Bug fixes

- Fix to return OK/200 and an empty result set when no data found (#720)

### Continuous Integration

### Documentation
Expand Down
14 changes: 4 additions & 10 deletions src/reporter/delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ def delete_entity(entity_id, type_=None, from_date=None, to_date=None):

logging.getLogger(__name__).info("deleted {} entities".format(deleted))
if deleted == 0:
r = {
"error": "Not Found",
"description": "No records were found for such query."
}
return r, 404
r = []
return r, 200

if deleted > 0:
return '{} records successfully deleted.'.format(deleted), 204
Expand Down Expand Up @@ -53,11 +50,8 @@ def delete_entities(entity_type, from_date=None, to_date=None,
logging.getLogger(__name__).info(
"deleted {} entities of type {}".format(deleted, entity_type))
if deleted == 0:
r = {
"error": "Not Found",
"description": "No records were found for such query."
}
return r, 404
r = []
return r, 200

if deleted > 0:
return '{} records successfully deleted.'.format(deleted), 204
7 changes: 2 additions & 5 deletions src/reporter/op.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,9 @@ def query():
logging.getLogger(__name__).info("Query processed successfully")
res.append(entities[0])
else:
r = {
"error": "Not Found",
"description": "No records were found for such query."
}
r = []
logging.getLogger(__name__).info("No value found for query")
return r, 404
return r, 200
return res, 200


Expand Down
7 changes: 2 additions & 5 deletions src/reporter/query_1T1E1A.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,9 @@ def query_1T1E1A(attr_name, # In Path
logging.getLogger(__name__).info("Query processed successfully")
return res

r = {
"error": "Not Found",
"description": "No records were found for such query."
}
r = []
logging.getLogger(__name__).info("No value found for query")
return r, 404
return r, 200


def query_1T1E1A_value(*args, **kwargs):
Expand Down
7 changes: 2 additions & 5 deletions src/reporter/query_1T1ENA.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,9 @@ def query_1T1ENA(entity_id, # In Path
"usage of id and type rather than entityId and entityType from version 0.9")
return res

r = {
"error": "Not Found",
"description": "No records were found for such query."
}
r = []
logging.getLogger(__name__).info("No value found for query")
return r, 404
return r, 200


def query_1T1ENA_value(*args, **kwargs):
Expand Down
7 changes: 2 additions & 5 deletions src/reporter/query_1TNE1A.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,9 @@ def query_1TNE1A(attr_name, # In Path
"usage of id and type rather than entityId and entityType from version 0.9")
return res

r = {
"error": "Not Found",
"description": "No records were found for such query."
}
r = []
logging.getLogger(__name__).info("No value found for query")
return r, 404
return r, 200


def _prepare_response(entities, attr_name, entity_type, entity_ids,
Expand Down
7 changes: 2 additions & 5 deletions src/reporter/query_1TNENA.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,9 @@ def query_1TNENA(entity_type=None, # In Path
"usage of id and type rather than entityId and entityType from version 0.9")
return res

r = {
"error": "Not Found",
"description": "No records were found for such query."
}
r = []
logging.getLogger(__name__).info("No value found for query")
return r, 404
return r, 200


def _prepare_response(entities, attrs, entity_type, entity_ids,
Expand Down
7 changes: 2 additions & 5 deletions src/reporter/query_NTNE.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ def query_NTNE(limit=10000,
logging.getLogger(__name__).info("Query processed successfully")
return res

r = {
"error": "Not Found",
"description": "No records were found for such query."
}
r = []
logging.getLogger(__name__).info("No value found for query")
return r, 404
return r, 200
7 changes: 2 additions & 5 deletions src/reporter/query_NTNE1A.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,9 @@ def query_NTNE1A(attr_name, # In Path
logging.warning(
"usage of id and type rather than entityId and entityType from version 0.9")
return res
r = {
"error": "Not Found",
"description": "No records were found for such query."
}
r = []
logging.getLogger(__name__).info("No value found for query")
return r, 404
return r, 200


def query_NTNE1A_value(*args, **kwargs):
Expand Down
7 changes: 2 additions & 5 deletions src/reporter/query_NTNENA.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,9 @@ def query_NTNENA(id_=None, # In Query
logging.getLogger(__name__).info("AggrMethod cannot be applied")
return r, 404

r = {
"error": "Not Found",
"description": "No records were found for such query."
}
r = []
logging.getLogger(__name__).info("No value found for query")
return r, 404
return r, 200


def query_NTNENA_value(*args, **kwargs):
Expand Down
7 changes: 2 additions & 5 deletions src/reporter/tests/test_1T1E1A.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,11 +437,8 @@ def test_not_found(service):
h = {'Fiware-Service': service}

r = requests.get(query_url(), params=query_params, headers=h)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []


@pytest.mark.parametrize("service", services)
Expand Down
7 changes: 2 additions & 5 deletions src/reporter/tests/test_1T1ENA.py
Original file line number Diff line number Diff line change
Expand Up @@ -642,8 +642,5 @@ def test_not_found(service):
h = {'Fiware-Service': service}

r = requests.get(query_url(), params=query_params, headers=h)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []
14 changes: 4 additions & 10 deletions src/reporter/tests/test_1TNE1A.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,8 @@ def idPattern_not_found(service):
h = {'Fiware-Service': service}

r = requests.get(query_url(), params=query_params, headers=h)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []


@pytest.mark.parametrize("service", services)
Expand Down Expand Up @@ -281,11 +278,8 @@ def test_not_found(service):
h = {'Fiware-Service': service}

r = requests.get(query_url(), params=query_params, headers=h)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []


@pytest.mark.parametrize("service", services)
Expand Down
14 changes: 4 additions & 10 deletions src/reporter/tests/test_1TNENA.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,11 +159,8 @@ def idPattern_not_found(service):
}
h = {'Fiware-Service': service}
r = requests.get(query_url(), params=query_params, headers=h)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []


@pytest.mark.parametrize("service", services)
Expand Down Expand Up @@ -319,11 +316,8 @@ def test_not_found(service):
}
h = {'Fiware-Service': service}
r = requests.get(query_url(), params=query_params, headers=h)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []


@pytest.mark.parametrize("service", services)
Expand Down
7 changes: 3 additions & 4 deletions src/reporter/tests/test_Headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,8 @@ def test_for_invalid_headers(notification):
get_url = "{}/entities/Room0".format(QL_URL)
res_get = requests.get(get_url, headers=HEADERS_INVALID)

assert res_get.status_code == 404
assert res_get.status_code == 200
assert res_get.json() == []

exp_result = {
'description': 'No records were found for such query.',
'error': 'Not Found'}
exp_result = []
assert res_get.json() == exp_result
14 changes: 4 additions & 10 deletions src/reporter/tests/test_NTNE.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,8 @@ def test_not_found(service):
}
h = {'Fiware-Service': service}
r = requests.get(query_url(), params=query_params, headers=h)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []


@pytest.mark.parametrize("service", services)
Expand All @@ -79,11 +76,8 @@ def idpattern_not_found(service):
}
h = {'Fiware-Service': service}
r = requests.get(query_url(), params=query_params, headers=h)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []


@pytest.mark.parametrize("service", services)
Expand Down
14 changes: 4 additions & 10 deletions src/reporter/tests/test_NTNE1A.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,8 @@ def idPattern_not_found(service, reporter_dataset):
}
h = {'Fiware-Service': service}
r = requests.get(query_url(), params=query_params, headers=h)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []


@pytest.mark.parametrize("service", services)
Expand Down Expand Up @@ -308,11 +305,8 @@ def test_not_found(service, reporter_dataset):
}
h = {'Fiware-Service': service}
r = requests.get(query_url(), params=query_params, headers=h)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []


@pytest.mark.parametrize("service", services)
Expand Down
14 changes: 4 additions & 10 deletions src/reporter/tests/test_NTNENA.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,11 +301,8 @@ def idPattern_not_found(service, reporter_dataset):
'idPattern': 'NotThere'
}
r = query(params=query_params, service=service)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []


@pytest.mark.parametrize("service", services)
Expand Down Expand Up @@ -985,11 +982,8 @@ def test_not_found(service, reporter_dataset):
'type': 'NotThere'
}
r = query(params=query_params, service=service)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []


@pytest.mark.parametrize("service", services)
Expand Down
22 changes: 12 additions & 10 deletions src/reporter/tests/test_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def test_delete_entity(service):

# Values are gone
r = requests.get(url, params=params, headers=h)
assert r.status_code == 404, r.text
assert r.status_code == 200, r.text
assert r.json() == []

# But not for other entities of same type
url = '{}/entities/{}'.format(QL_URL, entity_type + '1')
Expand Down Expand Up @@ -111,7 +112,8 @@ def test_delete_entities(service):
for e in range(2):
url = '{}/entities/{}'.format(QL_URL, '{}{}'.format(entity_type, e))
r = requests.get(url, params=params, headers=h)
assert r.status_code == 404, r.text
assert r.status_code == 200, r.text
assert r.json() == []

# But not for entities of other types
url = '{}/entities/{}'.format(QL_URL, 'Room1')
Expand All @@ -136,11 +138,8 @@ def test_not_found(service):
url = '{}/entities/{}'.format(QL_URL, entity_type + '0')

r = requests.delete(url, params=params, headers=h)
assert r.status_code == 404, r.text
assert r.json() == {
"error": "Not Found",
"description": "No records were found for such query."
}
assert r.status_code == 200, r.text
assert r.json() == []


@pytest.mark.parametrize("service", [
Expand Down Expand Up @@ -281,7 +280,8 @@ def test_delete_347():
time.sleep(SLEEP_TIME)
url = '{}/entities/{}'.format(QL_URL, '{}{}'.format(entity_type, 'un3'))
r = requests.get(url, params=params, headers=h)
assert r.status_code == 404, r.text
assert r.status_code == 200, r.text
assert r.json() == []


def test_delete_different_servicepaths():
Expand Down Expand Up @@ -366,7 +366,8 @@ def test_delete_different_servicepaths():
time.sleep(SLEEP_TIME)
url = '{}/entities/{}'.format(QL_URL, 'un3')
r = requests.get(url, params=params, headers=h)
assert r.status_code == 404, r.text
assert r.status_code == 200, r.text
assert r.json() == []


def test_drop_table():
Expand Down Expand Up @@ -448,4 +449,5 @@ def test_drop_table():
time.sleep(SLEEP_TIME)
url = '{}/entities/{}'.format(QL_URL, 'un3')
r = requests.get(url, params=params, headers=h)
assert r.status_code == 404, r.text
assert r.status_code == 200, r.text
assert r.json() == []
Loading
Loading