def test_serialize_project_contains_required_keys(self, with_users):
        self.setup_dummy_user(role='buyer')

        project = DirectAwardProject(name=DIRECT_AWARD_PROJECT_NAME,
                                     users=User.query.all())
        db.session.add(project)
        db.session.commit()

        serialized_project = project.serialize(with_users=with_users)
        project_keys_set = set(serialized_project.keys())

        expected_keys = {
            'id', 'name', 'createdAt', 'lockedAt', 'active', 'outcome',
            'downloadedAt', 'readyToAssessAt', 'stillAssessingAt'
        }
        if with_users:
            expected_keys.add('users')

        assert project_keys_set == expected_keys
        assert serialized_project['id'] == project.external_id

        if with_users:
            # Must send these keys exactly - don't want to unknowingly expose more info.
            for user in serialized_project['users']:
                assert {'active', 'emailAddress', 'id', 'name',
                        'role'} == set(user.keys())
Пример #2
0
    def test_serialize_project_contains_required_keys(self):
        self.setup_dummy_user(role='buyer')

        project = DirectAwardProject(name=DIRECT_AWARD_PROJECT_NAME, users=User.query.all())
        db.session.add(project)
        db.session.commit()

        serialized_project = project.serialize()
        project_keys_set = set(serialized_project.keys())
        assert {'id', 'name', 'createdAt', 'lockedAt', 'active'} <= project_keys_set
        assert serialized_project['id'] == project.external_id

        # We aren't serializing with_users=True, so we better not get them.
        assert 'users' not in project_keys_set
Пример #3
0
    def test_serialize_project_includes_users_if_requested(self):
        self.setup_dummy_user(role='buyer')

        project = DirectAwardProject(name=DIRECT_AWARD_PROJECT_NAME, users=User.query.all())
        db.session.add(project)
        db.session.commit()

        serialized_project = project.serialize(with_users=True)
        project_keys_set = set(serialized_project.keys())
        # Must send at least these keys.
        assert {'id', 'name', 'createdAt', 'lockedAt', 'active', 'users'} <= project_keys_set
        assert serialized_project['id'] == project.external_id

        # Must send these keys exactly - don't want to unknowingly expose more info.
        for user in serialized_project['users']:
            assert {'active', 'emailAddress', 'id', 'name', 'role'} == set(user.keys())
Пример #4
0
    def test_create_new_project_creates_project_users(self):
        self.setup_dummy_user(role='buyer')

        assert len(DirectAwardProjectUser.query.all()) == 0

        project = DirectAwardProject(name=DIRECT_AWARD_PROJECT_NAME, users=User.query.all())
        db.session.add(project)
        db.session.commit()

        assert len(DirectAwardProjectUser.query.all()) == len(User.query.all())
Пример #5
0
    def test_create_new_project(self):
        self.setup_dummy_user(role='buyer')

        project = DirectAwardProject(name=DIRECT_AWARD_PROJECT_NAME, users=User.query.all())
        db.session.add(project)
        db.session.commit()

        assert project.id is not None
        assert project.external_id is not None
        assert project.name == DIRECT_AWARD_PROJECT_NAME
        assert isinstance(project.created_at, datetime)
        assert project.locked_at is None
        assert project.active is True
Пример #6
0
    def create_direct_award_project(self, user_id, project_id=1, project_name=DIRECT_AWARD_PROJECT_NAME,
                                    created_at=DIRECT_AWARD_FROZEN_TIME):
        project = DirectAwardProject.query.get(project_id)
        if not project:
            project = DirectAwardProject(id=project_id, name=project_name, created_at=created_at)
            db.session.add(project)
            db.session.flush()

            project_user = DirectAwardProjectUser(user_id=user_id, project_id=project_id)
            db.session.add(project_user)
            db.session.commit()

        return project_id, project.external_id
    def test_serialize_project_contains_required_keys(self, with_users):
        self.setup_dummy_user(role='buyer')

        project = DirectAwardProject(name=DIRECT_AWARD_PROJECT_NAME, users=User.query.all())
        db.session.add(project)
        db.session.commit()

        serialized_project = project.serialize(with_users=with_users)
        project_keys_set = set(serialized_project.keys())

        expected_keys = {'id', 'name', 'createdAt', 'lockedAt', 'active', 'outcome', 'downloadedAt', 'readyToAssessAt',
                         'stillAssessingAt'}
        if with_users:
            expected_keys.add('users')

        assert project_keys_set == expected_keys
        assert serialized_project['id'] == project.external_id

        if with_users:
            # Must send these keys exactly - don't want to unknowingly expose more info.
            for user in serialized_project['users']:
                assert {'active', 'emailAddress', 'id', 'name', 'role'} == set(user.keys())
Пример #8
0
    def test_search_result_entries_fk_constraints(self, create_user, create_project, expect_error):
        if create_user:
            self.setup_dummy_user(role='buyer', id=1)

        if create_project:
            project = DirectAwardProject(id=1, name=DIRECT_AWARD_PROJECT_NAME, users=[])
            db.session.add(project)
            db.session.commit()

        project_user = DirectAwardProjectUser(project_id=1, user_id=1)
        db.session.add(project_user)

        if expect_error:
            with pytest.raises(IntegrityError):
                db.session.commit()
        else:
            db.session.commit()