11"""Unit tests for the Blueprints HTTP API client."""
22
3+ import datetime
4+ import io
35import pathlib
46import zipfile
5- import io
6- import datetime
77from unittest .mock import AsyncMock , MagicMock
88
99import httpx
@@ -30,17 +30,16 @@ async def test_get_blueprint(client, mock_httpx_client):
3030 mock_response = MagicMock (spec = httpx .Response )
3131 mock_response .status_code = 200
3232 mock_response .json .return_value = {
33- "blueprint" : {
34- "id" : "bp_123" ,
35- "created_at" : "2024-04-01T12:00:00+00:00"
36- }
33+ "blueprint" : {"id" : "bp_123" , "created_at" : "2024-04-01T12:00:00+00:00" }
3734 }
3835 mock_httpx_client .get = AsyncMock (return_value = mock_response )
3936
4037 blueprint = await client .get ("bp_123" )
4138
4239 assert blueprint .id == "bp_123"
43- assert blueprint .created_at == datetime .datetime .fromisoformat ("2024-04-01T12:00:00+00:00" )
40+ assert blueprint .created_at == datetime .datetime .fromisoformat (
41+ "2024-04-01T12:00:00+00:00"
42+ )
4443 mock_httpx_client .get .assert_called_once_with ("v3/blueprints/bp_123" )
4544
4645
@@ -50,18 +49,17 @@ async def test_upload_data(client, mock_httpx_client):
5049 mock_response = MagicMock (spec = httpx .Response )
5150 mock_response .status_code = 200
5251 mock_response .json .return_value = {
53- "blueprint" : {
54- "id" : "bp_new" ,
55- "created_at" : "2024-04-01T12:00:00+00:00"
56- }
52+ "blueprint" : {"id" : "bp_new" , "created_at" : "2024-04-01T12:00:00+00:00" }
5753 }
5854 mock_httpx_client .post = AsyncMock (return_value = mock_response )
5955
6056 data = b"blueprint content"
6157 blueprint = await client .upload (data )
6258
6359 assert blueprint .id == "bp_new"
64- assert blueprint .created_at == datetime .datetime .fromisoformat ("2024-04-01T12:00:00+00:00" )
60+ assert blueprint .created_at == datetime .datetime .fromisoformat (
61+ "2024-04-01T12:00:00+00:00"
62+ )
6563 mock_httpx_client .post .assert_called_once_with ("v3/blueprints/upload" , content = data )
6664
6765
@@ -71,10 +69,7 @@ async def test_upload_file(client, mock_httpx_client, tmp_path):
7169 mock_response = MagicMock (spec = httpx .Response )
7270 mock_response .status_code = 200
7371 mock_response .json .return_value = {
74- "blueprint" : {
75- "id" : "bp_file" ,
76- "created_at" : "2024-04-01T12:00:00+00:00"
77- }
72+ "blueprint" : {"id" : "bp_file" , "created_at" : "2024-04-01T12:00:00+00:00" }
7873 }
7974 mock_httpx_client .post = AsyncMock (return_value = mock_response )
8075
@@ -84,7 +79,9 @@ async def test_upload_file(client, mock_httpx_client, tmp_path):
8479 blueprint = await client .upload_file (file_path )
8580
8681 assert blueprint .id == "bp_file"
87- mock_httpx_client .post .assert_called_once_with ("v3/blueprints/upload" , content = b"manifest content" )
82+ mock_httpx_client .post .assert_called_once_with (
83+ "v3/blueprints/upload" , content = b"manifest content"
84+ )
8885
8986
9087@pytest .mark .asyncio
@@ -93,10 +90,7 @@ async def test_upload_directory(client, mock_httpx_client, tmp_path):
9390 mock_response = MagicMock (spec = httpx .Response )
9491 mock_response .status_code = 200
9592 mock_response .json .return_value = {
96- "blueprint" : {
97- "id" : "bp_dir" ,
98- "created_at" : "2024-04-01T12:00:00+00:00"
99- }
93+ "blueprint" : {"id" : "bp_dir" , "created_at" : "2024-04-01T12:00:00+00:00" }
10094 }
10195 mock_httpx_client .post = AsyncMock (return_value = mock_response )
10296
@@ -148,7 +142,9 @@ async def test_validate_success(client, mock_httpx_client):
148142
149143 await client .validate (b"blueprint content" )
150144
151- mock_httpx_client .post .assert_called_once_with ("v3/blueprints/validate" , content = b"blueprint content" )
145+ mock_httpx_client .post .assert_called_once_with (
146+ "v3/blueprints/validate" , content = b"blueprint content"
147+ )
152148
153149
154150@pytest .mark .asyncio
@@ -168,7 +164,9 @@ async def test_validate_error(client, mock_httpx_client):
168164 assert len (errors ) == 2
169165 assert errors [0 ].message == "Invalid manifest"
170166 assert errors [1 ].message == "Missing field"
171- mock_httpx_client .post .assert_called_once_with ("v3/blueprints/validate" , content = b"blueprint content" )
167+ mock_httpx_client .post .assert_called_once_with (
168+ "v3/blueprints/validate" , content = b"blueprint content"
169+ )
172170
173171
174172@pytest .mark .asyncio
@@ -184,7 +182,9 @@ async def test_validate_file(client, mock_httpx_client, tmp_path):
184182
185183 await client .validate_file (file_path )
186184
187- mock_httpx_client .post .assert_called_once_with ("v3/blueprints/validate" , content = b"manifest content" )
185+ mock_httpx_client .post .assert_called_once_with (
186+ "v3/blueprints/validate" , content = b"manifest content"
187+ )
188188
189189
190190@pytest .mark .asyncio
0 commit comments