Exemplo n.º 1
0
 def setUp(self):
     self.project = ProjectFactory(private=False, approved=True)
     self.url = reverse(
         "project-crowdfund",
         kwargs={"slug": self.project.slug, "pk": self.project.pk},
     )
     self.view = views.ProjectCrowdfundView.as_view()
     self.request_factory = RequestFactory()
Exemplo n.º 2
0
 def setUp(self):
     # We will start with a project that's already been made.
     self.project = ProjectFactory(private=True, approved=False)
     self.contributor = UserFactory()
     self.project.contributors.add(self.contributor)
     self.kwargs = {"slug": self.project.slug, "pk": self.project.pk}
     self.url = reverse("project-publish", kwargs=self.kwargs)
     self.view = views.ProjectPublishView.as_view()
Exemplo n.º 3
0
 def setUp(self):
     self.project = ProjectFactory(private=False, approved=True)
     self.url = reverse('project-crowdfund',
                        kwargs={
                            'slug': self.project.slug,
                            'pk': self.project.pk
                        })
     self.view = views.ProjectCrowdfundView.as_view()
     self.request_factory = RequestFactory()
Exemplo n.º 4
0
 def setUp(self):
     # We will start with a project that's already been made.
     # We will give that project a single contributor.
     self.contributor = UserFactory()
     self.project = ProjectFactory()
     self.project.contributors.add(self.contributor)
     self.kwargs = {"slug": self.project.slug, "pk": self.project.pk}
     self.url = reverse("project-edit", kwargs=self.kwargs)
     self.view = views.ProjectEditView.as_view()
Exemplo n.º 5
0
    def setUp(self):
        self.contributor = UserFactory()
        self.user = UserFactory()
        self.project = ProjectFactory()
        self.project.contributors.add(self.contributor)

        self.kwargs = {"slug": self.project.slug, "pk": self.project.pk}
        self.url = reverse("project-detail", kwargs=self.kwargs)
        self.view = views.ProjectDetailView.as_view()
Exemplo n.º 6
0
 def setUp(self):
     # We will start with a project that's already been made.
     # We will give that project a single contributor.
     self.contributor = UserFactory()
     self.project = ProjectFactory()
     self.project.contributors.add(self.contributor)
     self.project.save()
     self.factory = RequestFactory()
     self.kwargs = {'slug': self.project.slug, 'pk': self.project.pk}
     self.url = reverse('project-edit', kwargs=self.kwargs)
     self.view = views.ProjectEditView.as_view()
Exemplo n.º 7
0
 def test_pending(self):
     """Projects that are pending review should reject access to the Publish view."""
     pending_project = ProjectFactory(private=False, approved=False)
     pending_project.contributors.add(self.contributor)
     response = http_get_response(
         self.url, self.view, self.contributor, **{
             'slug': pending_project.slug,
             'pk': pending_project.pk
         })
     eq_(response.status_code, 302)
     eq_(response.url, pending_project.get_absolute_url(),
         'The user should be redirected to the project.')
Exemplo n.º 8
0
 def test_add_projects(self):
     """Posting a collection of projects to a request should add it to those projects."""
     project = ProjectFactory()
     project.contributors.add(self.foia.user)
     form = ProjectManagerForm({"projects": [project.pk]},
                               user=self.foia.user)
     ok_(form.is_valid())
     data = {"action": "projects"}
     data.update(form.data)
     http_post_response(self.url, self.view, data, self.foia.user,
                        **self.kwargs)
     project.refresh_from_db()
     ok_(self.foia in project.requests.all())
