1 | import requests |
---|
2 | import unittest |
---|
3 | |
---|
4 | class TestPostProcedureAddMethods(unittest.TestCase): |
---|
5 | |
---|
6 | def setUp(self): |
---|
7 | self.url = 'http://localhost:8888/procedure/add' |
---|
8 | self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'} |
---|
9 | self.full_json = { "center": "1", |
---|
10 | "name": "procedure1", |
---|
11 | "description": "procedure test" } |
---|
12 | self.minimal_json = { "center": "1", |
---|
13 | "name": "procedure2" } |
---|
14 | self.duplicated_procedure_json = { "center": "1", |
---|
15 | "name": "repeated_procedure" } |
---|
16 | |
---|
17 | def test_post(self): |
---|
18 | returned = requests.post(self.url, headers=self.headers, |
---|
19 | json=self.full_json) |
---|
20 | self.assertEqual(returned.status_code, 200) |
---|
21 | |
---|
22 | def test_post_only_required_fields(self): |
---|
23 | returned = requests.post(self.url, headers=self.headers, |
---|
24 | json=self.minimal_json) |
---|
25 | self.assertEqual(returned.status_code, 200) |
---|
26 | |
---|
27 | def test_post_duplicated_procedure(self): |
---|
28 | requests.post(self.url, headers=self.headers, |
---|
29 | json=self.duplicated_procedure_json) |
---|
30 | returned = requests.post(self.url, headers=self.headers, |
---|
31 | json=self.duplicated_procedure_json) |
---|
32 | self.assertEqual(returned.status_code, 400) |
---|
33 | |
---|
34 | def test_get(self): |
---|
35 | returned = requests.get(self.url, headers=self.headers) |
---|
36 | self.assertEqual(returned.status_code, 405) |
---|
37 | |
---|
38 | if __name__ == '__main__': |
---|
39 | unittest.main() |
---|