def test_omitting_nameless_speakers(self):
     nameless_speaker = SpeakerFactory()
     nameless_speaker.name = ""
     nameless_speaker.save()
     self.presentation.additional_speakers.add(nameless_speaker)
     response = self.client.get(self.presentation_url)
     nameless_speaker_url = reverse(
         "speaker_profile",
         args=[nameless_speaker.pk, nameless_speaker.slug],
     )
     self.assertNotContains(response, nameless_speaker_url)
Exemplo n.º 2
0
 def test_omitting_nameless_speakers(self):
     """Verify that speakers without a name do not appear."""
     presentation = PresentationFactory()
     speaker2 = SpeakerFactory()
     # Ensure that this speaker doesn't have a name.
     speaker2.name = ""
     speaker2.save()
     presentation.additional_speakers.add(speaker2)
     response = self.client.get(reverse("speaker_list"))
     # Since speaker2 is nameless, we check for a link to their
     # speaker page in the response instead of their
     # non-existent name.
     speaker2_url = reverse("speaker_profile",
                            args=[speaker2.pk, speaker2.slug])
     self.assertNotContains(response, speaker2_url)
Exemplo n.º 3
0
class ReviewingTestCase(object):
    """
    Base automated test case for reviewing application.

    This case has three required parameters:
    http_method_name (string) - either "get" or "post".
    reverse_view_name (string) - the name of the view to be reversed.
    reverse_view_args (list) - the arguments passed to the reversed view.

    """

    http_method_name = "get"
    reverse_view_args = None

    def _add_to_reviewers_group(self):
        self.user.groups.add(self.reviewers_group)
        self.user.save()

    def _create_proposals(self):
        """Create proposals if needed to test a view."""
        try:
            # If we already have a proposal, this is a DetailView
            # and we shouldn't create more.
            return [self.proposal]
        except AttributeError:
            return ProposalFactory.create_batch(size=randint(2, 5))

    def _i_am_the_speaker_now(self):
        """Make this testcase's user the primary speaker of the proposal."""
        # Create a reviewer (as a speaker profile).
        self.reviewer = SpeakerFactory()
        # Attach current user as the primary speaker on this proposal.
        self.proposal.speaker.user = self.user
        self.proposal.speaker.save()

    def _i_am_also_a_speaker_now(self):
        """Make this testcase's user an additional speaker on the proposal."""
        self.reviewer = SpeakerFactory()
        self.reviewer.user = self.user
        self.reviewer.save()
        AdditionalSpeaker.objects.create(
            proposalbase=self.proposal.proposalbase_ptr,
            speaker=self.reviewer,
            status=AdditionalSpeaker.SPEAKING_STATUS_ACCEPTED,
        )

    def _get_response(self):
        return self.client.get(
            reverse(self.reverse_view_name, args=self.reverse_view_args))

    def setUp(self):
        super(ReviewingTestCase, self).setUp()

        self.reviewers_group = Group.objects.get_or_create(name="Reviewers")[0]
        # The majority of tests require user login.
        self.client.login(username=self.user.email, password=self.password)

    def test_no_anonymous_access(self):
        """Verify that anonymous users cannot access the view."""
        self.client.logout()
        response = self._get_response()
        self.assertEqual(response.status_code, 403)

    def test_superuser_access(self):
        """Verify that superusers can access the view."""
        self._become_superuser()
        self.assertFalse(self.reviewers_group in self.user.groups.all())
        response = self._get_response()
        self.assertEqual(response.status_code, 200)

    def test_user_not_in_reviewers_group(self):
        """Verify that a non-reviewer cannot access the view."""
        self.assertFalse(self.reviewers_group in self.user.groups.all())
        response = self._get_response()
        self.assertEqual(response.status_code, 403)

    def test_user_in_reviewers_group(self):
        """Verify that a reviewer can access the view."""
        self._add_to_reviewers_group()
        self.assertTrue(self.reviewers_group in self.user.groups.all())
        response = self._get_response()
        self.assertEqual(response.status_code, 200)

    def test_blind_reviewing_types_as_reviewer(self):
        """Verify whether BLIND_REVIEWERS setting works properly."""
        # This is not applicable for POSTing views.
        if self.http_method_name == "post":
            return
        self._add_to_reviewers_group()
        proposals = self._create_proposals()
        for proposal in proposals:
            # Create feedback from a random user.
            ProposalFeedbackFactory(proposal=proposal)
            # Create feedback from the proposal's speaker.
            ProposalFeedbackFactory(proposal=proposal,
                                    author=proposal.speaker.user)

        with override_config(BLIND_REVIEWERS=True):
            response = self.client.get(
                reverse(self.reverse_view_name, args=self.reverse_view_args))
            for proposal in proposals:
                self.assertNotContains(response, proposal.speaker.name)
                self.assertNotContains(response,
                                       proposal.speaker.user.username)
                self.assertNotContains(response, proposal.speaker.email)

        with override_config(BLIND_REVIEWERS=False):
            response = self.client.get(
                reverse(self.reverse_view_name, args=self.reverse_view_args))
            for proposal in proposals:
                self.assertContains(response, proposal.speaker.name)

    def test_blind_reviewers_as_superuser(self):
        """Verify that superusers ignore the BLIND_REVIEWERS setting."""
        # This is not applicable for POSTing views.
        if self.http_method_name == "post":
            return
        self._become_superuser()
        proposals = self._create_proposals()
        for proposal in proposals:
            ProposalFeedbackFactory(proposal=proposal)

        with override_config(BLIND_REVIEWERS=True):
            response = self.client.get(
                reverse(self.reverse_view_name, args=self.reverse_view_args))
            self.assertContains(response, "Your superuser status")
            for proposal in proposals:
                self.assertContains(response, proposal.speaker.name)