Exemplo n.º 9
0
class TestProjectCrowdfundView(TestCase):
    """Tests the creation of a crowdfund for a project."""
    def setUp(self):
        self.project = ProjectFactory(private=False, approved=True)
        self.url = reverse('project-crowdfund',
                           kwargs={
                               'slug': self.project.slug,
                               'pk': self.project.pk
                           })
        self.view = views.ProjectCrowdfundView.as_view()
        self.request_factory = RequestFactory()

    def test_post(self):
        """Posting data for a crowdfund should create it."""
        user = UserFactory(is_staff=True)
        name = 'Project Crowdfund'
        description = 'A crowdfund'
        payment_required = 100
        payment_capped = True
        date_due = date.today() + timedelta(20)
        data = {
            'name': name,
            'description': description,
            'payment_required': payment_required,
            'payment_capped': payment_capped,
            'date_due': date_due
        }
        request = self.request_factory.post(self.url, data)
        request.user = user
        request = mock_middleware(request)
        response = self.view(request,
                             slug=self.project.slug,
                             pk=self.project.pk)
        self.project.refresh_from_db()
        eq_(self.project.crowdfunds.count(), 1,
            'A crowdfund should be created and added to the project.')
        crowdfund = self.project.crowdfunds.first()
        eq_(crowdfund.name, name)
        eq_(crowdfund.description, description)
        expected_payment_required = Decimal(payment_required +
                                            payment_required * .15) / 100
        eq_(
            crowdfund.payment_required, expected_payment_required,
            'Expected payment of %(expected).2f, actually %(actual).2f' % {
                'expected': expected_payment_required,
                'actual': crowdfund.payment_required
            })
        eq_(crowdfund.payment_capped, payment_capped)
        eq_(crowdfund.date_due, date_due)
        eq_(response.status_code, 302)
Exemplo n.º 10
0
 def test_set_projects(self):
     """Posting a group of projects to an article should set that article's projects."""
     project1 = ProjectFactory()
     project2 = ProjectFactory()
     staff = UserFactory(is_staff=True)
     project_form = ProjectManagerForm(
         {
             'projects': [project1.pk, project2.pk]
         },
         user=staff,
     )
     ok_(
         project_form.is_valid(),
         'We want to be sure we are posting valid data.'
     )
     data = {'action': 'projects'}
     data.update(project_form.data)
     response = self.post_helper(data, staff)
     self.article.refresh_from_db()
     project1.refresh_from_db()
     project2.refresh_from_db()
     ok_(response.status_code, 200)
     ok_(
         self.article in project1.articles.all(),
         'The article should be added to the project.'
     )
     ok_(
         self.article in project2.articles.all(),
         'The article should be added to teh project.'
     )
Exemplo n.º 11
0
 def setUp(self):
     self.user = UserFactory()
     project = ProjectFactory()
     project.contributors.add(self.user)
     self.kwargs = {"username": self.user.username}
     self.url = reverse("project-contributor", kwargs=self.kwargs)
     self.view = views.ProjectContributorView.as_view()
Exemplo n.º 12
0
def create_project_crowdfund():
    """Helper function to create a project crowdfund"""
    crowdfund = models.Crowdfund.objects.create(
        name='Cool project please help',
        payment_required=Decimal(50),
        date_due=(date.today() + timedelta(30)),
    )
    project = ProjectFactory()
    ProjectCrowdfunds.objects.create(crowdfund=crowdfund, project=project)
    return crowdfund
Exemplo n.º 13
0
    def test_projects(self):
        """Test bulk add to projects"""
        user = UserFactory()
        foia = FOIARequestFactory(composer__user=user)
        proj = ProjectFactory()
        proj.contributors.add(user)

        MyRequestList()._project(FOIARequest.objects.filter(pk=foia.pk), user,
                                 {"projects": [proj.pk]})

        foia.refresh_from_db()

        assert_in(proj, foia.projects.all())
Exemplo n.º 14
0
 def setUp(self):
     self.crowdfund = CrowdfundFactory()
     project = ProjectFactory()
     ProjectCrowdfunds.objects.create(crowdfund=self.crowdfund,
                                      project=project)
     self.url = self.crowdfund.get_absolute_url()
     self.data = {
         'amount': 200,
         'show': '',
         'crowdfund': self.crowdfund.pk,
         'email': '*****@*****.**'
     }
     self.request_factory = RequestFactory()
     self.view = CrowdfundDetailView.as_view()
