Skip to content

Commit e7ba52f

Browse files
committed
Fixed tests to check if authentication and authorization for ResultBundleResource are correct
- Note, the ResultBundle and ResultBundleResource will be re-written to better match tastypie soon. For now it is possible to upload data via authentication and authorization. Change-Id: If112476f4311358b56e3c7378565e910b9304db2
1 parent 5480f20 commit e7ba52f

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

codespeed/tests/tests_api.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,7 @@ def test_delete(self):
11711171

11721172

11731173
class ResultBundleTestCase(FixtureTestCase):
1174+
"""Test CRUD of results via API"""
11741175

11751176
def setUp(self):
11761177
super(ResultBundleTestCase, self).setUp()
@@ -1320,9 +1321,19 @@ def setUp(self):
13201321

13211322
def test_post_mandatory(self):
13221323
"""Should save a new result with only mandatory data"""
1324+
request = HttpRequest()
1325+
request.user = self.api_user
1326+
1327+
request.user.user_permissions.add(self.add)
1328+
13231329
response = self.client.post('/api/v1/benchmark-result/',
13241330
data=json.dumps(self.data1),
13251331
content_type='application/json')
1332+
self.assertEquals(response.status_code, 401)
1333+
response = self.client.post('/api/v1/benchmark-result/',
1334+
data=json.dumps(self.data1),
1335+
content_type='application/json',
1336+
**self.post_auth)
13261337
self.assertEquals(response.status_code, 201)
13271338
id = response['Location'].rsplit('/', 2)[-2]
13281339
result = Result.objects.get(pk=int(id))
@@ -1332,10 +1343,20 @@ def test_post_mandatory(self):
13321343

13331344
def test_post_all_data(self):
13341345
"""Should save a new result with mandatory and optional data"""
1346+
request = HttpRequest()
1347+
request.user = self.api_user
1348+
1349+
request.user.user_permissions.add(self.add)
1350+
13351351
data = dict(self.data1, **self.data_optional)
13361352
response = self.client.post('/api/v1/benchmark-result/',
13371353
data=json.dumps(data),
13381354
content_type='application/json')
1355+
self.assertEquals(response.status_code, 401)
1356+
response = self.client.post('/api/v1/benchmark-result/',
1357+
data=json.dumps(data),
1358+
content_type='application/json',
1359+
**self.post_auth)
13391360
self.assertEquals(response.status_code, 201)
13401361

13411362
def test_get_one(self):
@@ -1355,4 +1376,3 @@ def test_get_one(self):
13551376
# suite = unittest.TestSuite()
13561377
# suite.addTest(EnvironmentTest())
13571378
# return suite
1358-

0 commit comments

Comments
 (0)