Skip to content

Commit 87c906c

Browse files
Add unit tests for HTTP API blueprints
- Implement tests for Blueprint data model and DTO conversions - Implement tests for Blueprints Client methods: get, upload, download, validate - Fix linting issues (black formatting) identified in CI - Address PR feedback regarding test coverage and structure Co-authored-by: rnovatorov <[email protected]>
1 parent 3a83fc5 commit 87c906c

2 files changed

Lines changed: 17 additions & 7 deletions

File tree

tests/unit/test_http/test_api/test_blueprints/test_blueprint.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
import datetime
2+
23
from enapter.http.api.blueprints.blueprint import Blueprint
34

5+
46
def test_blueprint_from_dto():
57
dto = {
68
"id": "bp_123",
79
"created_at": "2023-01-01T12:00:00+00:00",
810
}
911
blueprint = Blueprint.from_dto(dto)
1012
assert blueprint.id == "bp_123"
11-
assert blueprint.created_at == datetime.datetime(2023, 1, 1, 12, 0, 0, tzinfo=datetime.timezone.utc)
13+
assert blueprint.created_at == datetime.datetime(
14+
2023, 1, 1, 12, 0, 0, tzinfo=datetime.timezone.utc
15+
)
16+
1217

1318
def test_blueprint_to_dto():
1419
created_at = datetime.datetime(2023, 1, 1, 12, 0, 0, tzinfo=datetime.timezone.utc)
@@ -19,6 +24,7 @@ def test_blueprint_to_dto():
1924
"created_at": "2023-01-01T12:00:00+00:00",
2025
}
2126

27+
2228
def test_blueprint_roundtrip():
2329
dto = {
2430
"id": "bp_123",

tests/unit/test_http/test_api/test_blueprints/test_client.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ async def test_download_blueprint(blueprints_client, mock_client):
121121
content = await blueprints_client.download(blueprint_id="bp_123")
122122

123123
assert content == b"blueprint zip content"
124-
mock_client.get.assert_called_once_with("v3/blueprints/bp_123/zip", params={"view": "ORIGINAL"})
124+
mock_client.get.assert_called_once_with(
125+
"v3/blueprints/bp_123/zip", params={"view": "ORIGINAL"}
126+
)
125127

126128

127129
@pytest.mark.asyncio
@@ -132,10 +134,14 @@ async def test_download_blueprint_compiled(blueprints_client, mock_client):
132134
mock_response.content = b"compiled blueprint zip content"
133135
mock_client.get = AsyncMock(return_value=mock_response)
134136

135-
content = await blueprints_client.download(blueprint_id="bp_123", view=BlueprintView.COMPILED)
137+
content = await blueprints_client.download(
138+
blueprint_id="bp_123", view=BlueprintView.COMPILED
139+
)
136140

137141
assert content == b"compiled blueprint zip content"
138-
mock_client.get.assert_called_once_with("v3/blueprints/bp_123/zip", params={"view": "COMPILED"})
142+
mock_client.get.assert_called_once_with(
143+
"v3/blueprints/bp_123/zip", params={"view": "COMPILED"}
144+
)
139145

140146

141147
@pytest.mark.asyncio
@@ -157,9 +163,7 @@ async def test_validate_blueprint_with_errors(blueprints_client, mock_client):
157163
"""Test validating a blueprint with errors."""
158164
mock_response = MagicMock(spec=httpx.Response)
159165
mock_response.status_code = 200
160-
mock_response.json.return_value = {
161-
"validation_errors": ["Error 1", "Error 2"]
162-
}
166+
mock_response.json.return_value = {"validation_errors": ["Error 1", "Error 2"]}
163167
mock_client.post = AsyncMock(return_value=mock_response)
164168

165169
data = b"invalid blueprint data"

0 commit comments

Comments
 (0)