Exemplo n.º 15
0
 def test_project_admin_can_view(self):
     """Project admin can view a crowdsource's details"""
     project = ProjectFactory()
     crowdsource = CrowdsourceFactory(project_admin=True, project=project)
     url = reverse(
         "crowdsource-detail",
         kwargs={"slug": crowdsource.slug, "idx": crowdsource.pk},
     )
     request = self.request_factory.get(url)
     request = mock_middleware(request)
     request.user = UserFactory()
     project.contributors.add(request.user)
     response = self.view(request, slug=crowdsource.slug, idx=crowdsource.pk)
     eq_(response.status_code, 200)
Exemplo n.º 16
0
 def setUp(self):
     self.crowdfund = CrowdfundFactory()
     project = ProjectFactory()
     ProjectCrowdfunds.objects.create(crowdfund=self.crowdfund,
                                      project=project)
     self.url = self.crowdfund.get_absolute_url()
     self.data = {
         "amount": 200,
         "show": "",
         "crowdfund": self.crowdfund.pk,
         "email": "*****@*****.**",
     }
     self.request_factory = RequestFactory()
     self.view = CrowdfundDetailView.as_view()
Exemplo n.º 17
0
 def test_owner(self):
     """Crowdsource owner can fill out a private assignment"""
     project = ProjectFactory()
     crowdsource = CrowdsourceFactory(
         status="open", project_only=True, project=project
     )
     url = reverse(
         "crowdsource-assignment",
         kwargs={"slug": crowdsource.slug, "idx": crowdsource.pk},
     )
     request = self.request_factory.get(url)
     request = mock_middleware(request)
     request.user = crowdsource.user
     response = self.view(request, slug=crowdsource.slug, idx=crowdsource.pk)
     eq_(response.status_code, 200)
Exemplo n.º 18
0
    def test_get_viewable(self):
        """Get the list of viewable crowdsources for the user"""
        project = ProjectFactory()
        admin = UserFactory(is_staff=True)
        proj_user, owner, user = UserFactory.create_batch(3)
        project.contributors.add(proj_user)

        draft_crowdsource = CrowdsourceFactory(user=owner, status='draft')
        open_crowdsource = CrowdsourceFactory(user=owner, status='open')
        closed_crowdsource = CrowdsourceFactory(user=owner, status='close')
        project_crowdsource = CrowdsourceFactory(
            user=owner,
            status='open',
            project=project,
            project_only=True,
        )

        crowdsources = Crowdsource.objects.get_viewable(admin)
        assert_in(draft_crowdsource, crowdsources)
        assert_in(open_crowdsource, crowdsources)
        assert_in(closed_crowdsource, crowdsources)
        assert_in(project_crowdsource, crowdsources)

        crowdsources = Crowdsource.objects.get_viewable(proj_user)
        assert_not_in(draft_crowdsource, crowdsources)
        assert_in(open_crowdsource, crowdsources)
        assert_not_in(closed_crowdsource, crowdsources)
        assert_in(project_crowdsource, crowdsources)

        crowdsources = Crowdsource.objects.get_viewable(owner)
        assert_in(draft_crowdsource, crowdsources)
        assert_in(open_crowdsource, crowdsources)
        assert_in(closed_crowdsource, crowdsources)
        assert_in(project_crowdsource, crowdsources)

        crowdsources = Crowdsource.objects.get_viewable(user)
        assert_not_in(draft_crowdsource, crowdsources)
        assert_in(open_crowdsource, crowdsources)
        assert_not_in(closed_crowdsource, crowdsources)
        assert_not_in(project_crowdsource, crowdsources)

        crowdsources = Crowdsource.objects.get_viewable(AnonymousUser())
        assert_not_in(draft_crowdsource, crowdsources)
        assert_in(open_crowdsource, crowdsources)
        assert_not_in(closed_crowdsource, crowdsources)
        assert_not_in(project_crowdsource, crowdsources)
Exemplo n.º 19
0
 def test_project_non_admin_cannot_view(self):
     """Project contributor cannot view a crowdsource's details if project
     admin option is not on
     """
     project = ProjectFactory()
     crowdsource = CrowdsourceFactory(project_admin=False, project=project)
     url = reverse('crowdsource-detail',
                   kwargs={
                       'slug': crowdsource.slug,
                       'idx': crowdsource.pk
                   })
     request = self.request_factory.get(url)
     request = mock_middleware(request)
     request.user = UserFactory()
     project.contributors.add(request.user)
     response = self.view(request,
                          slug=crowdsource.slug,
                          idx=crowdsource.pk)
     eq_(response.status_code, 302)
