diff --git a/README.md b/README.md index b614b5b..ad9e755 100644 --- a/README.md +++ b/README.md @@ -163,7 +163,7 @@ at least one test to verify the intended behavior. To run tests locally, execute the test suite using `pytest` with the following command: ```bash -pytest tests/ --cov elmo -s -v +pytest tests/ --cov --cov-branch -vv ``` For a comprehensive test that mirrors the Continuous Integration (CI) environment across all supported Python diff --git a/pyproject.toml b/pyproject.toml index debec61..1d0dee8 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -65,3 +65,8 @@ allow-direct-references = true [tool.pytest.ini_options] pythonpath = "src" + +[tool.coverage.run] +omit = [ + "tests/*", +] diff --git a/src/elmo/api/client.py b/src/elmo/api/client.py index 6815b0d..3023020 100644 --- a/src/elmo/api/client.py +++ b/src/elmo/api/client.py @@ -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() @@ -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 diff --git a/tests/test_client.py b/tests/test_client.py index 902091d..7f2c2a2 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -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 = """ diff --git a/tox.ini b/tox.ini index 40ccea3..6c0f9cb 100644 --- a/tox.ini +++ b/tox.ini @@ -11,7 +11,7 @@ allowlist_externals = pytest deps = -e .[dev] commands = - pytest tests/ --cov elmo -s -v + pytest tests --cov --cov-branch --cov-report=xml -vv [testenv:lint] skip_install = true