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_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