Exemple #1
0
 def admin_login(app, client):
     Role.add_default_roles()
     User.add_default_users()
     return client.post(url_for('account.login'),
                        data=dict(email=app.config['ADMIN_EMAIL'],
                                  password=app.config['ADMIN_PASSWORD']),
                        follow_redirects=True)
Exemple #2
0
 def test_make_administrator(self):
     Role.add_default_roles()
     u = User(email='*****@*****.**', password='******')
     self.assertFalse(u.can(Permission.ADMINISTER))
     u.role = Role.query.filter_by(
         permissions=Permission.ADMINISTER).first()
     self.assertTrue(u.can(Permission.ADMINISTER))
    def test_edit_user_should_confirm_user(self):
        """Test that user is confirmed"""

        TEST_USER_ID = 1

        with self.app.app_context():
            db.create_all()
            Role.add_default_roles()
            db.session.commit()

        with self.app.app_context():
            role_user = Role.query.filter(Role.name == 'User').first()
            unconfirmed_user = User(
                id=TEST_USER_ID,
                first_name='test',
                last_name='test',
                email='*****@*****.**',
                password='******',
                confirmed=False,
                role=role_user,
            )
            db.session.add(unconfirmed_user)
            db.session.commit()

        with self.app.app_context():
            user = User.query.get(TEST_USER_ID)
            self.assertFalse(user.confirmed)

        response = self.invoke(
            ["edit-user", f"{TEST_USER_ID}", "--confirm-mail"])

        with self.app.app_context():
            user = User.query.get(TEST_USER_ID)
            self.assertTrue(user.confirmed)
Exemple #4
0
 def test_administrator(self):
     Role.add_default_roles()
     r = Role.query.filter_by(permissions=Permission.ADMINISTER).first()
     u = User(email=self.app.config['ADMIN_EMAIL'],
              password=self.app.config['ADMIN_PASSWORD'],
              role=r)
     self.assertTrue(u.can(Permission.ADMINISTER))
     self.assertTrue(u.can(Permission.GENERAL))
     self.assertTrue(u.is_admin())
Exemple #5
0
    def db_create():
        """ Creates a local database
        """
        with app.app_context():
            db.create_all()

            Role.add_default_roles()
            User.add_default_users()
            ControlLists.add_default_lists()

            db.session.commit()
            click.echo("Created the database")
Exemple #6
0
    def setUp(self):
        """Setup the test driver and create test users"""
        db.session.commit()
        db.drop_all()
        db.create_all()
        db.session.commit()

        # add default roles & admin user
        Role.add_default_roles()
        User.add_default_users()

        self.create_driver()
        self.driver.get(self.get_server_url())
Exemple #7
0
    def db_recreate():
        """ Recreates a local database. You probably should not use this on
        production.
        """
        with app.app_context():
            db.drop_all()
            db.create_all()

            Role.add_default_roles()
            User.add_default_users()
            ControlLists.add_default_lists()

            db.session.commit()
            click.echo("Dropped then recreated the database")
    def test_edit_user_should_get_user_by_email(self):
        """Test that user gets identified by email"""

        TEST_USER_ID = 1
        TEST_USER_EMAIL = '*****@*****.**'

        with self.app.app_context():
            db.create_all()
            Role.add_default_roles()
            db.session.commit()

        with self.app.app_context():
            role_user = Role.query.filter(Role.name == 'User').first()
            unconfirmed_user = User(
                id=TEST_USER_ID,
                first_name='test',
                last_name='test',
                email=TEST_USER_EMAIL,
                password='******',
                confirmed=False,
                role=role_user,
            )
            db.session.add(unconfirmed_user)
            db.session.commit()

        with self.app.app_context():
            role_user = Role.query.filter(Role.name == 'User').first()
            self.assertIsNotNone(role_user)
            user = User.query.get(TEST_USER_ID)
            self.assertEqual(user.role_id, role_user.id)

        response = self.invoke(
            ["edit-user", f"{TEST_USER_EMAIL}", "--role", "Administrator"])

        with self.app.app_context():
            role_administrator = Role.query.filter(
                Role.name == 'Administrator').first()
            self.assertIsNotNone(role_administrator)
            user = User.query.get(TEST_USER_ID)
            self.assertEqual(user.role_id, role_administrator.id)
Exemple #9
0
 def test_roles_and_permissions(self):
     Role.add_default_roles()
     u = User(email='*****@*****.**', password='******')
     self.assertTrue(u.can(Permission.GENERAL))
     self.assertFalse(u.can(Permission.ADMINISTER))