From: Mukund Sivaraman Date: Tue, 19 Feb 2013 06:11:47 +0000 (+0530) Subject: [2641] Test that _try_login() makes the right API call to cmdctl X-Git-Tag: bind10-1.1.0beta1-release~51^2~17 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=77520e9dda0fc9cac5bbd8bdf7225ecc52bd8ed5;p=thirdparty%2Fkea.git [2641] Test that _try_login() makes the right API call to cmdctl --- diff --git a/src/bin/bindctl/tests/bindctl_test.py b/src/bin/bindctl/tests/bindctl_test.py index b28e640a59..344b198d6c 100644 --- a/src/bin/bindctl/tests/bindctl_test.py +++ b/src/bin/bindctl/tests/bindctl_test.py @@ -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