Skip to content

Commit

Permalink
Fixes auth tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredbriskman committed May 5, 2018
1 parent 4d3a248 commit 8ed00fb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 6 deletions.
30 changes: 29 additions & 1 deletion tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,43 @@ def test_post(self):
self.assertEqual(response.status_code, 400)
self.assertRegex(flask.json.loads(response.data)['error_message'], r"^ValidationError.*'start'")

def test_post_auth(self):
event = {
'title': 'test_post',
'start': isodate.parse_datetime('2018-05-04T09:00:00')
}
with self.subTest("fails when the client is not authorized"):
# self.cookie_jar.clear() # clear existing auth cookie
response = self.app.post(
'/events/',
data=flask.json.dumps(event),
content_type='application/json',
headers={'X-Forwarded-For': '192.168.1.1'}
headers={
'X-Forwarded-For': '192.168.1.1',
}
)
self.assertEqual(response.status_code, 401)

with self.subTest("succeeds when required fields are present"):
response = self.app.post(
'/events/',
data=flask.json.dumps(event),
content_type='application/json'
)
self.assertEqual(response.status_code, 201)

with self.subTest("Succeededs due to auth cookie"):
# self.cookie_jar.clear() # clear existing auth cookie
response = self.app.post(
'/events/',
data=flask.json.dumps(event),
content_type='application/json',
headers={
'X-Forwarded-For': '192.168.1.1',
}
)
self.assertEqual(response.status_code, 201)

@skip("Unimplemented test")
def test_put(self):
# TODO: test success
Expand Down
34 changes: 29 additions & 5 deletions tests/test_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,42 @@ def test_post(self):
self.assertEqual(response.status_code, 400)
self.assertRegex(flask.json.loads(response.data)['error_message'], r"^ValidationError.*'name'")

with self.subTest("fails when the client is not authorized"):
label = {
'name': 'label-test-2',
}
def test_post_auth(self):
label_noauth = {
'name': 'label-test-notauth',
}
label_success = {
'name': 'label-test-success',
}
label_auth = {
'name': 'label-test-auth',
}
with self.subTest("fails when the client is not yet authorized"):
response = self.app.post(
'/labels/',
data=flask.json.dumps(label),
data=flask.json.dumps(label_noauth),
content_type='application/json',
headers={'X-Forwarded-For': '192.168.1.1'}
)
self.assertEqual(response.status_code, 401)

with self.subTest("succeeds when required fields are present"):
response = self.app.post(
'/labels/',
data=flask.json.dumps(label_success),
content_type='application/json'
)
self.assertEqual(response.status_code, 201)

with self.subTest("succeededs with auth cookie"):
response = self.app.post(
'/labels/',
data=flask.json.dumps(label_auth),
content_type='application/json',
headers={'X-Forwarded-For': '192.168.1.1'}
)
self.assertEqual(response.status_code, 201)

def test_put(self):
# TODO: test success
# TODO: test invalid id
Expand Down

0 comments on commit 8ed00fb

Please sign in to comment.