Пример #1
0
    def test_anonymous_user_create_given_blogpost(self):
        """Test anonymous users cannot create a given blogpost"""

        project = ProjectFactory.create()
        blogpost = BlogpostFactory.build(project=project, owner=None)

        assert_raises(Unauthorized, ensure_authorized_to, 'create', blogpost)
Пример #2
0
    def test_save_fails_if_integrity_error(self):
        """Test save raises a DBIntegrityError if the instance to be saved lacks
        a required value"""

        blogpost = BlogpostFactory.build(title=None)

        assert_raises(DBIntegrityError, self.blog_repo.save, blogpost)
Пример #3
0
    def test_anonymous_user_create_given_blogpost(self):
        """Test anonymous users cannot create a given blogpost"""

        app = AppFactory.create()
        blogpost = BlogpostFactory.build(app=app, owner=None)

        assert_raises(Unauthorized, getattr(require, 'blogpost').create, blogpost)
Пример #4
0
    def test_anonymous_user_create_given_blogpost(self):
        """Test anonymous users cannot create a given blogpost"""

        project = ProjectFactory.create()
        blogpost = BlogpostFactory.build(project=project, owner=None)

        assert_raises(Unauthorized, ensure_authorized_to, 'create', blogpost)
    def test_save_fails_if_integrity_error(self):
        """Test save raises a DBIntegrityError if the instance to be saved lacks
        a required value"""

        blogpost = BlogpostFactory.build(title=None)

        assert_raises(DBIntegrityError, self.blog_repo.save, blogpost)
Пример #6
0
    def test_anonymous_user_create_given_blogpost(self):
        """Test anonymous users cannot create a given blogpost"""

        app = AppFactory.create()
        blogpost = BlogpostFactory.build(app=app, owner=None)

        assert_raises(Unauthorized,
                      getattr(require, 'blogpost').create, blogpost)
Пример #7
0
    def test_save(self):
        """Test save persist the blogpost"""

        blogpost = BlogpostFactory.build()
        assert self.blog_repo.get(blogpost.id) is None

        self.blog_repo.save(blogpost)

        assert self.blog_repo.get(blogpost.id) == blogpost, "Blogpost not saved"
Пример #8
0
    def test_owner_create_given_blogpost(self):
        """Test authenticated user can create a given blogpost if is project owner"""

        owner = UserFactory.create_batch(2)[1]
        app = AppFactory.create(owner=owner)
        blogpost = BlogpostFactory.build(app=app, owner=owner)

        assert self.mock_authenticated.id == app.owner_id
        assert_not_raises(Exception, getattr(require, 'blogpost').create, blogpost)
    def test_save(self):
        """Test save persist the blogpost"""

        blogpost = BlogpostFactory.build()
        assert self.blog_repo.get(blogpost.id) is None

        self.blog_repo.save(blogpost)

        assert self.blog_repo.get(blogpost.id) == blogpost, "Blogpost not saved"
Пример #10
0
    def test_owner_create_given_blogpost(self):
        """Test authenticated user can create a given blogpost if is project owner"""

        owner = UserFactory.create_batch(2)[1]
        project = ProjectFactory.create(owner=owner)
        blogpost = BlogpostFactory.build(project=project, owner=owner)

        assert self.mock_authenticated.id == project.owner_id
        assert_not_raises(Exception, ensure_authorized_to, 'create', blogpost)
Пример #11
0
    def test_owner_create_given_blogpost(self):
        """Test authenticated user can create a given blogpost if is project owner"""

        owner = UserFactory.create_batch(2)[1]
        project = ProjectFactory.create(owner=owner)
        blogpost = BlogpostFactory.build(project=project, owner=owner)

        assert self.mock_authenticated.id == project.owner_id
        assert_not_raises(Exception, ensure_authorized_to, 'create', blogpost)
Пример #12
0
    def test_owner_create_given_blogpost(self):
        """Test authenticated user can create a given blogpost if is project owner"""

        owner = UserFactory.create_batch(2)[1]
        app = AppFactory.create(owner=owner)
        blogpost = BlogpostFactory.build(app=app, owner=owner)

        assert self.mock_authenticated.id == app.owner.id
        assert_not_raises(Exception,
                          getattr(require, 'blogpost').create, blogpost)
