Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Jan 22, 2025
1 parent fba0877 commit a5279d1
Showing 1 changed file with 38 additions and 19 deletions.
57 changes: 38 additions & 19 deletions tests/awqms/test_e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ def test_post_awqms_station(sample_station_data):
api_url = url_join(API_BACKEND_URL, "Things")

# Test: Station not found (404) -> should trigger POST
with (patch("userCode.awqms.dag.requests.get") as mock_get,
patch("userCode.awqms.dag.requests.post") as mock_post):
with (
patch("userCode.awqms.dag.requests.get") as mock_get,
patch("userCode.awqms.dag.requests.post") as mock_post,
):
# Mock responses
mock_get.return_value = MagicMock(status_code=404)
mock_post.return_value = MagicMock(ok=True)
Expand All @@ -61,29 +63,35 @@ def test_post_awqms_station(sample_station_data):
post_awqms_station(sample_station_data)

# Assertions
mock_get.assert_called_once_with(f"{api_url}('{sample_station_data.MonitoringLocationId}')")
mock_get.assert_called_once_with(
f"{api_url}('{sample_station_data.MonitoringLocationId}')"
)
mock_post.assert_called_once()

# Test: FROST error (500) -> should raise RuntimeError
with (patch("userCode.awqms.dag.requests.get") as mock_get,
patch("userCode.awqms.dag.requests.post") as mock_post):
with (
patch("userCode.awqms.dag.requests.get") as mock_get,
patch("userCode.awqms.dag.requests.post") as mock_post,
):
# Mock responses
msg = f"Failed checking if station '{sample_station_data.MonitoringLocationId}' exists"
mock_get.return_value = MagicMock(status_code=500,
ok=False,
text=msg)
mock_get.return_value = MagicMock(status_code=500, ok=False, text=msg)

# Run code
with pytest.raises(RuntimeError, match="Failed checking if station.*exists"):
post_awqms_station(sample_station_data)

# Assertions
mock_get.assert_called_once_with(f"{api_url}('{sample_station_data.MonitoringLocationId}')")
mock_get.assert_called_once_with(
f"{api_url}('{sample_station_data.MonitoringLocationId}')"
)
mock_post.assert_not_called()

# Test: Station not found (404) -> failed POST
with (patch("userCode.awqms.dag.requests.get") as mock_get,
patch("userCode.awqms.dag.requests.post") as mock_post):
with (
patch("userCode.awqms.dag.requests.get") as mock_get,
patch("userCode.awqms.dag.requests.post") as mock_post,
):
# Mock responses
mock_get.return_value = MagicMock(status_code=404)
mock_post.return_value = MagicMock(ok=False)
Expand All @@ -93,7 +101,9 @@ def test_post_awqms_station(sample_station_data):
post_awqms_station(sample_station_data)

# Assertions
mock_get.assert_called_once_with(f"{api_url}('{sample_station_data.MonitoringLocationId}')")
mock_get.assert_called_once_with(
f"{api_url}('{sample_station_data.MonitoringLocationId}')"
)
mock_post.assert_called_once()


Expand All @@ -106,8 +116,10 @@ def test_post_awqms_datastreams(sample_datastream):
api_url = url_join(API_BACKEND_URL, "Datastreams")

# Test: Datastream not found (404) -> should trigger POST
with (patch("userCode.awqms.dag.requests.get") as mock_get,
patch("userCode.awqms.dag.requests.post") as mock_post):
with (
patch("userCode.awqms.dag.requests.get") as mock_get,
patch("userCode.awqms.dag.requests.post") as mock_post,
):
# Mock responses
mock_get.return_value = MagicMock(status_code=404)
mock_post.return_value = MagicMock(ok=True)
Expand All @@ -120,10 +132,15 @@ def test_post_awqms_datastreams(sample_datastream):
mock_post.assert_called_once()

# Test: FROST error (500) -> should raise RuntimeError
with (patch("userCode.awqms.dag.requests.get") as mock_get,
patch("userCode.awqms.dag.requests.post") as mock_post):
with (
patch("userCode.awqms.dag.requests.get") as mock_get,
patch("userCode.awqms.dag.requests.post") as mock_post,
):
# Mock responses
mock_get.return_value = MagicMock(status_code=500, ok=False, )
mock_get.return_value = MagicMock(
status_code=500,
ok=False,
)

# Run code
with pytest.raises(RuntimeError):
Expand All @@ -134,8 +151,10 @@ def test_post_awqms_datastreams(sample_datastream):
mock_post.assert_not_called()

# Test: Station not found (404) -> failed POST
with (patch("userCode.awqms.dag.requests.get") as mock_get,
patch("userCode.awqms.dag.requests.post") as mock_post):
with (
patch("userCode.awqms.dag.requests.get") as mock_get,
patch("userCode.awqms.dag.requests.post") as mock_post,
):
# Mock responses
mock_get.return_value = MagicMock(status_code=404)
mock_post.return_value = MagicMock(ok=False)
Expand Down

0 comments on commit a5279d1

Please sign in to comment.