Moved creation of standard groups in unittests
This commit is contained in:
parent
3094a09fec
commit
3980133100
@ -161,3 +161,22 @@ class AbstractPillarTest(TestMinimal):
|
|||||||
"""Returns a Basic HTTP Authentication header value."""
|
"""Returns a Basic HTTP Authentication header value."""
|
||||||
|
|
||||||
return 'basic ' + base64.b64encode('%s:%s' % (username, subclient_id))
|
return 'basic ' + base64.b64encode('%s:%s' % (username, subclient_id))
|
||||||
|
|
||||||
|
def create_standard_groups(self, additional_groups=()):
|
||||||
|
"""Creates standard admin/demo/subscriber groups, plus any additional.
|
||||||
|
|
||||||
|
:returns: mapping from group name to group ID
|
||||||
|
"""
|
||||||
|
from application.modules import service
|
||||||
|
|
||||||
|
with self.app.test_request_context():
|
||||||
|
group_ids = {}
|
||||||
|
groups_coll = self.app.data.driver.db['groups']
|
||||||
|
|
||||||
|
for group_name in ['admin', 'demo', 'subscriber'] + list(additional_groups):
|
||||||
|
result = groups_coll.insert_one({'name': group_name})
|
||||||
|
group_ids[group_name] = result.inserted_id
|
||||||
|
|
||||||
|
service.fetch_role_to_group_id_map()
|
||||||
|
|
||||||
|
return group_ids
|
||||||
|
@ -54,17 +54,9 @@ class BadgerServiceTest(AbstractPillarTest):
|
|||||||
def test_group_membership(self):
|
def test_group_membership(self):
|
||||||
"""Certain roles are linked to certain groups."""
|
"""Certain roles are linked to certain groups."""
|
||||||
|
|
||||||
from application.modules import service
|
group_ids = self.create_standard_groups(additional_groups=['succubus'])
|
||||||
|
|
||||||
with self.app.test_request_context():
|
with self.app.test_request_context():
|
||||||
# Create the groups
|
|
||||||
group_ids = {}
|
|
||||||
for group_name in ['admin', 'demo', 'subscriber', 'succubus']:
|
|
||||||
groups_coll = self.app.data.driver.db['groups']
|
|
||||||
result = groups_coll.insert_one({'name': group_name})
|
|
||||||
group_ids[group_name] = result.inserted_id
|
|
||||||
service.fetch_role_to_group_id_map()
|
|
||||||
|
|
||||||
def test_for_group(group_name, test=self.assertIn):
|
def test_for_group(group_name, test=self.assertIn):
|
||||||
# Assign the 'subscriber' role
|
# Assign the 'subscriber' role
|
||||||
resp = self._post({'action': 'grant',
|
resp = self._post({'action': 'grant',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user