This repository has been archived by the owner on Apr 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 302
/
test_services.py
194 lines (151 loc) · 7.56 KB
/
test_services.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
try:
import json
except ImportError:
import simplejson as json
from mock import patch
from models import Service, List
from test_api import StashboardTest
class PublicServicesTest(StashboardTest):
def test_get(self):
response = self.get("/api/v1/services")
self.assertEquals(response.status_code, 200)
def test_post(self):
response = self.post("/api/v1/services")
self.assertEquals(response.status_code, 405)
def test_delete(self):
response = self.delete("/api/v1/services")
self.assertEquals(response.status_code, 405)
def test_put(self):
response = self.put("/api/v1/services")
self.assertEquals(response.status_code, 405)
class ServiceInstanceTest(StashboardTest):
def setUp(self):
super(ServiceInstanceTest, self).setUp()
self.service_list = List(slug="foo", name="Foo", description="Bar")
self.service_list.put()
self.service = Service(name="Foo", slug="foo", description="foo")
self.service.put()
@patch("handlers.api.invalidate_cache")
def test_delete_service(self, mock):
response = self.delete("/admin/api/v1/services/foo")
self.assertEquals(response.status_code, 200)
def test_delete_wrong_service(self):
response = self.delete("/admin/api/v1/services/bar")
self.assertEquals(response.status_code, 404)
def test_delete_wrong_version(self):
response = self.delete("/admin/api/foo/services/foo")
self.assertEquals(response.status_code, 404)
def test_post_wrong_service(self):
response = self.post("/admin/api/v1/services/bar")
self.assertEquals(response.status_code, 404)
def test_post_wrong_version(self):
response = self.post("/admin/api/foo/services/foo")
self.assertEquals(response.status_code, 404)
def test_post_update_list(self):
response = self.post("/admin/api/v1/services/foo",
data={"list": "foo"})
print response.content
self.assertEquals(response.headers["Content-Type"], "application/json")
self.assertEquals(response.status_code, 200)
service = Service.get(self.service.key())
self.assertEquals(service.list.name, "Foo")
def test_post_update_desc(self):
response = self.post("/admin/api/v1/services/foo",
data={"description": "hello"})
self.assertEquals(response.headers["Content-Type"], "application/json")
self.assertEquals(response.status_code, 200)
service = Service.get(self.service.key())
self.assertEquals(service.description, "hello")
def test_post_update(self):
response = self.post("/admin/api/v1/services/foo",
data={"name": "bar"})
self.assertEquals(response.headers["Content-Type"], "application/json")
self.assertEquals(response.status_code, 200)
service = Service.get(self.service.key())
self.assertEquals(service.name, "bar")
def test_get_wrong_service(self):
response = self.get("/admin/api/v1/services/bar")
self.assertEquals(response.status_code, 404)
def test_get_wrong_version(self):
response = self.get("/admin/api/foo/services/foo")
self.assertEquals(response.status_code, 404)
def test_get_service(self):
response = self.get("/admin/api/v1/services/foo")
self.assertEquals(response.status_code, 200)
self.assertEquals(response.headers["Content-Type"], "application/json")
class ServicesTest(StashboardTest):
def setUp(self):
super(ServicesTest, self).setUp()
self.service_list = List(slug="foo", name="Foo", description="Bar")
self.service_list.put()
def test_post_wrong_version(self):
response = self.post("/admin/api/foo/services")
self.assertEquals(response.status_code, 404)
self.assertEquals(response.headers["Content-Type"], "application/json")
def test_get_wrong_version(self):
response = self.get("/api/foo/services")
self.assertEquals(response.status_code, 404)
self.assertEquals(response.headers["Content-Type"], "application/json")
def test_get_services_list(self):
"""Services should return a 200 with the proper content type"""
response = self.get("/api/v1/services")
self.assertEquals(response.status_code, 200)
self.assertEquals(response.headers["Content-Type"], "application/json")
def test_create_service_bad_list(self):
"""Services should 201 """
response = self.post("/admin/api/v1/services",
data={"description": "An example service API",
"name": "Some Random Name",
"list": "bar"})
service = json.loads(response.content)
self.assertEquals(response.status_code, 400)
def test_create_service_list(self):
"""Services should 201 """
response = self.post("/admin/api/v1/services",
data={"description": "An example service API",
"name": "Some Random Name",
"list": "foo"})
service = json.loads(response.content)
self.assertEquals(response.status_code, 201)
def test_create_service_name(self):
"""Services should 201 """
response = self.post("/admin/api/v1/services",
data={"description": "An example service API",
"name": "Some Random Name"})
service = json.loads(response.content)
self.assertEquals(response.status_code, 201)
self.assertEquals(service["name"], "Some Random Name")
self.assertEquals(service["description"], "An example service API")
def test_missing_service_name(self):
"""Services should 400 without a name"""
response = self.post("/admin/api/v1/services",
data={"description": "An example service API"})
self.assertEquals(response.status_code, 400)
self.assertEquals(response.headers["Content-Type"], "application/json")
def test_missing_service_description(self):
"""Services should 400 without a description"""
response = self.post("/admin/api/v1/services",
data={"name": "Some Random Name"})
self.assertEquals(response.status_code, 400)
self.assertEquals(response.headers["Content-Type"], "application/json")
def test_missing_service_data(self):
"""Creating a service should 400 without data"""
response = self.post("/admin/api/v1/services")
self.assertEquals(response.status_code, 400)
self.assertEquals(response.headers["Content-Type"], "application/json")
def test_delete(self):
"should return 405 Method Not Allowed"
response = self.delete("/admin/api/v1/services")
self.assertEquals(response.status_code, 405)
self.assertEquals(response.headers["Content-Type"], "application/json")
def test_put(self):
"""Should return 405 Content Length Required"""
response = self.put("/admin/api/v1/services")
self.assertEquals(response.status_code, 405)
self.assertEquals(response.headers["Content-Type"], "application/json")
def test_put_with_data(self):
"""should return 405 Method Not Allowed"""
response = self.put("/admin/api/v1/services",
data={"description": "An example service API"})
self.assertEquals(response.status_code, 405)
self.assertEquals(response.headers["Content-Type"], "application/json")