This repository has been archived by the owner on Apr 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
/
images_tests.py
138 lines (110 loc) · 4.25 KB
/
images_tests.py
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env python
# encoding: utf-8
import mock
from ec2stack.helpers import read_file, generate_signature
from . import Ec2StackAppTestCase
class ImagesTestCase(Ec2StackAppTestCase):
def test_describe_image(self):
data = self.get_example_data()
data['Action'] = 'DescribeImages'
data['Signature'] = generate_signature(data, 'POST', 'localhost')
get = mock.Mock()
get.return_value.text = read_file(
'tests/data/valid_describe_images.json'
)
get.return_value.status_code = 200
with mock.patch('requests.get', get):
response = self.post(
'/',
data=data
)
self.assert_ok(response)
assert 'DescribeImagesResponse' in response.data
def test_describe_image_by_id(self):
data = self.get_example_data()
data['Action'] = 'DescribeImages'
data['ImageId.1'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
data['Signature'] = generate_signature(data, 'POST', 'localhost')
get = mock.Mock()
get.return_value.text = read_file(
'tests/data/valid_describe_images.json'
)
get.return_value.status_code = 200
with mock.patch('requests.get', get):
response = self.post(
'/',
data=data
)
self.assert_ok(response)
assert 'DescribeImagesResponse' in response.data
assert 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d' in response.data
def test_invalid_describe_image_by_id(self):
data = self.get_example_data()
data['Action'] = 'DescribeImages'
data['ImageId.1'] = 'invalid-image-id'
data['Signature'] = generate_signature(data, 'POST', 'localhost')
get = mock.Mock()
get.return_value.text = read_file(
'tests/data/valid_describe_images.json'
)
get.return_value.status_code = 200
with mock.patch('requests.get', get):
response = self.post(
'/',
data=data
)
self.assert_bad_request(response)
assert 'InvalidAMIID.NotFound' in response.data
def test_empty_response_describe_images_by_id(self):
data = self.get_example_data()
data['Action'] = 'DescribeImages'
data['ImageId.1'] = 'invalid-images-id'
data['Signature'] = generate_signature(data, 'POST', 'localhost')
get = mock.Mock()
get.return_value.text = read_file(
'tests/data/empty_describe_images.json'
)
get.return_value.status_code = 200
with mock.patch('requests.get', get):
response = self.post(
'/',
data=data
)
self.assert_bad_request(response)
assert 'InvalidAMIID.NotFound' in response.data
def test_describe_image_attribute(self):
data = self.get_example_data()
data['Action'] = 'DescribeImageAttribute'
data['ImageId'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
data['Attribute'] = 'description'
data['Signature'] = generate_signature(data, 'POST', 'localhost')
get = mock.Mock()
get.return_value.text = read_file(
'tests/data/valid_describe_image.json'
)
get.return_value.status_code = 200
with mock.patch('requests.get', get):
response = self.post(
'/',
data=data
)
self.assert_ok(response)
assert 'DescribeImageAttributeResponse' in response.data
def test_describe_invalid_image_attribute(self):
data = self.get_example_data()
data['Action'] = 'DescribeImageAttribute'
data['ImageId'] = 'a32d70ee-95e4-11e3-b2e4-d19c9d3e5e1d'
data['Attribute'] = 'invalid_attribute'
data['Signature'] = generate_signature(data, 'POST', 'localhost')
get = mock.Mock()
get.return_value.text = read_file(
'tests/data/valid_describe_image.json'
)
get.return_value.status_code = 200
with mock.patch('requests.get', get):
response = self.post(
'/',
data=data
)
self.assert_bad_request(response)
assert 'InvalidParameterValue' in response.data