Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes auth tests #226

Merged
merged 3 commits into from
May 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 28 additions & 2 deletions tests/test_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,41 @@ def test_post(self):
self.assertEqual(response.status_code, 400)
self.assertRegex(flask.json.loads(response.data)['error_message'], r"^ValidationError.*'start'")

with self.subTest("fails when the client is not authorized"):
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 yet authorized"):
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("succeeds due to 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