Exemplo n.º 20
0
 def test_private(self):
     """Everybody cannot fill out a private assignment"""
     project = ProjectFactory()
     crowdsource = CrowdsourceFactory(
         status='open',
         project_only=True,
         project=project,
     )
     url = reverse('crowdsource-assignment',
                   kwargs={
                       'slug': crowdsource.slug,
                       'idx': crowdsource.pk
                   })
     request = self.request_factory.get(url)
     request = mock_middleware(request)
     request.user = AnonymousUser()
     response = self.view(request,
                          slug=crowdsource.slug,
                          idx=crowdsource.pk)
     eq_(response.status_code, 302)
Exemplo n.º 21
0
 def test_project(self):
     """Project members can fill out a private assignment"""
     project = ProjectFactory()
     crowdsource = CrowdsourceFactory(
         status='open',
         project_only=True,
         project=project,
     )
     url = reverse('crowdsource-assignment',
                   kwargs={
                       'slug': crowdsource.slug,
                       'idx': crowdsource.pk
                   })
     request = self.request_factory.get(url)
     request = mock_middleware(request)
     request.user = UserFactory()
     project.contributors.add(request.user)
     response = self.view(request,
                          slug=crowdsource.slug,
                          idx=crowdsource.pk)
     eq_(response.status_code, 200)
Exemplo n.º 22
0
class TestProjectDetailView(TestCase):
    """Tests creating a project as a user."""

    def setUp(self):
        self.contributor = UserFactory()
        self.user = UserFactory()
        self.project = ProjectFactory()
        self.project.contributors.add(self.contributor)

        self.kwargs = {"slug": self.project.slug, "pk": self.project.pk}
        self.url = reverse("project-detail", kwargs=self.kwargs)
        self.view = views.ProjectDetailView.as_view()

    @raises(Http404)
    def test_private_user(self):
        """Users should not be able to see private projects"""
        self.project.private = True
        self.project.approved = False
        self.project.save()

        http_get_response(self.url, self.view, self.user, **self.kwargs)

    def test_private_contributor(self):
        """Contributors should be able to see private projects"""
        self.project.private = True
        self.project.approved = False
        self.project.save()

        response = http_get_response(
            self.url, self.view, self.contributor, **self.kwargs
        )
        eq_(response.status_code, 200)

    @raises(Http404)
    def test_pending_user(self):
        """Users should not be able to see pending projects"""
        self.project.private = False
        self.project.approved = False
        self.project.save()

        http_get_response(self.url, self.view, self.user, **self.kwargs)

    def test_pending_contributor(self):
        """Contributors should be able to see pending projects"""
        self.project.private = False
        self.project.approved = False
        self.project.save()

        response = http_get_response(
            self.url, self.view, self.contributor, **self.kwargs
        )
        eq_(response.status_code, 200)

    def test_public_user(self):
        """Users should be able to see public projects"""
        self.project.private = False
        self.project.approved = True
        self.project.save()

        response = http_get_response(self.url, self.view, self.user, **self.kwargs)
        eq_(response.status_code, 200)

    def test_public_contributor(self):
        """Contributors should be able to see public projects"""
        self.project.private = False
        self.project.approved = True
        self.project.save()

        response = http_get_response(
            self.url, self.view, self.contributor, **self.kwargs
        )
        eq_(response.status_code, 200)
