|
@@ -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
|