-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtest_images.py
More file actions
63 lines (50 loc) · 1.74 KB
/
test_images.py
File metadata and controls
63 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import json
import responses # https://github.com/getsentry/responses
from responses import matchers
from verda.images import Image, ImagesService
IMAGE_RESPONSE = {
'id': '0888da25-bb0d-41cc-a191-dccae45d96fd',
'name': 'Ubuntu 20.04 + CUDA 11.0',
'details': ['Ubuntu 20.04', 'CUDA 11.0'],
'image_type': 'ubuntu-20.04-cuda-11.0',
}
def test_images(http_client):
# arrange
responses.add(
responses.GET,
http_client._base_url + '/images',
json=[IMAGE_RESPONSE],
status=200,
)
image_service = ImagesService(http_client)
# act
images = image_service.get()
# assert
assert isinstance(images, list)
assert len(images) == 1
assert isinstance(images[0], Image)
assert images[0].id == '0888da25-bb0d-41cc-a191-dccae45d96fd'
assert images[0].name == 'Ubuntu 20.04 + CUDA 11.0'
assert images[0].image_type == 'ubuntu-20.04-cuda-11.0'
assert isinstance(images[0].details, list)
assert images[0].details[0] == 'Ubuntu 20.04'
assert images[0].details[1] == 'CUDA 11.0'
assert json.loads(str(images[0])) == IMAGE_RESPONSE
def test_images_filter_by_instance_type(http_client):
# arrange
responses.add(
responses.GET,
http_client._base_url + '/images',
match=[matchers.query_param_matcher({'instance_type': '1A100.22V'})],
json=[IMAGE_RESPONSE],
status=200,
)
image_service = ImagesService(http_client)
# act
images = image_service.get(instance_type='1A100.22V')
# assert
assert isinstance(images, list)
assert len(images) == 1
assert isinstance(images[0], Image)
assert images[0].id == '0888da25-bb0d-41cc-a191-dccae45d96fd'
assert images[0].image_type == 'ubuntu-20.04-cuda-11.0'