Exemplo n.º 23
0
class TestProject(TestCase):
    """Projects are a mixture of general and specific information on a broad subject."""

    def setUp(self):
        self.project = ProjectFactory(title=test_title)

    def test_project_attributes(self):
        """
        All projects need at least a title.
        Projects should be private by default.
        Projects should be unapproved by default.
        Projects should have a statement describing their purpose
        and an image or illustration to accompany them.
        """
        ok_(self.project)
        eq_(self.project.title, test_title)
        ok_(self.project.private)
        ok_(not self.project.approved)
        self.project.summary = test_summary
        self.project.description = test_description
        self.project.image = test_image
        self.project.save()
        ok_(self.project)

    def test_project_unicode(self):
        """Projects should default to printing their title."""
        eq_(self.project.__unicode__(), test_title)

    def test_contributors(self):
        """
        A project should keep a list of contributors,
        but a list of contributors should not be required.
        """
        user1 = UserFactory()
        user2 = UserFactory()
        self.project.contributors.add(user1, user2)
        ok_(
            user1 in self.project.contributors.all()
            and user2 in self.project.contributors.all()
        )
        self.project.contributors.clear()
        eq_(len(self.project.contributors.all()), 0)

    def test_articles(self):
        """Projects should keep a list of relevant articles."""
        article1 = ArticleFactory()
        article2 = ArticleFactory()
        self.project.articles.add(article1, article2)
        ok_(article1 in self.project.articles.all())
        ok_(article2 in self.project.articles.all())
        self.project.articles.clear()
        eq_(len(self.project.articles.all()), 0)

    def test_requests(self):
        """Projects should keep a list of relevant FOIA requests."""
        request1 = FOIARequestFactory()
        request2 = FOIARequestFactory()
        self.project.requests.add(request1, request2)
        ok_(request1 in self.project.requests.all())
        ok_(request2 in self.project.requests.all())
        self.project.articles.clear()
        eq_(len(self.project.articles.all()), 0)

    def test_make_public(self):
        """Projects can be made public, but they shouldn't be approved."""
        self.project.make_public()
        ok_(not self.project.private)
        ok_(not self.project.approved)

    def test_has_contributors(self):
        """Projects should test to see if a given user is a contributor."""
        user1 = UserFactory()
        user2 = UserFactory()
        self.project.contributors.add(user1)
        ok_(self.project.has_contributor(user1))
        ok_(not self.project.has_contributor(user2))

    def test_editable_by(self):
        """Projects should test to see if a given user can edit a request."""
        user1 = UserFactory()
        user2 = UserFactory()
        self.project.contributors.add(user1)
        ok_(self.project.editable_by(user1))
        ok_(not self.project.editable_by(user2))

    def test_publish(self):
        """Publishing a project should make it public and submit it for approval."""
        explanation = 'Test'
        task = self.project.publish(explanation)
        eq_(self.project.private, False, 'The project should be made public.')
        eq_(
            self.project.approved, False,
            'The project should be waiting approval.'
        )
        ok_(
            isinstance(task, ProjectReviewTask),
            'A ProjectReviewTask should be created.\n\tTask: %s' % type(task)
        )

    def test_suggest_requests(self):
        """
        Projects should recommend requests to be added to them.
        They should recommend requests that intersect both the
        project's set of contributors and the project's set of tags.
        But projects should not recommend requests that they already contain.
        """
        # set up data
        tags = u'a'
        user = UserFactory()
        self.project.contributors.add(user)
        self.project.tags.add(tags)
        test_request = FOIARequestFactory(composer__user=user)
        test_request.tags.add(tags)
        # since they have the same user and tags, the project should suggest the request
        ok_(test_request in self.project.suggest_requests())
        # add the request to the project, then try again. it should not be suggested
        self.project.requests.add(test_request)
        ok_(test_request not in self.project.suggest_requests())

    def test_suggest_articles(self):
        """
        Projects should recommend articles to be added to them.
        They should recommend articles that intersect both the
        project's set of contributors and the project's set of tags.
        But projects should not recommend articles that they already contain.
        """
        # set up data
        tags = u'a'
        user = UserFactory()
        self.project.contributors.add(user)
        self.project.tags.add(tags)
        test_article = ArticleFactory()
        test_article.authors.add(user)
        test_article.tags.add(tags)
        # since they have the same user and tags, the project should suggest the article.
        ok_(test_article in self.project.suggest_articles())
        # add the article to the project, then try again. it should not be suggested
        self.project.articles.add(test_article)
        ok_(test_article not in self.project.suggest_articles())
