Exemplo n.º 1
0
    def test_save_fails_if_integrity_error(self):
        """Test save raises a DBIntegrityError if the instance to be saved lacks
        a required value"""

        page = PageFactory.build(project_id=None)

        assert_raises(DBIntegrityError, self.page_repo.save, page)
Exemplo n.º 2
0
    def test_anonymous_user_create_given_page(self):
        """Test anonymous users cannot create pages for a project"""

        project = ProjectFactory.create()
        page = PageFactory.build(project_id=project.id)

        assert_raises(Unauthorized, ensure_authorized_to, 'create', page)
Exemplo n.º 3
0
    def test_non_owner_authenticated_user_create_given_page(self):
        """Test authenticated user cannot create a given page if is not the
        project owner"""

        project = ProjectFactory.create()
        page = PageFactory.build(project_id=project.id)

        assert self.mock_authenticated.id != project.owner_id
        assert_raises(Forbidden, ensure_authorized_to, 'create', page)
Exemplo n.º 4
0
    def test_owner_create_given_page(self):
        """Test authenticated user can create a given page
        if it's project owner"""

        owner = UserFactory.create(id=2)
        project = ProjectFactory.create(owner=owner)
        page = PageFactory.build(project_id=project.id)

        assert self.mock_authenticated.id == project.owner_id
        assert_not_raises(Exception, ensure_authorized_to, 'create', page)
Exemplo n.º 5
0
    def test_save(self):
        """Test save persist the page"""

        page = PageFactory.build()
        project = ProjectFactory.create()
        page.project_id = project.id
        assert self.page_repo.get(page.id) is None

        self.page_repo.save(page)

        assert self.page_repo.get(
            page.id) == page, "Helping material not saved"