def test_filter_by_one_condition(self):
        """Test filter_by returns a list of logs that meet the filtering
        condition"""

        project = ProjectFactory.create()
        AuditlogFactory.create_batch(
            size=3,
            project_id=project.id,
            project_short_name=project.short_name,
            user_id=project.owner.id,
            user_name=project.owner.name,
        )

        project2 = ProjectFactory.create()
        should_be_missing = AuditlogFactory.create_batch(
            size=3,
            project_id=project2.id,
            project_short_name=project2.short_name,
            user_id=project2.owner.id,
            user_name=project2.owner.name,
        )

        retrieved_logs = self.auditlog_repo.filter_by(user_id=project.owner.id)

        assert len(retrieved_logs) == 3, retrieved_logs
        assert should_be_missing not in retrieved_logs, retrieved_logs
Exemplo n.º 2
0
    def test_get_by_returns_none_if_no_log(self):
        """Test get_by returns None if no log matches the query"""

        app = AppFactory.create()
        AuditlogFactory.create(app_id=app.id,
                               app_short_name=app.short_name,
                               user_id=app.owner.id,
                               user_name=app.owner.name)

        retrieved_log = self.auditlog_repo.get_by(user_id=5555)

        assert retrieved_log is None, retrieved_log
Exemplo n.º 3
0
    def test_get_by_returns_none_if_no_log(self):
        """Test get_by returns None if no log matches the query"""

        app = AppFactory.create()
        AuditlogFactory.create(app_id=app.id,
                               app_short_name=app.short_name,
                               user_id=app.owner.id,
                               user_name=app.owner.name)

        retrieved_log = self.auditlog_repo.get_by(user_id=5555)

        assert retrieved_log is None, retrieved_log
    def test_get_by_returns_none_if_no_log(self):
        """Test get_by returns None if no log matches the query"""

        project = ProjectFactory.create()
        AuditlogFactory.create(project_id=project.id,
                               project_short_name=project.short_name,
                               user_id=project.owner.id,
                               user_name=project.owner.name)

        retrieved_log = self.auditlog_repo.get_by(user_id=5555)

        assert retrieved_log is None, retrieved_log
    def test_get_by_returns_none_if_no_log(self):
        """Test get_by returns None if no log matches the query"""

        project = ProjectFactory.create()
        AuditlogFactory.create(project_id=project.id,
                               project_short_name=project.short_name,
                               user_id=project.owner.id,
                               user_name=project.owner.name)

        retrieved_log = self.auditlog_repo.get_by(user_id=5555)

        assert retrieved_log is None, retrieved_log
Exemplo n.º 6
0
    def test_filter_by_no_matches(self):
        """Test filter_by returns an empty list if no log matches the query"""

        app = AppFactory.create()
        AuditlogFactory.create(app_id=app.id,
                               app_short_name=app.short_name,
                               user_id=app.owner.id,
                               user_name=app.owner.name)

        retrieved_logs = self.auditlog_repo.filter_by(user_name='no_name')

        assert isinstance(retrieved_logs, list)
        assert len(retrieved_logs) == 0, retrieved_logs
Exemplo n.º 7
0
    def test_filter_by_no_matches(self):
        """Test filter_by returns an empty list if no log matches the query"""

        app = AppFactory.create()
        AuditlogFactory.create(app_id=app.id,
                               app_short_name=app.short_name,
                               user_id=app.owner.id,
                               user_name=app.owner.name)

        retrieved_logs = self.auditlog_repo.filter_by(user_name='no_name')

        assert isinstance(retrieved_logs, list)
        assert len(retrieved_logs) == 0, retrieved_logs
    def test_filter_by_no_matches(self):
        """Test filter_by returns an empty list if no log matches the query"""

        project = ProjectFactory.create()
        AuditlogFactory.create(
            project_id=project.id,
            project_short_name=project.short_name,
            user_id=project.owner.id,
            user_name=project.owner.name,
        )

        retrieved_logs = self.auditlog_repo.filter_by(user_name="no_name")

        assert isinstance(retrieved_logs, list)
        assert len(retrieved_logs) == 0, retrieved_logs