Exemplo n.º 24
0
class TestProjectEditView(TestCase):
    """Contributors and staff may edit a project."""

    def setUp(self):
        # We will start with a project that's already been made.
        # We will give that project a single contributor.
        self.contributor = UserFactory()
        self.project = ProjectFactory()
        self.project.contributors.add(self.contributor)
        self.kwargs = {"slug": self.project.slug, "pk": self.project.pk}
        self.url = reverse("project-edit", kwargs=self.kwargs)
        self.view = views.ProjectEditView.as_view()

    def test_staff(self):
        """Staff users should be able to edit projects."""
        staff_user = UserFactory(is_staff=True)
        response = http_get_response(self.url, self.view, staff_user, **self.kwargs)
        eq_(response.status_code, 200)

    def test_contributor(self):
        """Contributors should be able to edit projects."""
        response = http_get_response(
            self.url, self.view, self.contributor, **self.kwargs
        )
        eq_(response.status_code, 200)

    @raises(Http404)
    def test_basic(self):
        """Basic users should not be able to edit projects."""
        user = UserFactory()
        http_get_response(self.url, self.view, user, **self.kwargs)

    def test_anonymous(self):
        """Logged out users cannot edit projects."""
        response = http_get_response(self.url, self.view, AnonymousUser())
        redirect_url = reverse("acct-login") + "?next=" + self.url
        eq_(response.status_code, 302, "The user should be redirected.")
        eq_(
            response.url,
            redirect_url,
            "The user should be redirected to the login page.",
        )

    def test_edit_description(self):
        """
        The description should be editable.
        When sending data, the 'edit' keyword should be set to 'description'.
        """
        desc = "Lorem ipsum"
        data = {"title": self.project.title, "description": desc, "tags": ""}
        form = forms.ProjectUpdateForm(data, instance=self.project)
        ok_(form.is_valid(), "The form should validate. %s" % form.errors)
        http_post_response(self.url, self.view, data, self.contributor, **self.kwargs)
        self.project.refresh_from_db()
        eq_(self.project.description, desc, "The description should be updated.")

    @mock.patch("muckrock.message.tasks.notify_project_contributor.delay")
    def test_add_contributors(self, mock_notify):
        """When adding contributors, each new contributor should get an email notification."""
        new_contributor = UserFactory()
        data = {
            "title": self.project.title,
            "contributors": [self.contributor.pk, new_contributor.pk],
            "tags": "",
        }
        form = forms.ProjectUpdateForm(data, instance=self.project)
        ok_(form.is_valid(), "The form should validate. %s" % form.errors)
        http_post_response(self.url, self.view, data, self.contributor, **self.kwargs)
        self.project.refresh_from_db()
        ok_(self.project.has_contributor(new_contributor))
        ok_(self.project.has_contributor(self.contributor))
        mock_notify.assert_called_once_with(
            new_contributor.pk, self.project.pk, self.contributor.pk
        )
Exemplo n.º 25
0
class TestProjectPublishView(TestCase):
    """Tests publishing a project."""

    def setUp(self):
        # We will start with a project that's already been made.
        self.project = ProjectFactory(private=True, approved=False)
        self.contributor = UserFactory()
        self.project.contributors.add(self.contributor)
        self.kwargs = {"slug": self.project.slug, "pk": self.project.pk}
        self.url = reverse("project-publish", kwargs=self.kwargs)
        self.view = views.ProjectPublishView.as_view()

    def test_staff(self):
        """Staff users should be able to publish projects."""
        staff_user = UserFactory(is_staff=True)
        response = http_get_response(self.url, self.view, staff_user, **self.kwargs)
        eq_(response.status_code, 200)

    def test_contributor(self):
        """Contributors should be able to delete projects."""
        response = http_get_response(
            self.url, self.view, self.contributor, **self.kwargs
        )
        eq_(response.status_code, 200)

    @raises(Http404)
    def test_basic(self):
        """Basic users should not be able to delete projects."""
        user = UserFactory()
        http_get_response(self.url, self.view, user, **self.kwargs)

    def test_anonymous(self):
        """Anonymous users cannot delete projects."""
        response = http_get_response(
            self.url, self.view, AnonymousUser(), **self.kwargs
        )
        redirect_url = reverse("acct-login") + "?next=" + self.url
        eq_(response.status_code, 302, "The user should be redirected.")
        eq_(
            response.url,
            redirect_url,
            "The user should be reidrected to the login screen.",
        )

    def test_pending(self):
        """Projects that are pending review should reject access to the Publish view."""
        pending_project = ProjectFactory(private=False, approved=False)
        pending_project.contributors.add(self.contributor)
        response = http_get_response(
            self.url,
            self.view,
            self.contributor,
            **{"slug": pending_project.slug, "pk": pending_project.pk}
        )
        eq_(response.status_code, 302)
        eq_(
            response.url,
            pending_project.get_absolute_url(),
            "The user should be redirected to the project.",
        )

    @mock.patch("muckrock.project.models.Project.publish")
    def test_post(self, mock_publish):
        """Posting a valid ProjectPublishForm should publish the project."""
        notes = "Testing project publishing"
        form = forms.ProjectPublishForm({"notes": notes})
        ok_(form.is_valid(), "The form should validate.")
        response = http_post_response(
            self.url, self.view, form.data, self.contributor, **self.kwargs
        )
        eq_(response.status_code, 302, "The user should be redirected.")
        eq_(
            response.url,
            self.project.get_absolute_url(),
            "The user should be redirected back to the project page.",
        )
        mock_publish.assert_called_with(notes)
