]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[2641] Test that _try_login() makes the right API call to cmdctl
authorMukund Sivaraman <muks@isc.org>
Tue, 19 Feb 2013 06:11:47 +0000 (11:41 +0530)
committerMukund Sivaraman <muks@isc.org>
Tue, 19 Feb 2013 06:11:47 +0000 (11:41 +0530)
src/bin/bindctl/tests/bindctl_test.py

index b28e640a5973d1ded756fe5f1401d374e6b1443f..344b198d6c0abad166630d0c3f96cf67f0ee62a3 100644 (file)
@@ -458,6 +458,44 @@ class TestConfigCommands(unittest.TestCase):
         finally:
             self.tool.send_POST = orig_send_POST
 
+    def test_try_login_calls_cmdctl(self):
+        # Make sure _try_login() makes the right API call to cmdctl.
+        orig_conn = self.tool.conn
+        try:
+            class MyConn:
+                def __init__(self):
+                    self.method = None
+                    self.url = None
+                    self.param = None
+                    self.headers = None
+
+                def request(self, method, url, param, headers):
+                    self.method = method
+                    self.url = url
+                    self.param = param
+                    self.headers = headers
+
+                def getresponse(self):
+                    class MyResponse:
+                        def __init__(self):
+                            self.status = http.client.OK
+                        def read(self):
+                            class MyData:
+                                def decode(self):
+                                    return json.dumps(True)
+                            return MyData()
+                    return MyResponse()
+
+            self.tool.conn = MyConn()
+            self.assertTrue(self.tool._try_login('user32', 'pass64'))
+            self.assertEqual(self.tool.conn.method, 'POST')
+            self.assertEqual(self.tool.conn.url, '/login')
+            self.assertEqual(json.loads(self.tool.conn.param),
+                             {"password": "pass64", "username": "user32"})
+            self.assertIn('cookie', self.tool.conn.headers)
+        finally:
+            self.tool.conn = orig_conn
+
     def test_have_users(self):
         # Make sure _have_users raises the correct exception
         # upon failure of either send_POST or the read() on the