66from .exceptions import CorelliumApiException
77from .types import Device , Instance , Project , Session
88
9+ pytestmark = pytest .mark .anyio
10+
11+
12+ @pytest .fixture
13+ def anyio_backend ():
14+ return "asyncio"
15+
916
1017def fixture (path ):
1118 """
@@ -18,7 +25,7 @@ def fixture(path):
1825 return f .read ()
1926
2027
21- def test_login_ok (requests_mock ):
28+ async def test_login_ok (requests_mock ):
2229 requests_mock .post ("https://api-host/api/v1/auth/login" , text = fixture ("http/login-200.json" ))
2330
2431 api = ApiClient ("api-host" , "api-token" )
@@ -36,7 +43,7 @@ def test_login_ok(requests_mock):
3643 (200 , fixture ("http/json-error.json" ), "Invalid control character at" ),
3744 ],
3845)
39- def test_login_error (requests_mock , status_code , data , msg ):
46+ async def test_login_error (requests_mock , status_code , data , msg ):
4047 requests_mock .post ("https://api-host/api/v1/auth/login" , status_code = status_code , text = data )
4148 api = ApiClient ("api-host" , "api-token" )
4249
@@ -55,7 +62,7 @@ def test_login_error(requests_mock, status_code, data, msg):
5562 ("notfound" , fixture ("http/get-projects-200.json" ), False ),
5663 ],
5764)
58- def test_get_project_ok (requests_mock , project_name , data , has_results ):
65+ async def test_get_project_ok (requests_mock , project_name , data , has_results ):
5966 requests_mock .get ("https://api-host/api/v1/projects" , status_code = 200 , text = data )
6067 api = ApiClient ("api-host" , "api-token" )
6168 api .session = Session ("session-token" , "2022-03-20T01:50:10.000Z" )
@@ -79,7 +86,7 @@ def test_get_project_ok(requests_mock, project_name, data, has_results):
7986 (404 , fixture ("http/get-projects-404.json" ), "" ),
8087 ],
8188)
82- def test_get_project_error (requests_mock , status_code , data , msg ):
89+ async def test_get_project_error (requests_mock , status_code , data , msg ):
8390 requests_mock .get ("https://api-host/api/v1/projects" , status_code = status_code , text = data )
8491 api = ApiClient ("api-host" , "api-token" )
8592 api .session = Session ("session-token" , "2022-03-20T01:50:10.000Z" )
@@ -94,7 +101,7 @@ def test_get_project_error(requests_mock, status_code, data, msg):
94101 "model,data,has_results" ,
95102 [("rpi4b" , fixture ("http/get-models-200.json" ), True ), ("notfound" , fixture ("http/get-models-200.json" ), False )],
96103)
97- def test_get_device_ok (requests_mock , model , data , has_results ):
104+ async def test_get_device_ok (requests_mock , model , data , has_results ):
98105 requests_mock .get ("https://api-host/api/v1/models" , status_code = 200 , text = data )
99106 api = ApiClient ("api-host" , "api-token" )
100107 api .session = Session ("session-token" , "2022-03-20T01:50:10.000Z" )
@@ -114,7 +121,7 @@ def test_get_device_ok(requests_mock, model, data, has_results):
114121 (403 , fixture ("http/403.json" ), "Invalid or missing authorization token" ),
115122 ],
116123)
117- def test_get_device_error (requests_mock , status_code , data , msg ):
124+ async def test_get_device_error (requests_mock , status_code , data , msg ):
118125 requests_mock .get ("https://api-host/api/v1/models" , status_code = status_code , text = data )
119126 api = ApiClient ("api-host" , "api-token" )
120127 api .session = Session ("session-token" , "2022-03-20T01:50:10.000Z" )
@@ -125,7 +132,7 @@ def test_get_device_error(requests_mock, status_code, data, msg):
125132 assert msg in str (e .value )
126133
127134
128- def test_create_instance_ok (requests_mock ):
135+ async def test_create_instance_ok (requests_mock ):
129136 data = fixture ("http/create-instance-200.json" )
130137 requests_mock .post ("https://api-host/api/v1/instances" , status_code = 200 , text = data )
131138 api = ApiClient ("api-host" , "api-token" )
@@ -153,7 +160,7 @@ def test_create_instance_ok(requests_mock):
153160 (400 , fixture ("http/create-instance-400.json" ), "Unsupported device model" ),
154161 ],
155162)
156- def test_create_instance_error (requests_mock , status_code , data , msg ):
163+ async def test_create_instance_error (requests_mock , status_code , data , msg ):
157164 requests_mock .post ("https://api-host/api/v1/instances" , status_code = status_code , text = data )
158165 api = ApiClient ("api-host" , "api-token" )
159166 api .session = Session ("session-token" , "2022-03-20T01:50:10.000Z" )
@@ -173,7 +180,7 @@ def test_create_instance_error(requests_mock, status_code, data, msg):
173180 assert msg in str (e .value )
174181
175182
176- def test_destroy_instance_state_ok (requests_mock ):
183+ async def test_destroy_instance_state_ok (requests_mock ):
177184 instance = Instance (id = "d59db33d-27bd-4b22-878d-49e4758a648e" )
178185
179186 requests_mock .delete (f"https://api-host/api/v1/instances/{ instance .id } " , status_code = 204 , text = "" )
@@ -189,7 +196,7 @@ def test_destroy_instance_state_ok(requests_mock):
189196 (404 , fixture ("http/get-instance-state-404.json" ), "No instance associated with this value" ),
190197 ],
191198)
192- def test_destroy_instance_error (requests_mock , status_code , data , msg ):
199+ async def test_destroy_instance_error (requests_mock , status_code , data , msg ):
193200 instance = Instance (id = "d59db33d-27bd-4b22-878d-49e4758a648e" )
194201
195202 requests_mock .delete (f"https://api-host/api/v1/instances/{ instance .id } " , status_code = status_code , text = data )
0 commit comments