def test_project_errors(self):
        """Test project model errors."""
        project = Project(name="Project", short_name="proj", description="desc", owner_id=None)

        # Project.owner_id should not be nullable
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        # Project.name should not be nullable
        user = User(email_addr="*****@*****.**", name="johndoe", fullname="John Doe", locale="en")
        db.session.add(user)
        db.session.commit()
        user = db.session.query(User).first()
        project.owner_id = user.id
        project.name = None
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        project.name = ""
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        # Project.short_name should not be nullable
        project.name = "Project"
        project.short_name = None
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        project.short_name = ""
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        # Project.description should not be nullable
        db.session.add(project)
        project.short_name = "project"
        project.description = None
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        project.description = ""
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        # Project.featured should not be nullable
        project.description = "description"
        project.featured = None
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()
Exemple #2
0
 def test_info_public_keys_extension(self):
     """Test DomainObject to_public_json method works with extra fields."""
     project = Project()
     project.name = 'test'
     project.short_name = 'test'
     project.description = 'Desc'
     project.info = dict(container='3',
                         thumbnail='img.png',
                         token='secret',
                         tutorial='help',
                         sched='default',
                         task_presenter='something',
                         super_secret='hidden',
                         public_field='so true')
     project_dict = project.dictize()
     json = project.to_public_json()
     err_msg = "Wrong value"
     assert json['name'] == project.name, err_msg
     err_msg = "Missing fields"
     assert json.keys().sort() == project.public_attributes().sort(
     ), err_msg
     err_msg = "There should be info keys"
     assert json['info'].keys().sort() == Project().public_info_keys().sort(
     ), err_msg
     with patch.dict(self.flask_app.config,
                     {'PROJECT_INFO_PUBLIC_FIELDS': ['public_field']}):
         json = project.to_public_json()
         assert json['info'].keys().sort() == Project().public_info_keys(
         ).sort(), err_msg
         assert 'public_field' in json['info'].keys()
         assert 'secret_key' not in json['info'].keys()
    def test_project_errors(self):
        """Test project model errors."""
        project = Project(name='Project',
                          short_name='proj',
                          description='desc',
                          owner_id=None)

        # Project.owner_id should not be nullable
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        # Project.name should not be nullable
        user = User(email_addr="*****@*****.**",
                    name="johndoe",
                    fullname="John Doe",
                    locale="en")
        db.session.add(user)
        db.session.commit()
        user = db.session.query(User).first()
        project.owner_id = user.id
        project.name = None
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        project.name = ''
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        # Project.short_name should not be nullable
        project.name = "Project"
        project.short_name = None
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        project.short_name = ''
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        # Project.description should not be nullable
        db.session.add(project)
        project.short_name = "project"
        project.description = None
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        project.description = ''
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()

        # Project.featured should not be nullable
        project.description = 'description'
        project.featured = None
        db.session.add(project)
        assert_raises(IntegrityError, db.session.commit)
        db.session.rollback()