Exemplo n.º 9
0
    def test_save_fails_if_integrity_error(self):
        """Test save raises a DBIntegrityError if the instance to be saved lacks
        a required value"""

        log = AuditlogFactory.build(app_id=None)

        assert_raises(DBIntegrityError, self.auditlog_repo.save, log)
    def test_save_fails_if_integrity_error(self):
        """Test save raises a DBIntegrityError if the instance to be saved lacks
        a required value"""

        log = AuditlogFactory.build(project_id=None)

        assert_raises(DBIntegrityError, self.auditlog_repo.save, log)
Exemplo n.º 11
0
    def test_admin_user_can_read_auditlog(self):
        """Test admin users can read auditlogs"""

        owner = UserFactory.create_batch(2)[1]
        app = AppFactory.create(owner=owner)
        log = AuditlogFactory.create(app_id=app.id)

        assert self.mock_admin.id != app.owner_id
        assert_not_raises(Exception, getattr(require, 'auditlog').read, log)
Exemplo n.º 12
0
    def test_pro_user_can_read_auditlog(self):
        """Test pro users can read auditlogs from owned projects"""

        owner = UserFactory.create_batch(2, pro=True)[1]
        app = AppFactory.create(owner=owner)
        log = AuditlogFactory.create(app_id=app.id)

        assert self.mock_pro.id == app.owner_id
        assert_not_raises(Exception, getattr(require, 'auditlog').read, log)
Exemplo n.º 13
0
    def test_admin_user_can_read_auditlog(self):
        """Test admin users can read an auditlog"""

        owner = UserFactory.create_batch(2)[1]
        project = ProjectFactory.create(owner=owner)
        log = AuditlogFactory.create(project_id=project.id)

        assert self.mock_admin.id != project.owner_id
        assert_not_raises(Exception, ensure_authorized_to, 'read', log)
Exemplo n.º 14
0
    def test_pro_user_cannot_read_auditlog(self):
        """Test pro users cannot read an auditlog from a non-owned project"""

        users = UserFactory.create_batch(2, pro=True)
        project = ProjectFactory.create(owner=users[0])
        log = AuditlogFactory.create(project_id=project.id)

        assert self.mock_pro.id != project.owner_id
        assert_raises(Forbidden, ensure_authorized_to, 'read', log)
Exemplo n.º 15
0
    def test_pro_user_cannot_read_auditlog(self):
        """Test pro users cannot read auditlogs from non-owned projects"""

        users = UserFactory.create_batch(2, pro=True)
        app = AppFactory.create(owner=users[0])
        log = AuditlogFactory.create(app_id=app.id)

        assert self.mock_pro.id != app.owner_id
        assert_raises(Forbidden, getattr(require, 'auditlog').read, log)
Exemplo n.º 16
0
    def test_admin_user_can_read_auditlog(self):
        """Test admin users can read an auditlog"""

        owner = UserFactory.create_batch(2)[1]
        project = ProjectFactory.create(owner=owner)
        log = AuditlogFactory.create(project_id=project.id)

        assert self.mock_admin.id != project.owner_id
        assert_not_raises(Exception, ensure_authorized_to, 'read', log)
Exemplo n.º 17
0
    def test_pro_user_can_read_auditlog(self):
        """Test pro users can read an auditlog from an owned project"""

        owner = UserFactory.create_batch(2, pro=True)[1]
        project = ProjectFactory.create(owner=owner)
        log = AuditlogFactory.create(project_id=project.id)

        assert self.mock_pro.id == project.owner_id
        assert_not_raises(Exception, ensure_authorized_to, 'read', log)
Exemplo n.º 18
0
    def test_pro_user_can_read_auditlog(self):
        """Test pro users can read an auditlog from an owned project"""

        owner = UserFactory.create_batch(2, pro=True)[1]
        project = ProjectFactory.create(owner=owner)
        log = AuditlogFactory.create(project_id=project.id)

        assert self.mock_pro.id == project.owner_id
        assert_not_raises(Exception, ensure_authorized_to, 'read', log)
Exemplo n.º 19
0
    def test_pro_user_cannot_read_auditlog(self):
        """Test pro users cannot read an auditlog from a non-owned project"""

        users = UserFactory.create_batch(2, pro=True)
        project = ProjectFactory.create(owner=users[0])
        log = AuditlogFactory.create(project_id=project.id)

        assert self.mock_pro.id != project.owner_id
        assert_raises(Forbidden, ensure_authorized_to, 'read', log)
