Пример #1
0
    def test_invite_view_post_valid(self):
        email_address = '*****@*****.**'
        data = {'email_address': email_address}
        self.assertEqual(
            0, len(Invitation.objects.filter(email_address=email_address)))

        anonymous_client = testing.get_client()
        response = anonymous_client.post(reverse('invite'), data, follow=True)
        self.assertRedirects(response, self._INVITE_LOGIN_URL)
        self.assertEqual(
            0, len(Invitation.objects.filter(email_address=email_address)))

        regular_client = testing.get_client(testing.create_user())
        response = regular_client.post(reverse('invite'), data)
        self.assertEqual(403, response.status_code)
        self.assertEqual(
            0, len(Invitation.objects.filter(email_address=email_address)))

        self.assertEqual(0, len(mail.outbox))
        allowed_client = testing.get_client(testing.create_user(
            perms=['piosenka.invite']))
        response = allowed_client.post(reverse('invite'), data)
        self.assertEqual(302, response.status_code)
        self.assertRedirects(response, reverse('index'))  # Redirect on success.

        self.assertEqual(
            1, len(Invitation.objects.filter(email_address=email_address)))
        self.assertEqual(1, len(mail.outbox))
        self.assertEqual([email_address], mail.outbox[0].to)
Пример #2
0
    def test_join_view_post_valid(self):
        email_address = '*****@*****.**'
        invitation = Invitation.create_for_testing(email_address,
                                                   testing.create_user())
        self.assertTrue(invitation.is_valid)

        anonymous_client = testing.get_client()
        response = anonymous_client.post(invitation.get_invitation_url(),
                                         self._JOIN_DATA)
        self.assertRedirects(response, reverse('index'))  # Redirect on success.

        invitation.refresh_from_db()
        self.assertFalse(invitation.is_valid)
        self.assertEqual(1, len(User.objects.filter(email=email_address)))

        new_user = User.objects.get(email=email_address)
        self.assertEqual(1, new_user.groups.count())
        self.assertEqual('everyone',
                         new_user.groups.values_list('name', flat=True)[0])

        another_client = testing.get_client()
        response = another_client.post(invitation.get_invitation_url(),
                                       self._JOIN_DATA)
        self.assertEqual(404, response.status_code)

        response = another_client.get(invitation.get_invitation_url())
        self.assertEqual(404, response.status_code)
Пример #3
0
    def test_invite_view_post_empty(self):
        anonymous_client = testing.get_client()
        response = anonymous_client.post(reverse('invite'), follow=True)
        self.assertRedirects(response, self._INVITE_LOGIN_URL)

        regular_client = testing.get_client(testing.create_user())
        response = regular_client.post(reverse('invite'))
        self.assertEqual(403, response.status_code)

        allowed_client = testing.get_client(testing.create_user(
            perms=['piosenka.invite']))
        response = allowed_client.post(reverse('invite'))
        self.assertEqual(200, response.status_code)
Пример #4
0
    def test_join_view_get(self):
        invitation = Invitation.create_for_testing('*****@*****.**',
                                                   testing.create_user())

        anonymous_client = testing.get_client()
        response = anonymous_client.get(invitation.get_invitation_url())
        self.assertEqual(200, response.status_code)

        regular_client = testing.get_client(testing.create_user())
        response = regular_client.get(invitation.get_invitation_url())
        self.assertEqual(404, response.status_code)

        allowed_client = testing.get_client(testing.create_user(
            perms=['piosenka.invite']))
        response = allowed_client.get(invitation.get_invitation_url())
        self.assertEqual(404, response.status_code)
Пример #5
0
    def test_review_item(self):
        """Tests the review helper view."""
        # Add a new item.
        author = testing.create_user()
        item = self.item_cls.create_for_testing(author)
        self.assertFalse(item.is_live())

        # Verify that anonymous user is redirected to login.
        response = testing.get_public_client().get(item.get_review_url())
        self.assertEqual(302, response.status_code)
        self.assertTrue(reverse('hello') in response.url)

        # The author should be redirected to the actual item with some
        # informative message.
        response = testing.get_client(author).get(
            item.get_review_url(), follow=True)
        self.assertRedirects(response, item.get_absolute_url())
        self.assertTrue('messages' in response.context)
        self.assertEqual(1, len(response.context['messages']))

        # Another regular user should be redirected too.
        response = testing.get_user_client().get(
            item.get_review_url(), follow=True)
        self.assertRedirects(response, item.get_absolute_url())
        self.assertTrue('messages' in response.context)
        self.assertEqual(1, len(response.context['messages']))

        # And the valid approver too.
        reviewer = testing.create_user(perms=['content.review'])
        response = testing.get_client(reviewer).get(
            item.get_review_url(), follow=True)
        self.assertRedirects(response, item.get_absolute_url())
        self.assertTrue('messages' in response.context)
        self.assertEqual(1, len(response.context['messages']))

        # After the item is live too.
        item.reviewed = True
        item.save()
        response = testing.get_client(reviewer).get(
            item.get_review_url(), follow=True)
        self.assertRedirects(response, item.get_absolute_url())
        self.assertTrue('messages' in response.context)
        self.assertEqual(1, len(response.context['messages']))
Пример #6
0
    def test_join_view_post_empty(self):
        email_address = '*****@*****.**'
        invitation = Invitation.create_for_testing(email_address,
                                                   testing.create_user())
        self.assertTrue(invitation.is_valid)

        anonymous_client = testing.get_client()
        response = anonymous_client.post(invitation.get_invitation_url())
        self.assertEqual(200, response.status_code)

        invitation.refresh_from_db()
        self.assertTrue(invitation.is_valid)
        self.assertEqual(0, len(User.objects.filter(email=email_address)))
Пример #7
0
    def test_join_view_expired(self):
        email_address = '*****@*****.**'
        invitation = Invitation.create_for_testing(email_address,
                                                   testing.create_user())
        invitation.expires_on = timezone.now() - timedelta(days=1)
        invitation.save()
        self.assertTrue(invitation.is_valid)

        anonymous_client = testing.get_client()
        response = anonymous_client.post(invitation.get_invitation_url(),
                                         self._JOIN_DATA)
        self.assertEqual(404, response.status_code)

        invitation.refresh_from_db()
        self.assertTrue(invitation.is_valid)
        self.assertEqual(0, len(User.objects.filter(email=email_address)))