def setup_class(): """ Create the group adapter, load groups and users into the test database, and save expected values in the configuration. """ Config.adapter = GroupAdapter(Config.t11) g1 = Group(name='g1') # will have multiple users g2 = Group(name='g2') # will have one user g3 = Group(name='g3') # will have no users Config.groups = [g1, g2, g3] Group.bulk_save(Config.groups) u1 = User(username='******') # belongs to g1, g2 u2 = User(username='******') # belongs to g1 u3 = User(username='******') # belongs to no groups u1.groups.append(g1) u1.groups.append(g2) u2.groups.append(g1) Config.users = [u1, u2, u3] User.bulk_save(Config.users) Config.sections = { u'g1': [u'u1', u'u2'], u'g2': [u'u1'], u'g3': []} Config.items = { u'u1': [u'g1', u'g2'], u'u2': [u'g1'], u'u3': []}
def _exclude_items(self, section, items): """ Test GroupAdapter._exclude_items() for the given group and users. :param section: The section to test _exclude_items() against. :param items: The items to use when testing _exclude_items(). """ Config.adapter._exclude_items(section, items) group = Config.adapter._get_group(section) users = [ Config.adapter._get_user(item) for item in items ] found_any = False for user in users: assert user is not None found = False for cgroup in user.groups: if cgroup.name == section: found = True if not found: user.groups.append(group) else: found_any = True User.bulk_save(users) assert not found