Exemplo n.º 20
0
    def test_owner_user_cannot_read_auditlog(self):
        """Test owner users cannot read an auditlog"""

        owner = UserFactory.create_batch(2)[1]
        project = ProjectFactory.create(owner=owner)
        log = AuditlogFactory.create(project_id=project.id)

        assert self.mock_authenticated.id == project.owner_id

        assert_raises(Forbidden, ensure_authorized_to, 'read', log)
Exemplo n.º 21
0
    def test_owner_user_cannot_read_auditlog(self):
        """Test owner users cannot read auditlogs"""

        owner = UserFactory.create_batch(2)[1]
        app = AppFactory.create(owner=owner)
        log = AuditlogFactory.create(app_id=app.id)

        assert self.mock_authenticated.id == app.owner_id

        assert_raises(Forbidden, getattr(require, 'auditlog').read, log)
Exemplo n.º 22
0
    def test_owner_user_cannot_read_auditlog(self):
        """Test owner users cannot read an auditlog"""

        owner = UserFactory.create_batch(2)[1]
        project = ProjectFactory.create(owner=owner)
        log = AuditlogFactory.create(project_id=project.id)

        assert self.mock_authenticated.id == project.owner_id

        assert_raises(Forbidden, ensure_authorized_to, 'read', log)
Exemplo n.º 23
0
    def test_filter_by_multiple_conditions(self):
        """Test filter_by supports multiple-condition queries"""

        project = ProjectFactory.create()
        user = UserFactory.create()
        AuditlogFactory.create_batch(size=3, project_id=project.id,
                               project_short_name=project.short_name,
                               user_id=project.owner.id,
                               user_name=project.owner.name)

        log = AuditlogFactory.create(project_id=project.id,
                                     project_short_name=project.short_name,
                                     user_id=user.id,
                                     user_name=user.name)

        retrieved_logs = self.auditlog_repo.filter_by(project_id=project.id,
                                                      user_id=user.id)

        assert len(retrieved_logs) == 1, retrieved_logs
        assert log in retrieved_logs, retrieved_logs
Exemplo n.º 24
0
    def test_filter_by_multiple_conditions(self):
        """Test filter_by supports multiple-condition queries"""

        app = AppFactory.create()
        user = UserFactory.create()
        AuditlogFactory.create_batch(size=3, app_id=app.id,
                               app_short_name=app.short_name,
                               user_id=app.owner.id,
                               user_name=app.owner.name)

        log = AuditlogFactory.create(app_id=app.id,
                                     app_short_name=app.short_name,
                                     user_id=user.id,
                                     user_name=user.name)

        retrieved_logs = self.auditlog_repo.filter_by(app_id=app.id,
                                                      user_id=user.id)

        assert len(retrieved_logs) == 1, retrieved_logs
        assert log in retrieved_logs, retrieved_logs
Exemplo n.º 25
0
    def test_filter_by_one_condition(self):
        """Test filter_by returns a list of logs that meet the filtering
        condition"""

        app = AppFactory.create()
        AuditlogFactory.create_batch(size=3, app_id=app.id,
                               app_short_name=app.short_name,
                               user_id=app.owner.id,
                               user_name=app.owner.name)

        app2 = AppFactory.create()
        should_be_missing = AuditlogFactory.create_batch(size=3, app_id=app2.id,
                                                   app_short_name=app2.short_name,
                                                   user_id=app2.owner.id,
                                                   user_name=app2.owner.name)


        retrieved_logs = self.auditlog_repo.filter_by(user_id=app.owner.id)

        assert len(retrieved_logs) == 3, retrieved_logs
        assert should_be_missing not in retrieved_logs, retrieved_logs
Exemplo n.º 26
0
    def test_get_returns_log(self):
        """Test get method returns a log if exists"""

        project = ProjectFactory.create()
        log = AuditlogFactory.create(project_id=project.id,
                                     project_short_name=project.short_name,
                                     user_id=project.owner.id,
                                     user_name=project.owner.name)

        retrieved_log = self.auditlog_repo.get(log.id)

        assert log == retrieved_log, retrieved_log