Exemplo n.º 26
0
 def setUp(self):
     self.project = ProjectFactory(title=test_title)
Exemplo n.º 27
0
 def setUp(self):
     self.foia = FOIARequestFactory()
     self.map = Map.objects.create(title='Test map',
                                   project=ProjectFactory())
     self.marker = Marker.objects.create(map=self.map, foia=self.foia)
Exemplo n.º 28
0
 def setUp(self):
     self.project = ProjectFactory()
     self.map = Map.objects.create(title='Test map', project=self.project)
Exemplo n.º 29
0
 def test_notify_contributor(self, mock_send):
     """Notifies a contributor that they were added to a project."""
     project = ProjectFactory()
     added_by = UserFactory()
     tasks.notify_project_contributor(self.user, project, added_by)
     mock_send.assert_called_with(fail_silently=False)
Exemplo n.º 30
0
class TestProjectCrowdfundView(TestCase):
    """Tests the creation of a crowdfund for a project."""

    def setUp(self):
        self.project = ProjectFactory(private=False, approved=True)
        self.url = reverse(
            "project-crowdfund",
            kwargs={"slug": self.project.slug, "pk": self.project.pk},
        )
        self.view = views.ProjectCrowdfundView.as_view()
        self.request_factory = RequestFactory()

    def test_get(self):
        """Users should be able to GET the ProjectCrowdfundView."""
        user = UserFactory(is_staff=True)
        response = http_get_response(
            self.url, self.view, user, slug=self.project.slug, pk=self.project.pk
        )
        eq_(response.status_code, 200)

    def test_post(self):
        """Posting data for a crowdfund should create it."""
        user = UserFactory(is_staff=True)
        name = "Project Crowdfund"
        description = "A crowdfund"
        payment_required = 100
        payment_capped = True
        date_due = date.today() + timedelta(20)
        data = {
            "name": name,
            "description": description,
            "payment_required": payment_required,
            "payment_capped": payment_capped,
            "date_due": date_due,
        }
        request = self.request_factory.post(self.url, data)
        request.user = user
        request = mock_middleware(request)
        response = self.view(request, slug=self.project.slug, pk=self.project.pk)
        self.project.refresh_from_db()
        eq_(
            self.project.crowdfunds.count(),
            1,
            "A crowdfund should be created and added to the project.",
        )
        crowdfund = self.project.crowdfunds.first()
        eq_(crowdfund.name, name)
        eq_(crowdfund.description, description)
        expected_payment_required = (
            Decimal(payment_required + payment_required * 0.15) / 100
        )
        eq_(
            crowdfund.payment_required,
            expected_payment_required,
            "Expected payment of %(expected).2f, actually %(actual).2f"
            % {
                "expected": expected_payment_required,
                "actual": crowdfund.payment_required,
            },
        )
        eq_(crowdfund.payment_capped, payment_capped)
        eq_(crowdfund.date_due, date_due)
        eq_(response.status_code, 302)