def test_delete_existing_article_with_other_existing_article(self):
     article_delete = create_article("heading", "my long content", -5)
     create_article("other heading", "my long content", -5)
     response = self.client.post(reverse("backend:delete"), {"pk":article_delete.id})
     self.assertTrue(response.status_code, 200)
     response = self.client.get(reverse("backend:index"))
     self.assertQuerysetEqual(response.context['latest_articles'], ['<Article: other heading>'])
 def test_view_with_multiple_past_and_multiple_future_article(self):
     create_article("past article", "", -5)
     create_article("very old article", "", -15)
     create_article("future article", "", 15)
     create_article("tomorrows article", "", 1)
     response = self.client.get(reverse("backend:index"))
     self.assertQuerysetEqual(response.context['latest_articles'], ['<Article: future article>','<Article: tomorrows article>','<Article: past article>','<Article: very old article>'])
 def test_form_edit_with_correct_data(self):
     article = create_article("my heading", "my long content", -5)
     response = self.client.post(reverse("backend:edit", args=(article.id,)), 
                                 {"heading":"new heading", "content":"new long content", "publication": timezone.now() + datetime.timedelta(days=5)})
     self.assertTrue(response.status_code, 200)
     response = self.client.get(reverse("backend:index"))
     self.assertQuerysetEqual(response.context['latest_articles'], ['<Article: new heading>'])
 def test_view_with_future_article(self):
     article_future = create_article("future article", "future article content", 5)
     response = self.client.get(reverse("backend:detail", args=(article_future.id,)))
     self.assertContains(response, article_future.heading)
     self.assertContains(response, article_future.content)
 def test_view_with_past_article(self):
     article_past = create_article("past article", "past article content", -5)
     response = self.client.get(reverse("backend:detail", args=(article_past.id,)))
     self.assertContains(response, article_past.heading)
     self.assertContains(response, article_past.content)
 def test_if_fields_are_set(self):
     article = create_article("my heading", "my long content", -5)
     response = self.client.get(reverse("backend:edit", args=(article.id,)))
     self.assertContains(response, article.heading)
     self.assertContains(response, article.content)
     self.assertContains(response, article.publication.strftime('%Y-%m-%d %H:%M'))
 def test_delete_not_existing_article(self):
     article = create_article("heading", "my long content", -5)
     response = self.client.post(reverse("backend:delete"), {"pk":article.id})
     self.assertTrue(response.status_code, 404)
 def test_delete_existing_article(self):
     article = create_article("heading", "my long content", -5)
     response = self.client.post(reverse("backend:delete"), {"pk":article.id})
     self.assertTrue(response.status_code, 200)
     response = self.client.get(reverse("backend:index"))
     self.assertContains(response, NO_ARTICLES_STRING)