Exemplo n.º 27
0
    def test_get_by(self):
        """Test get_by returns a log with the specified attribute"""

        app = AppFactory.create()
        log = AuditlogFactory.create(app_id=app.id,
                                     app_short_name=app.short_name,
                                     user_id=app.owner.id,
                                     user_name=app.owner.name)

        retrieved_log = self.auditlog_repo.get_by(user_id=app.owner.id)

        assert log == retrieved_log, retrieved_log
    def test_get_returns_log(self):
        """Test get method returns a log if exists"""

        project = ProjectFactory.create()
        log = AuditlogFactory.create(project_id=project.id,
                                     project_short_name=project.short_name,
                                     user_id=project.owner.id,
                                     user_name=project.owner.name)

        retrieved_log = self.auditlog_repo.get(log.id)

        assert log == retrieved_log, retrieved_log
    def test_get_by(self):
        """Test get_by returns a log with the specified attribute"""

        project = ProjectFactory.create()
        log = AuditlogFactory.create(project_id=project.id,
                                     project_short_name=project.short_name,
                                     user_id=project.owner.id,
                                     user_name=project.owner.name)

        retrieved_log = self.auditlog_repo.get_by(user_id=project.owner.id)

        assert log == retrieved_log, retrieved_log
Exemplo n.º 30
0
    def test_get_returns_log(self):
        """Test get method returns a log if exists"""

        app = AppFactory.create()
        log = AuditlogFactory.create(app_id=app.id,
                                     app_short_name=app.short_name,
                                     user_id=app.owner.id,
                                     user_name=app.owner.name)

        retrieved_log = self.auditlog_repo.get(log.id)

        assert log == retrieved_log, retrieved_log
Exemplo n.º 31
0
    def test_get_returns_log(self):
        """Test get method returns a log if exists"""

        app = AppFactory.create()
        log = AuditlogFactory.create(app_id=app.id,
                                     app_short_name=app.short_name,
                                     user_id=app.owner.id,
                                     user_name=app.owner.name)

        retrieved_log = self.auditlog_repo.get(log.id)

        assert log == retrieved_log, retrieved_log
Exemplo n.º 32
0
    def test_filter_by_one_condition(self):
        """Test filter_by returns a list of logs that meet the filtering
        condition"""

        project = ProjectFactory.create()
        AuditlogFactory.create_batch(size=3, project_id=project.id,
                               project_short_name=project.short_name,
                               user_id=project.owner.id,
                               user_name=project.owner.name)

        project2 = ProjectFactory.create()
        should_be_missing = AuditlogFactory.create_batch(size=3, project_id=project2.id,
                                                   project_short_name=project2.short_name,
                                                   user_id=project2.owner.id,
                                                   user_name=project2.owner.name)


        retrieved_logs = self.auditlog_repo.filter_by(user_id=project.owner.id)

        assert len(retrieved_logs) == 3, retrieved_logs
        assert should_be_missing not in retrieved_logs, retrieved_logs
Exemplo n.º 33
0
    def test_filter_by_multiple_conditions(self):
        """Test filter_by supports multiple-condition queries"""

        app = AppFactory.create()
        user = UserFactory.create()
        AuditlogFactory.create_batch(size=3,
                                     app_id=app.id,
                                     app_short_name=app.short_name,
                                     user_id=app.owner.id,
                                     user_name=app.owner.name)

        log = AuditlogFactory.create(app_id=app.id,
                                     app_short_name=app.short_name,
                                     user_id=user.id,
                                     user_name=user.name)

        retrieved_logs = self.auditlog_repo.filter_by(app_id=app.id,
                                                      user_id=user.id)

        assert len(retrieved_logs) == 1, retrieved_logs
        assert log in retrieved_logs, retrieved_logs
Exemplo n.º 34
0
    def create_auditlogs(self):
        project = ProjectFactory.create(info={'task_presenter': 'version1', 'task_guidelines': 'version1'})

        AuditlogFactory.create(project_id=project.id,
            project_short_name=project.short_name,
            user_id=project.owner.id,
            user_name=project.owner.name,
            attribute='task_presenter',
            old_value="old_task_presenter1",
            new_value="new_task_presenter2",
            created='2019-01-11T15:24:42.263980')

        AuditlogFactory.create_batch(size=3, project_id=project.id,
            project_short_name=project.short_name,
            user_id=project.owner.id,
            user_name=project.owner.name,
            attribute='task_guidelines',
            old_value="old_task_guidelines1",
            new_value="new_task_guidelines2",
            created='2019-01-11T15:24:42.263980')

        AuditlogFactory.create_batch(size=3, project_id=project.id,
            project_short_name=project.short_name,
            user_id=project.owner.id,
            user_name=project.owner.name,
            attribute='task_guidelines',
            old_value="old_task_guidelines1",
            new_value="new_task_guidelines2",
            created='2020-01-11T15:24:42.263980')
