Ejemplo n.º 1
0
def createArticle(request, valid_form):
    new_article = Article(title=valid_form.cleaned_data['title'],
                          content=valid_form.cleaned_data['content'],
                          game_id=valid_form.cleaned_data['game_id'],
                          author=request.user,
                          date=datetime.datetime.now())
    return new_article
Ejemplo n.º 2
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)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def render(self, context):
     context[self.context_name] = Article.get_queryset().order_by("hit_count_generic")[:5]
     return ""