[Kimchi-devel] [PATCH v2][Wok 7/8] Fix test utils imports and add auth tests
Rodrigo Trujillo
rodrigo.trujillo at linux.vnet.ibm.com
Mon Jun 6 19:13:35 UTC 2016
This patch add auth test to GET and POST requests in API of Plugins
Manager. It also fixes imports in tests/utils.py
Signed-off-by: Rodrigo Trujillo <rodrigo.trujillo at linux.vnet.ibm.com>
---
tests/test_plugin.py | 5 +++--
tests/test_server.py | 10 +++++++++-
tests/utils.py | 7 ++++---
3 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/tests/test_plugin.py b/tests/test_plugin.py
index 7c5e8e8..d785cfa 100644
--- a/tests/test_plugin.py
+++ b/tests/test_plugin.py
@@ -23,7 +23,8 @@ import json
import unittest
from functools import partial
-from wok.utils import get_enabled_plugins
+#from wok.pluginsmanager import get_enabled_plugins
+from wok.pluginsmanager import Plugins
import utils
@@ -50,7 +51,7 @@ def tearDownModule():
@unittest.skipUnless(
- 'sample' in [plugin for plugin, _config in get_enabled_plugins()],
+ 'sample' in Plugins().get_enabled_plugins(),
'sample plugin is not enabled, skip this test!')
class PluginTests(unittest.TestCase):
diff --git a/tests/test_server.py b/tests/test_server.py
index 1f5a236..6e4749e 100644
--- a/tests/test_server.py
+++ b/tests/test_server.py
@@ -188,12 +188,20 @@ class ServerTests(unittest.TestCase):
def test_auth_protected(self):
hdrs = {'AUTHORIZATION': ''}
- uris = ['/tasks']
+ uris = ['/tasks',
+ '/pluginsmanager',
+ '/pluginsmanager/sample']
for uri in uris:
resp = self.request(uri, None, 'GET', hdrs)
self.assertEquals(401, resp.status)
+ uris = ['/pluginsmanager/sample/disable']
+
+ for uri in uris:
+ resp = self.request(uri, {}, 'POST', hdrs)
+ self.assertEquals(401, resp.status)
+
def test_auth_bad_creds(self):
# Test HTTPBA
hdrs = {'AUTHORIZATION': "Basic " + base64.b64encode("nouser:badpass")}
diff --git a/tests/utils.py b/tests/utils.py
index d158ba1..ed709e1 100644
--- a/tests/utils.py
+++ b/tests/utils.py
@@ -38,8 +38,9 @@ from lxml import etree
import wok.server
from wok.config import config, PluginPaths
-from wok.auth import User, USER_NAME, USER_GROUPS, USER_ROLES, tabs
+from wok.auth import User, USER_NAME, USER_GROUPS, USER_ROLES
from wok.exception import NotFoundError, OperationFailed
+from wok.pluginsmanager import get_all_tabs
from wok.utils import wok_log
@@ -192,14 +193,14 @@ class FakeUser(User):
self.user = {}
self.user[USER_NAME] = username
self.user[USER_GROUPS] = None
- self.user[USER_ROLES] = dict.fromkeys(tabs, 'user')
+ self.user[USER_ROLES] = dict.fromkeys(get_all_tabs(), 'user')
def get_groups(self):
return sorted([group.gr_name for group in grp.getgrall()])[0:3]
def get_roles(self):
if self.sudo:
- self.user[USER_ROLES] = dict.fromkeys(tabs, 'admin')
+ self.user[USER_ROLES] = dict.fromkeys(get_all_tabs(), 'admin')
return self.user[USER_ROLES]
def get_user(self):
--
2.1.0
More information about the Kimchi-devel
mailing list