Ejemplo n.º 1
0
    def setUp(self):
        """
        create a new test client, initialise a database and activate TESTING mode
        """
        self.db_fd, meterage.app.config['DATABASE'] = tempfile.mkstemp()
        meterage.app.config['TESTING'] = True
        self.app = meterage.app.test_client()
        meterage.init_db()

        global users
        usernames = ["admin", "hari", "spock", "test"]
        passwords = ["default", "seldon", "vulcan", "test"]
        gravataremails = ["*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**"]
        flag_admins=[True, False, False, True]
        flag_approvals=[True, True, False, True]
		
        users = zip(usernames, passwords, gravataremails, flag_admins, flag_approvals)

        # add an admin and a normal user to the database
        with closing(meterage.connect_db()) as db:
            for username, password, gravataremail, flag_admin, flag_approval in users:
                user = User(username, password, gravataremail, flag_admin, flag_approval)
                db.execute('insert into userPassword (username, password, gravataremail, flag_admin, flag_approval) values (?, ?, ?, ?, ?)',
                           [user.username, user.password, user.gravataremail, user.flag_admin, user.flag_approval])
            db.commit()
Ejemplo n.º 2
0
def before_feature(context, feature):
    """
    Create a new test client, initialise a database and activate TESTING mode
    """
    context.db_fd, meterage.app.config['DATABASE'] = tempfile.mkstemp()
    meterage.app.config['TESTING'] = True
    context.app = meterage.app.test_client()
    meterage.init_db()

    #flat dictionary of users, so we have access to the plain text versions of the passwords
    context.users = {"admin": "default", "hari": "seldon"}

    # add users to the temporary database
    # Note that an admin and a normal user are added.
    with closing(meterage.connect_db()) as db:
        admin = User('admin', 'default', '*****@*****.**', True, True)
        db.execute('insert into userPassword (username, password, gravataremail,flag_admin,flag_approval) values (?, ?, ? ,? ,?)',
                   [admin.username, admin.password, admin.gravataremail, admin.flag_admin, admin.flag_approval])
        user = User('hari', 'seldon', '*****@*****.**', False, True)
        db.execute('insert into userPassword (username, password, gravataremail,flag_admin,flag_approval) values (?, ?, ?,? ,?)',
                   [user.username, user.password, user.gravataremail, user.flag_admin, user.flag_approval])
        user2 = User('spock', 'vulcan', '*****@*****.**', True, True)
        db.execute('insert into userPassword (username, password, gravataremail,flag_admin,flag_approval) values (?, ?, ?,? ,?)',
                   [user2.username, user2.password, user2.gravataremail, user2.flag_admin, user2.flag_approval])
        user3 = User('test', 'test', '*****@*****.**', False, True)
        db.execute('insert into userPassword (username, password, gravataremail,flag_admin,flag_approval) values (?, ?, ?,? ,?)',
                   [user3.username, user3.password, user3.gravataremail, user3.flag_admin, user3.flag_approval])
        db.commit()
Ejemplo n.º 3
0
    def setUp(self):
        """
        create a new test client, initialise a database and activate TESTING mode
        """
        self.db_fd, meterage.app.config['DATABASE'] = tempfile.mkstemp()
        meterage.app.config['TESTING'] = True
        self.app = meterage.app.test_client()
        meterage.init_db()

        global users
        usernames = ["admin", "hari", "spock", "test"]
        passwords = ["default", "seldon", "vulcan", "test"]
        gravataremails = [
            "*****@*****.**", "*****@*****.**",
            "*****@*****.**", "*****@*****.**"
        ]
        flag_admins = [True, False, False, True]
        flag_approvals = [True, True, False, True]

        users = zip(usernames, passwords, gravataremails, flag_admins,
                    flag_approvals)

        # add an admin and a normal user to the database
        with closing(meterage.connect_db()) as db:
            for username, password, gravataremail, flag_admin, flag_approval in users:
                user = User(username, password, gravataremail, flag_admin,
                            flag_approval)
                db.execute(
                    'insert into userPassword (username, password, gravataremail, flag_admin, flag_approval) values (?, ?, ?, ?, ?)',
                    [
                        user.username, user.password, user.gravataremail,
                        user.flag_admin, user.flag_approval
                    ])
            db.commit()
Ejemplo n.º 4
0
def before_feature(context, feature):
    """
    Create a new test client, initialise a database and activate TESTING mode
    """
    context.db_fd, meterage.app.config['DATABASE'] = tempfile.mkstemp()
    meterage.app.config['TESTING'] = True
    context.app = meterage.app.test_client()
    meterage.init_db()

    #flat dictionary of users, so we have access to the plain text versions of the passwords
    context.users = {"admin": "default", "hari": "seldon"}

    # add users to the temporary database
    # Note that an admin and a normal user are added.
    with closing(meterage.connect_db()) as db:
        admin = User('admin', 'default', '*****@*****.**', True, True)
        db.execute(
            'insert into userPassword (username, password, gravataremail,flag_admin,flag_approval) values (?, ?, ? ,? ,?)',
            [
                admin.username, admin.password, admin.gravataremail,
                admin.flag_admin, admin.flag_approval
            ])
        user = User('hari', 'seldon', '*****@*****.**', False, True)
        db.execute(
            'insert into userPassword (username, password, gravataremail,flag_admin,flag_approval) values (?, ?, ?,? ,?)',
            [
                user.username, user.password, user.gravataremail,
                user.flag_admin, user.flag_approval
            ])
        user2 = User('spock', 'vulcan', '*****@*****.**', True, True)
        db.execute(
            'insert into userPassword (username, password, gravataremail,flag_admin,flag_approval) values (?, ?, ?,? ,?)',
            [
                user2.username, user2.password, user2.gravataremail,
                user2.flag_admin, user2.flag_approval
            ])
        user3 = User('test', 'test', '*****@*****.**', False, True)
        db.execute(
            'insert into userPassword (username, password, gravataremail,flag_admin,flag_approval) values (?, ?, ?,? ,?)',
            [
                user3.username, user3.password, user3.gravataremail,
                user3.flag_admin, user3.flag_approval
            ])
        db.commit()