[41fad11] | 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", |
---|
[1fdb7e6] | 11 | "description": "procedure test", |
---|
| 12 | "steps": [ { "command": "wol", |
---|
| 13 | "params": { "type": "broadcast" } }, |
---|
| 14 | { "procedure": 22 } ] } |
---|
[41fad11] | 15 | self.minimal_json = { "center": "1", |
---|
| 16 | "name": "procedure2" } |
---|
| 17 | self.duplicated_procedure_json = { "center": "1", |
---|
| 18 | "name": "repeated_procedure" } |
---|
| 19 | |
---|
| 20 | def test_post(self): |
---|
| 21 | returned = requests.post(self.url, headers=self.headers, |
---|
| 22 | json=self.full_json) |
---|
| 23 | self.assertEqual(returned.status_code, 200) |
---|
| 24 | |
---|
| 25 | def test_post_only_required_fields(self): |
---|
| 26 | returned = requests.post(self.url, headers=self.headers, |
---|
| 27 | json=self.minimal_json) |
---|
| 28 | self.assertEqual(returned.status_code, 200) |
---|
| 29 | |
---|
| 30 | def test_post_duplicated_procedure(self): |
---|
| 31 | requests.post(self.url, headers=self.headers, |
---|
| 32 | json=self.duplicated_procedure_json) |
---|
| 33 | returned = requests.post(self.url, headers=self.headers, |
---|
| 34 | json=self.duplicated_procedure_json) |
---|
| 35 | self.assertEqual(returned.status_code, 400) |
---|
| 36 | |
---|
| 37 | def test_get(self): |
---|
| 38 | returned = requests.get(self.url, headers=self.headers) |
---|
| 39 | self.assertEqual(returned.status_code, 405) |
---|
| 40 | |
---|
| 41 | if __name__ == '__main__': |
---|
| 42 | unittest.main() |
---|