Esempio n. 1
0
    def test_article(self):
        user = User.objects.create_user("testuser", "*****@*****.**", "pass")
        article = Article(
            title="My article", slug="my-article", author=user, status="private", content="Well, nothing interesting"
        )
        article.save()

        from_db = Article.objects.get(pk=article.id)

        # __unicode__
        self.assertEquals("My article", "%s" % from_db)

        # get_absolute_url()
        self.assertTrue(from_db.slug in from_db.get_absolute_url())

        # private()
        self.assertTrue(from_db.private)
Esempio n. 2
0
    def test_article(self):
        """Behaviour of the Article model"""
        # Create a user
        user = User.objects.create_user("testuser", "*****@*****.**", "pass")

        article = Article(
            title="Testing", slug="testing", author=user, status="private", content="This is a test article"
        )
        article.save()

        # This is not viewable by an anonymous user
        url = reverse("article", args=[article.slug])
        response = self.client.get(url)
        self.assertEquals(response.status_code, 404)

        # If the user is logged in, he can read it
        self.client.login(username="******", password="******")
        response = self.client.get(url)
        self.assertEquals(response.status_code, 200)
        self.assertTrue("This is a test article" in response.content)