[Kimchi-devel] [PATCH v2][Wok 7/8] Fix test utils imports and add auth tests
Aline Manera
alinefm at linux.vnet.ibm.com
Wed Jun 8 21:42:21 UTC 2016
On 06/08/2016 06:37 PM, Rodrigo Trujillo wrote:
>
>
> On 06/08/2016 04:11 PM, Aline Manera wrote:
>>
>>
>> On 06/06/2016 04:13 PM, Rodrigo Trujillo wrote:
>>> 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
>>
>> Keep importing 'tabs' to do not parse the file multiple times.
>
> 'tabs' will not back to auth, like explained before
> Also, does not make sense a module "auth" provide a variable related
> to UI tabs.
>
I am not saying to you get the function back to auth.py
I am saying to do:
tabs = <the function wherever it is>
And use 'tabs' in the code when needed.
> Here I can see that the function is called multiple times. Got to
> think a better solution. Maybe change the function
> in PluginsManager to keep a variable and not read file every time .
>
>>
>>> +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):
>>
>> _______________________________________________
>> Kimchi-devel mailing list
>> Kimchi-devel at ovirt.org
>> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>>
>
> _______________________________________________
> Kimchi-devel mailing list
> Kimchi-devel at ovirt.org
> http://lists.ovirt.org/mailman/listinfo/kimchi-devel
>
More information about the Kimchi-devel
mailing list