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)
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)
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"
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_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)
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_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)
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)
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)
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)
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)
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)
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)