Пример #13
0
    def test_non_owner_authenticated_user_create_given_blogpost(self):
        """Test authenticated user cannot create a given blogpost if is not the
        project owner, even if is admin"""

        admin = UserFactory.create()
        app = AppFactory.create()
        blogpost = BlogpostFactory.build(app=app, owner=admin)

        assert self.mock_admin.id != app.owner.id
        assert_raises(Forbidden, getattr(require, 'blogpost').create, blogpost)
Пример #14
0
    def test_non_owner_authenticated_user_create_given_blogpost(self):
        """Test authenticated user cannot create a given blogpost if is not the
        project owner, even if is admin"""

        admin = UserFactory.create()
        app = AppFactory.create()
        blogpost = BlogpostFactory.build(app=app, owner=admin)

        assert self.mock_admin.id != app.owner_id
        assert_raises(Forbidden, getattr(require, 'blogpost').create, blogpost)
Пример #15
0
    def test_non_owner_authenticated_user_create_given_blogpost(self):
        """Test authenticated user cannot create a given blogpost if is not the
        project owner, even if is admin"""

        admin = UserFactory.create()
        project = ProjectFactory.create()
        blogpost = BlogpostFactory.build(project=project, owner=admin)

        assert self.mock_admin.id != project.owner_id
        assert_raises(Forbidden, ensure_authorized_to, 'create', blogpost)
Пример #16
0
    def test_save(self, clean_project_mock):
        """Test save persist the blogpost"""

        blogpost = BlogpostFactory.build()
        assert self.blog_repo.get(blogpost.id) is None

        self.blog_repo.save(blogpost)

        assert self.blog_repo.get(blogpost.id) == blogpost, "Blogpost not saved"
        clean_project_mock.assert_called_with(blogpost.project_id)
Пример #17
0
    def test_owner_create_blogpost_as_other_user(self):
        """Test authenticated user cannot create blogpost if is project owner but
        sets another person as the author of the blogpost"""

        another_user = UserFactory.create()
        app = AppFactory.create()
        blogpost = BlogpostFactory.build(app_id=app.id, owner=another_user)

        assert self.mock_authenticated.id == app.owner.id
        assert_raises(Forbidden, getattr(require, 'blogpost').create, blogpost)
Пример #18
0
    def test_non_owner_authenticated_user_create_given_blogpost(self):
        """Test authenticated user cannot create a given blogpost if is not the
        project owner, even if is admin"""

        admin = UserFactory.create()
        project = ProjectFactory.create()
        blogpost = BlogpostFactory.build(project=project, owner=admin)

        assert self.mock_admin.id != project.owner_id
        assert_raises(Forbidden, ensure_authorized_to, 'create', blogpost)
Пример #19
0
    def test_owner_create_blogpost_as_other_user(self):
        """Test authenticated user cannot create blogpost if is project owner but
        sets another person as the author of the blogpost"""

        another_user = UserFactory.create()
        project = ProjectFactory.create()
        blogpost = BlogpostFactory.build(project_id=project.id,
                                          owner=another_user)

        assert self.mock_authenticated.id == project.owner_id
        assert_raises(Forbidden, ensure_authorized_to, 'create', blogpost)
Пример #20
0
    def test_owner_create_blogpost_as_other_user(self):
        """Test authenticated user cannot create blogpost if is project owner but
        sets another person as the author of the blogpost"""

        another_user = UserFactory.create()
        project = ProjectFactory.create()
        blogpost = BlogpostFactory.build(project_id=project.id,
                                          owner=another_user)

        assert self.mock_authenticated.id == project.owner_id
        assert_raises(Forbidden, ensure_authorized_to, 'create', blogpost)
    def test_save(self, clean_project_mock):
        """Test save persist the blogpost"""

        blogpost = BlogpostFactory.build()
        assert self.blog_repo.get(blogpost.id) is None

        self.blog_repo.save(blogpost)

        assert self.blog_repo.get(
            blogpost.id) == blogpost, "Blogpost not saved"
        clean_project_mock.assert_called_with(blogpost.project_id)
Пример #22
0
    def test_owner_create_blogpost_as_other_user(self):
        """Test authenticated user cannot create blogpost if is project owner but
        sets another person as the author of the blogpost"""

        another_user = UserFactory.create()
        app = AppFactory.create()
        blogpost = BlogpostFactory.build(app_id=app.id,
                                          owner=another_user)

        assert self.mock_authenticated.id == app.owner_id
        assert_raises(Forbidden, getattr(require, 'blogpost').create, blogpost)