Пример #1
0
 def test_success(self):
     username = test_utils.get_data()
     password = test_utils.get_data()
     test_utils.create_user(username, password)
     auth.authenticate(username=username, password=password)
     self.client.get(reverse("user_logout"))
     logged_in = test_utils.logged_in(self.client)
     self.assertFalse(logged_in)
Пример #2
0
 def test_success(self):
     username = test_utils.get_data(length=16)
     password = test_utils.get_data()
     test_utils.create_user(username, password)
     self.client.post(reverse("user_login"),
                      {"username": username,
                       "password": password})
     logged_in = test_utils.logged_in(self.client)
     self.assertTrue(logged_in)
Пример #3
0
 def test_no_results(self):
     response = self.client.get(reverse("blog_search"),
                                {"phrase": test_utils.get_data()})
     found_articles = response.context[-1]["found_articles"]
     self.assertFalse(found_articles)
     test_utils.create_article()
     response = self.client.get(reverse("blog_search"),
                                {"phrase": test_utils.get_data()})
     found_articles = response.context[-1]["found_articles"]
     self.assertFalse(list(found_articles))
Пример #4
0
    def test_single_article(self):
        # Wrong PK.
        response = self.client.get(reverse("blog_article",
                                   kwargs={"article_pk": 9999}))
        self.assertEqual(404, response.status_code)

        article = test_utils.create_article()

        # No slug.
        response = self.client.get(reverse("blog_article",
                                   kwargs={"article_pk": article.pk}))
        self.assertEqual(301, response.status_code)

        # Wrong slug.
        response = self.client.get(reverse(
            "blog_article",
            kwargs={
                "article_pk": article.pk,
                "slug": slugify(test_utils.get_data()),
            },
        ))
        self.assertEqual(301, response.status_code)

        # All OK.
        response = test_utils.request_article(self.client, article)
        self.assertEqual(200, response.status_code)
        self.assertIn(article.title, response.content)
        self.assertIn(article.content, response.content)
Пример #5
0
 def test_username_remembered_when_fail(self):
     username = test_utils.get_data(length=30)
     response = self.client.post(
         reverse("user_registration"),
         {"username": username},
     )
     self.assertIn(username, response.content)
Пример #6
0
 def test_comment_draft(self):
     article = test_utils.create_article(is_draft=True)
     test_utils.create_and_login_user(self.client)
     response = self.client.post(article.get_absolute_url(), {
         "article": article.pk,
         "content": test_utils.get_data(),
     })
     self.assertEqual(response.status_code, 404)
Пример #7
0
 def test_success(self):
     self.client.post(
         reverse("user_registration"),
         {
             "username": test_utils.get_data(length=30),
             "password1": "P4ssw0rd*",
             "password2": "P4ssw0rd*",
         },
     )
     self.assertTrue(User.objects.all().exists())
Пример #8
0
 def test_max_depth(self):
     """Tests that comment nesting isn't deeper than defined."""
     article = test_utils.create_article()
     comment1 = test_utils.create_comment(article=article)
     comment2 = test_utils.create_comment(article=article, parent=comment1)
     test_utils.create_and_login_user(self.client)
     self.client.post(article.get_absolute_url(), {
         "article": article.pk,
         "content": test_utils.get_data(),
         "parent": comment2.pk,
     })
     self.assertEqual(Comment.objects.count(),
                      settings.MAX_DEPTH_FOR_COMMENT)
Пример #9
0
 def test_honeypot(self):
     """Honeypot is CAPTCHA alternative."""
     response = self.client.post(
         reverse("user_registration"),
         {
             "username": test_utils.get_data(length=30),
             "password1": "P4ssw0rd*",
             "password2": "P4ssw0rd*",
             "im_bot": "on",
         },
     )
     self.assertEqual(response.status_code, 403)
     self.assertFalse(User.objects.all().exists())
Пример #10
0
 def test_fail(self):
     # No data.
     self.client.post(reverse("user_registration"))
     self.assertFalse(User.objects.all().exists())
     # Password mismatch.
     self.client.post(
         reverse("user_registration"),
         {
             "username": test_utils.get_data(length=30),
             "password1": "P4ssw0rd*",
             "password2": "P4ssw0rd",
         },
     )
     self.assertFalse(User.objects.all().exists())
Пример #11
0
 def test_add_comment(self):
     article = test_utils.create_article()
     # As anonymous.
     response = self.client.post(
         article.get_absolute_url(),
         {
             "article": article.pk,
             "content": test_utils.get_data(),
         }
     )
     self.assertEqual(response.status_code, 403)
     self.assertFalse(Article.objects.get(pk=article.pk).comment_set
                      .exists())
     # As member.
     test_utils.create_and_login_user(self.client)
     response = self.client.post(
         article.get_absolute_url(),
         {
             "article": article.pk,
             "content": test_utils.get_data(),
         }
     )
     self.assertTrue(Article.objects.get(pk=article.pk).comment_set
                     .exists())
Пример #12
0
 def test_moderated_automatically(self):
     article = test_utils.create_article(is_comments_moderated=True)
     user = test_utils.create_and_login_user(self.client)
     # Special cases aren't special enough.
     user.is_staff = True
     user.is_superuser = True
     user.save()
     self.client.post(
         article.get_absolute_url(),
         {
             "article": article.pk,
             "content": test_utils.get_data(),
         }
     )
     self.assertTrue(Comment.objects.get(article=article).is_moderated)
Пример #13
0
 def test_fail(self):
     self.client.post(reverse("user_login"),
                      {"username": test_utils.get_data(),
                       "password": test_utils.get_data()})
     logged_in = test_utils.logged_in(self.client)
     self.assertFalse(logged_in)