diff --git a/tests/common_test_class.py b/tests/common_test_class.py index 0317c08d..670c64e4 100644 --- a/tests/common_test_class.py +++ b/tests/common_test_class.py @@ -161,3 +161,22 @@ class AbstractPillarTest(TestMinimal): """Returns a Basic HTTP Authentication header value.""" 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 diff --git a/tests/test_service_badger.py b/tests/test_service_badger.py index e54f7249..9be6f27f 100644 --- a/tests/test_service_badger.py +++ b/tests/test_service_badger.py @@ -54,17 +54,9 @@ class BadgerServiceTest(AbstractPillarTest): def test_group_membership(self): """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(): - # 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): # Assign the 'subscriber' role resp = self._post({'action': 'grant',