Commit 857ebb4c authored by Dimitrios Gogos's avatar Dimitrios Gogos
Browse files

fix: update tests for location retrieval to handle 503 responses when no network adapter is set

parent a71f9a1a
Loading
Loading
Loading
Loading
+11 −15
Original line number Diff line number Diff line
@@ -26,24 +26,20 @@ from conftest import (
# ---------------------------------------------------------------------------

class TestStubMode:
    """When NETWORK_ADAPTER_NAME is not set the controller returns a static stub."""
    """When NETWORK_ADAPTER_NAME is not set the controller returns 503 UNAVAILABLE."""

    def test_returns_200_shape(self, flask_app):
        result = call_retrieve_location(flask_app, PAYLOAD_BY_NAI)
        assert isinstance(result, dict)
        assert "lastLocationTime" in result
        assert "area" in result
    def test_returns_503_when_no_adapter(self, flask_app):
        body, status = call_retrieve_location(flask_app, PAYLOAD_BY_NAI)
        assert status == 503

    def test_stub_area_is_circle(self, flask_app):
        result = call_retrieve_location(flask_app, PAYLOAD_BY_NAI)
        assert result["area"]["areaType"] == "CIRCLE"
    def test_503_body_has_code_unavailable(self, flask_app):
        body, status = call_retrieve_location(flask_app, PAYLOAD_BY_NAI)
        assert body.get("code") == "UNAVAILABLE"

    def test_stub_has_center_and_radius(self, flask_app):
        area = call_retrieve_location(flask_app, PAYLOAD_BY_NAI)["area"]
        assert "center" in area
        assert "latitude" in area["center"]
        assert "longitude" in area["center"]
        assert "radius" in area
    def test_503_body_has_message(self, flask_app):
        body, status = call_retrieve_location(flask_app, PAYLOAD_BY_NAI)
        assert "message" in body
        assert "Network Adapter" in body["message"]

    def test_non_json_returns_400(self, flask_app):
        result = call_retrieve_location_plain_text(flask_app)