summaryrefslogtreecommitdiffstats
path: root/tests/units/test_0033_post_procedure_add.py
blob: 89a21c7e18cb0da71ae713f50b69f54b9ca7c597 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import requests
import unittest

class TestPostProcedureAddMethods(unittest.TestCase):

    def setUp(self):
        self.url = 'http://localhost:8888/procedure/add'
        self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'}
        self.full_json = { "center": "1",
                           "name": "procedure1",
                           "description": "procedure test",
                           "steps": [ { "command": "wol",
                                        "params": { "type": "broadcast" } },
                                      { "procedure": 22 } ] }
        self.minimal_json = { "center": "1",
                              "name": "procedure2" }
        self.duplicated_procedure_json = { "center": "1",
                                           "name": "repeated_procedure" }

    def test_post(self):
        returned = requests.post(self.url, headers=self.headers,
                                 json=self.full_json)
        self.assertEqual(returned.status_code, 200)

    def test_post_only_required_fields(self):
        returned = requests.post(self.url, headers=self.headers,
                                 json=self.minimal_json)
        self.assertEqual(returned.status_code, 200)

    def test_post_duplicated_procedure(self):
        requests.post(self.url, headers=self.headers,
                                 json=self.duplicated_procedure_json)
        returned = requests.post(self.url, headers=self.headers,
                                 json=self.duplicated_procedure_json)
        self.assertEqual(returned.status_code, 400)

    def test_get(self):
        returned = requests.get(self.url, headers=self.headers)
        self.assertEqual(returned.status_code, 405)

if __name__ == '__main__':
    unittest.main()