summaryrefslogtreecommitdiffstats
path: root/tests/units
diff options
context:
space:
mode:
authorJavier Sánchez Parra <jsanchez@soleta.eu>2021-04-20 11:54:00 +0200
committerOpenGnSys Support Team <soporte-og@soleta.eu>2021-04-20 12:05:42 +0200
commit29e7641e910901e813f5682da677f767a2aea5cc (patch)
tree6cff56ee2a03673d66f9908d09bbf83fe09a8204 /tests/units
parent7d74d42c79fb2747e42b4d9e2743abbc86a5354c (diff)
#915 Add /room/add POST method
Adds POST method to add rooms (labs), required payload parameters are name, netmask and center; any additional attributes are optional. Required JSON: { "center": 0, "name": "classroom10", "netmask": "255.255.255.0" } Full JSON: { "center": 0, "name": "classroom11", "netmask": "255.255.255.0", "group": 0, "location": "First floor", "gateway": "192.168.56.1", "ntp": "hora.cica.es", "dns": "1.1.1.1", "remote": True } This commit also adds unit tests for /room/add POST method.
Diffstat (limited to 'tests/units')
-rw-r--r--tests/units/test_0031_post_room_add.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/units/test_0031_post_room_add.py b/tests/units/test_0031_post_room_add.py
new file mode 100644
index 0000000..3db8c6d
--- /dev/null
+++ b/tests/units/test_0031_post_room_add.py
@@ -0,0 +1,47 @@
+import requests
+import unittest
+
+class TestPostRoomAddMethods(unittest.TestCase):
+
+ def setUp(self):
+ self.url = 'http://localhost:8888/room/add'
+ self.headers = {'Authorization' : '07b3bfe728954619b58f0107ad73acc1'}
+ self.full_json = { "center": 0,
+ "name": "classroom11",
+ "netmask": "255.255.255.0",
+ "group": 0,
+ "location": "First floor",
+ "gateway": "192.168.56.1",
+ "ntp": "hora.cica.es",
+ "dns": "1.1.1.1",
+ "remote": True }
+ self.minimal_json = { "center": 0,
+ "name": "classroom10",
+ "netmask": "255.255.255.0" }
+ self.duplicated_room_json = { "center": 0,
+ "name": "repeated_room",
+ "netmask": "255.255.255.0" }
+
+ 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_room(self):
+ requests.post(self.url, headers=self.headers,
+ json=self.duplicated_room_json)
+ returned = requests.post(self.url, headers=self.headers,
+ json=self.duplicated_room_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()