Skip to content

Commit

Permalink
tests: update code to reach 100% code coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
palazzem committed Oct 20, 2023
1 parent b1a72c4 commit 2e013e1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/elmo/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,7 @@ def query(self, query):

_LOGGER.debug(f"Client | Query parsed successfully: {result}")
return result

if query == q.ALERTS:
elif query == q.ALERTS:
try:
# Check if the response has the expected format
msg = response.json()
Expand All @@ -610,3 +609,5 @@ def query(self, query):
_LOGGER.debug(f"Client | Status retrieved: {new_dict}")

return new_dict
else:
raise QueryNotValid() # pragma: no cover
25 changes: 25 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,31 @@ def test_client_query_error(server, mocker):
client.query(query.SECTORS)


def test_client_query_invalid_response(server, mocker):
"""Should raise ParseError if the response doesn't pass the expected parsing."""
html = """[
{
"Active": true,
"ActivePartial": false,
"Max": false,
"Activable": true,
"ActivablePartial": false,
"Id": 1,
"Index": 0,
"Element": 1,
"CommandId": 0,
"InProgress": false
}
]"""
server.add(responses.POST, "https://example.com/api/areas", body=html, status=200)
client = ElmoClient(base_url="https://example.com", domain="domain")
client._session_id = "test"
mocker.patch.object(client, "_get_descriptions")
# Test
with pytest.raises(ParseError):
client.query(query.SECTORS)


def test_client_get_alerts_status(server):
"""Should query a Elmo system to retrieve alerts status."""
html = """
Expand Down

0 comments on commit 2e013e1

Please sign in to comment.