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 setup_app(command, conf, vars): """Place any commands to setup whatcouch_pylons here""" # Don't reload the app if it was loaded under the testing environment if not pylons.test.pylonsapp: load_environment(conf.global_conf, conf.local_conf) # Add design docs to CouchDB. loader = FileSystemDocsLoader(sys.path[0] + '/whatcouch_pylons/_design') loader.sync(Session.auth) # Add a user, group, and permission to CouchDB. user_name = 'admin' user_password = '******' group_name = 'administrators' perm_name = 'superpowers' if len(User.view('whatcouch/user_list', key=user_name)) > 0: raise Exception('User already exists.') if len(Group.view('whatcouch/group_list', key=group_name)) > 0: raise Exception('Group already exists.') if len(Permission.view('whatcouch/permission_list', key=perm_name)) > 0: raise Exception('Permission already exists.') perm = Permission(name=perm_name) perm.save() group = Group(name=group_name) group.permissions.append(perm) group.save() user = User.create(user_name, user_password) user.groups.append(group) user.save()
def setup_app(settings): # Init CouchDB model. print "initializing model" init_model(settings) # Add design docs to CouchDB. path = sys.path[0] + '/_design' print "loading views at %s" % path loader = FileSystemDocsLoader(path) loader.sync(Session.auth) # Add a user, group, and permission to CouchDB. user_name = 'admin' user_password = '******' group_name = 'administrators' perm_name = 'superpowers' if len(User.view('whatcouch/user_list', key=user_name)) > 0: raise Exception('User already exists.') if len(Group.view('whatcouch/group_list', key=group_name)) > 0: raise Exception('Group already exists.') if len(Permission.view('whatcouch/permission_list', key=perm_name)) > 0: raise Exception('Permission already exists.') print "loading data" perm = Permission(name=perm_name) perm.save() group = Group(name=group_name) group.permissions.append(perm) group.save() user = User.create(user_name, user_password) user.groups.append(group) user.save()
def test_set_password(self): """ Test User.set_password(). """ user = User(username=Config.username) user.set_password(Config.password) assert hashcmp(user.password, Config.password)
def teardown_class(): """ Delete the password attribute and remove the database associated with the model documents. """ del Config.password User.set_db(None) Group.set_db(None) Permission.set_db(None)
def test_create(self): """ Test User.create(). """ user = User.create(Config.username, Config.password) assert user.username == Config.username assert hashcmp(user.password, Config.password)
def test_init_model(self): """ Test the init_model function. """ init_model(Config.db) assert User.get_db() == Config.db assert Group.get_db() == Config.db assert Permission.get_db() == Config.db
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
def setup_class(): Config.username = '******' Config.password = '******' Config.user = User.create(Config.username, Config.password) Config.user.save() Config.plugin = AuthenticatorPlugin(Config.t11)
def setup_class(): Config.username = "******" Config.user = User.create(Config.username, "password") Config.user.save() Config.plugin = MetadataPlugin(Config.t11)
def teardown_package(): User.set_db(None) del Config.environ del Config.t11
def setup_package(): User.set_db(Config.db) Config.environ = {} Config.t11 = default_translations Config.t11['user_class'] = User
def test_authenticate(self): """ Test User.authenticate(). """ user = User.create(Config.username, Config.password) assert user.authenticate(Config.password)