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(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 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 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_delete_section(self): """ Test GroupAdapter._delete_section(). """ section = 'delgroup' group = Group(name=section) group.save() Config.adapter._delete_section(section) del_group = Config.adapter._get_group(section) assert del_group is None
def test_edit_section(self): """ Test GroupAdapter._edit_section(). """ old_section = 'oldgroup' new_section = 'newgroup' group = Group(name=old_section) group.save() Config.adapter._edit_section(old_section, new_section) new_group = Config.adapter._get_group(new_section) assert new_group is not None assert new_group.name == new_section new_group.delete()
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