[Chaos] Adding unittests to chaos AP

Adding unittests to run on local server before deploying.

BUG=None
TEST= Start local server with 'devapp_server.py app.yaml' then run
'python chaos_unittest.py' for tests.

Change-Id: I5744a6d3d7e429342adce3f1dc637919065d66eb
Reviewed-on: https://chromium-review.googlesource.com/929589
Commit-Ready: Ruchi Jahagirdar <rjahagir@chromium.org>
Tested-by: Ruchi Jahagirdar <rjahagir@chromium.org>
Reviewed-by: Harpreet Grewal <harpreet@chromium.org>
diff --git a/provingground/chaosap/chaos_unittest.py b/provingground/chaosap/chaos_unittest.py
new file mode 100644
index 0000000..40cf1cf
--- /dev/null
+++ b/provingground/chaosap/chaos_unittest.py
@@ -0,0 +1,61 @@
+import unittest
+import requests
+import json
+
+class TestChaosApiUsingRequests(unittest.TestCase):
+    def test_create_new_AP(self):
+        response = requests.post('http://localhost:8080/devices/new', \
+                   json={"hostname":"test0", "lab_label":"lab", \
+                         "ap_label":"ap", "router_name":"router"})
+        self.assertEqual(response.json(), {'id':'test0', 'result': True})
+
+    def test_create_another_AP(self):
+        response = requests.post('http://localhost:8080/devices/new', \
+                   json={"hostname":"test1", "lab_label":"lab", \
+                         "ap_label":"ap", "router_name":"router"})
+        self.assertEqual(response.json(), {'id':'test1', 'result': True})
+
+    def test_lock_AP(self):
+        response = requests.put('http://localhost:8080/devices/lock', \
+                   json={"hostname":"test0", "locked_by":"admin"})
+        self.assertEqual(response.json(), {'id':'test0', 'result': True})
+
+    def test_unlock_AP(self):
+        response = requests.put('http://localhost:8080/devices/unlock', \
+                   json={"hostname":"test0"})
+        self.assertEqual(response.json(), {'id':'test0', 'result': True})
+
+    def test_lock_list_AP(self):
+        response = requests.put('http://localhost:8080/devices/lock', \
+                   json={"hostname":["test0", "test1"], "locked_by":"admin"})
+        self.assertEqual(response.json(), {'id':['test0', 'test1'], \
+                         "result": True})
+
+    def test_unlock_list_AP(self):
+        response = requests.put('http://localhost:8080/devices/unlock', \
+                   json={"hostname":["test0", "test1"]})
+        self.assertEqual(response.json(), {'id':['test0', 'test1'], \
+                         'result': True})
+
+    def test_edit_ap(self):
+        response = requests.put('http://localhost:8080/devices/test0', \
+                   json={"lab_label":"newlablabel"})
+        self.assertEqual(response.json(), {"id":"test0", \
+                         'lab_label':'newlablabel', \
+                         "ap_label":"ap", "router_name":"router", \
+                         'result': True})
+
+        response = requests.put('http://localhost:8080/devices/test0', \
+                   json={"ap_label":"newaplabel"})
+        self.assertEqual(response.json(), {'id':'test0', \
+                         'lab_label':'newlablabel', "ap_label":"newaplabel", \
+                          "router_name":"router", 'result': True})
+
+        response = requests.put('http://localhost:8080/devices/test0', \
+                   json={"router_name":"newroutername"})
+        self.assertEqual(response.json(), {'id':'test0', \
+                         'lab_label':'newlablabel', "ap_label":"newaplabel", \
+                         "router_name":"newroutername", 'result': True})
+
+if __name__ == "__main__":
+    unittest.main()
\ No newline at end of file