Exemplo n.º 35
0
    def test_get_by(self):
        """Test get_by returns a log with the specified attribute"""

        project = ProjectFactory.create()
        log = AuditlogFactory.create(project_id=project.id,
                                     project_short_name=project.short_name,
                                     user_id=project.owner.id,
                                     user_name=project.owner.name)


        retrieved_log = self.auditlog_repo.get_by(user_id=project.owner.id)

        assert log == retrieved_log, retrieved_log
Exemplo n.º 36
0
    def test_get_by(self):
        """Test get_by returns a log with the specified attribute"""

        app = AppFactory.create()
        log = AuditlogFactory.create(app_id=app.id,
                                     app_short_name=app.short_name,
                                     user_id=app.owner.id,
                                     user_name=app.owner.name)


        retrieved_log = self.auditlog_repo.get_by(user_id=app.owner.id)

        assert log == retrieved_log, retrieved_log
Exemplo n.º 37
0
    def test_filter_by_one_condition(self):
        """Test filter_by returns a list of logs that meet the filtering
        condition"""

        app = AppFactory.create()
        AuditlogFactory.create_batch(size=3,
                                     app_id=app.id,
                                     app_short_name=app.short_name,
                                     user_id=app.owner.id,
                                     user_name=app.owner.name)

        app2 = AppFactory.create()
        should_be_missing = AuditlogFactory.create_batch(
            size=3,
            app_id=app2.id,
            app_short_name=app2.short_name,
            user_id=app2.owner.id,
            user_name=app2.owner.name)

        retrieved_logs = self.auditlog_repo.filter_by(user_id=app.owner.id)

        assert len(retrieved_logs) == 3, retrieved_logs
        assert should_be_missing not in retrieved_logs, retrieved_logs
Exemplo n.º 38
0
    def test_save(self):
        """Test save persist the log"""

        project = ProjectFactory.create()
        log = AuditlogFactory.build(project_id=project.id,
                                    project_short_name=project.short_name,
                                    user_id=project.owner.id,
                                    user_name=project.owner.name)

        assert self.auditlog_repo.get(log.id) is None

        self.auditlog_repo.save(log)

        assert self.auditlog_repo.get(log.id) == log, "Log not saved"
    def test_save(self):
        """Test save persist the log"""

        project = ProjectFactory.create()
        log = AuditlogFactory.build(project_id=project.id,
                                    project_short_name=project.short_name,
                                    user_id=project.owner.id,
                                    user_name=project.owner.name)

        assert self.auditlog_repo.get(log.id) is None

        self.auditlog_repo.save(log)

        assert self.auditlog_repo.get(log.id) == log, "Log not saved"
Exemplo n.º 40
0
    def test_save(self):
        """Test save persist the log"""

        app = AppFactory.create()
        log = AuditlogFactory.build(app_id=app.id,
                                    app_short_name=app.short_name,
                                    user_id=app.owner.id,
                                    user_name=app.owner.name)

        assert self.auditlog_repo.get(log.id) is None

        self.auditlog_repo.save(log)

        assert self.auditlog_repo.get(log.id) == log, "Log not saved"
Exemplo n.º 41
0
    def test_save(self):
        """Test save persist the log"""

        app = AppFactory.create()
        log = AuditlogFactory.build(app_id=app.id,
                                    app_short_name=app.short_name,
                                    user_id=app.owner.id,
                                    user_name=app.owner.name)

        assert self.auditlog_repo.get(log.id) is None

        self.auditlog_repo.save(log)

        assert self.auditlog_repo.get(log.id) == log, "Log not saved"
Exemplo n.º 42
0
    def test_anonymous_user_cannot_read_auditlog(self):
        """Test anonymous users cannot read an auditlog"""

        log = AuditlogFactory.create()

        assert_raises(Unauthorized, ensure_authorized_to, 'read', log)
Exemplo n.º 43
0
    def test_anonymous_user_cannot_read_auditlog(self):
        """Test anonymous users cannot read an auditlog"""

        log = AuditlogFactory.create()

        assert_raises(Unauthorized, ensure_authorized_to, 'read', log)
Exemplo n.º 44
0
    def test_anonymous_user_cannot_read_auditlog(self):
        """Test anonymous users cannot read auditlogs"""

        log = AuditlogFactory.create()

        assert_raises(Unauthorized, getattr(require, 'auditlog').read, log)