11import responses # https://github.com/getsentry/responses
2+ from responses import matchers
23
34from verda .images import Image , ImagesService
45
6+ IMAGE_RESPONSE = {
7+ 'id' : '0888da25-bb0d-41cc-a191-dccae45d96fd' ,
8+ 'name' : 'Ubuntu 20.04 + CUDA 11.0' ,
9+ 'details' : ['Ubuntu 20.04' , 'CUDA 11.0' ],
10+ 'image_type' : 'ubuntu-20.04-cuda-11.0' ,
11+ }
12+
513
614def test_images (http_client ):
7- # arrange - add response mock
15+ # arrange
816 responses .add (
917 responses .GET ,
1018 http_client ._base_url + '/images' ,
11- json = [
12- {
13- 'id' : '0888da25-bb0d-41cc-a191-dccae45d96fd' ,
14- 'name' : 'Ubuntu 20.04 + CUDA 11.0' ,
15- 'details' : ['Ubuntu 20.04' , 'CUDA 11.0' ],
16- 'image_type' : 'ubuntu-20.04-cuda-11.0' ,
17- }
18- ],
19+ json = [IMAGE_RESPONSE ],
1920 status = 200 ,
2021 )
2122
@@ -34,4 +35,26 @@ def test_images(http_client):
3435 assert isinstance (images [0 ].details , list )
3536 assert images [0 ].details [0 ] == 'Ubuntu 20.04'
3637 assert images [0 ].details [1 ] == 'CUDA 11.0'
37- assert isinstance (images [0 ].__str__ (), str )
38+
39+
40+ def test_images_filter_by_instance_type (http_client ):
41+ # arrange
42+ responses .add (
43+ responses .GET ,
44+ http_client ._base_url + '/images' ,
45+ match = [matchers .query_param_matcher ({'instance_type' : '1A100.22V' })],
46+ json = [IMAGE_RESPONSE ],
47+ status = 200 ,
48+ )
49+
50+ image_service = ImagesService (http_client )
51+
52+ # act
53+ images = image_service .get (instance_type = '1A100.22V' )
54+
55+ # assert
56+ assert isinstance (images , list )
57+ assert len (images ) == 1
58+ assert isinstance (images [0 ], Image )
59+ assert images [0 ].id == '0888da25-bb0d-41cc-a191-dccae45d96fd'
60+ assert images [0 ].image_type == 'ubuntu-20.04-cuda-11.0'
0 commit comments