]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard_v2: Added unit test for module.py
authorRicardo Dias <rdias@suse.com>
Fri, 26 Jan 2018 12:13:49 +0000 (12:13 +0000)
committerRicardo Dias <rdias@suse.com>
Mon, 5 Mar 2018 13:07:01 +0000 (13:07 +0000)
Signed-off-by: Ricardo Dias <rdias@suse.com>
src/pybind/mgr/dashboard_v2/tests/test_module.py [new file with mode: 0644]

diff --git a/src/pybind/mgr/dashboard_v2/tests/test_module.py b/src/pybind/mgr/dashboard_v2/tests/test_module.py
new file mode 100644 (file)
index 0000000..3edc3a5
--- /dev/null
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+from __future__ import absolute_import
+
+import errno
+
+from .helper import ControllerTestCase
+from ..controllers.auth import Auth
+
+
+class ModuleTest(ControllerTestCase):
+
+    def test_ping(self):
+        self._get("/api/ping")
+        self.assertStatus("401 Unauthorized")
+
+    def test_set_login_credentials_cmd(self):
+        ret, _, _ = self._mgr_module.handle_command({
+            'prefix': 'dashboard set-login-credentials',
+            'username': 'admin',
+            'password': 'admin'
+        })
+        self.assertEqual(ret, 0)
+        user = self._mgr_module.get_localized_config('username')
+        passwd = self._mgr_module.get_localized_config('password')
+        self.assertEqual(user, 'admin')
+        self.assertEqual(passwd, Auth.password_hash('admin', passwd))
+
+    def test_cmd_not_found(self):
+        ret, _, _ = self._mgr_module.handle_command({
+            'prefix': 'dashboard non-command'
+        })
+        self.assertEqual(ret, -errno.EINVAL)