Skip to content

Commit 3593955

Browse files
committed
wip
1 parent 15b0b0c commit 3593955

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

tests/test_views.py

+18-13
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_all_posts_view(self):
4646
self.assertIsInstance(response.context["posts"][0], Post)
4747

4848
def test_home_view_anonymous_user(self):
49-
response = self.client.get(reverse("home"))
49+
response = self.client.get(reverse("home") + "/", follow=True)
5050
self.assertTemplateUsed(response, "blog/home.html")
5151
self.assertIsInstance(response.context["posts"][0], Post)
5252

@@ -225,11 +225,14 @@ def test_create_comment_view(self):
225225
"content": "Test comment",
226226
"post_slug": self.first_post.slug,
227227
},
228+
follow=True
229+
)
230+
# Check final redirect location and status
231+
self.assertRedirects(
232+
response,
233+
test_post_detail_url + "#comments",
234+
status_code=302
228235
)
229-
# Redirect to post detail page after comment submission
230-
self.assertEqual(response.status_code, 302)
231-
# Ensure redirect to post after comment submission
232-
self.assertRedirects(response, test_post_detail_url + "#comments")
233236
# Ensure a comment was added to the post
234237
self.assertEqual(self.first_post.comments.count(), first_post_comment_count + 1)
235238

@@ -371,14 +374,14 @@ def test_category_view_htmx_request(self):
371374
# self.assertTrue(response.context["page_obj"].has_previous())
372375

373376
def test_search_view_blank(self):
374-
response = self.client.get(reverse("blog-search"))
377+
response = self.client.get(reverse("blog-search"), follow=True)
375378
self.assertTemplateUsed(response, "blog/search_posts.html")
376379

377380
def test_search_view_anonymous(self):
378381
# If anonymous, should be able to find a post
379382
data = {"searched": self.first_post.title}
380-
response = self.client.get(reverse("blog-search"), data=data)
381-
383+
response = self.client.get(reverse("blog-search"), data=data, follow=True)
384+
self.assertTemplateUsed(response, "blog/search_posts.html")
382385
self.assertEqual(response.context["posts"][0], self.first_post)
383386

384387
def test_search_view_staff(self):
@@ -387,8 +390,8 @@ def test_search_view_staff(self):
387390
self.client.login(
388391
username=self.admin_user.username, password=self.admin_user_password
389392
)
390-
response = self.client.get(reverse("blog-search"), data=data)
391-
393+
response = self.client.get(reverse("blog-search"), data=data, follow=True)
394+
self.assertTemplateUsed(response, "blog/search_posts.html")
392395
posts_in_response = response.context["posts"]
393396
self.assertEqual(posts_in_response.count(), 1)
394397

@@ -525,10 +528,12 @@ def test_generate_gpt_input_title(self, mock_create):
525528
mock_create.return_value = {"choices": [{"text": "mocked response"}]}
526529
headers = {"HTTP_HX-Trigger": "generate-title"}
527530
response = self.client.post(
528-
"/generate-with-gpt/", data={"content": "my test blog content"}, **headers
531+
"/generate-with-gpt/",
532+
data={"content": "my test blog content"},
533+
**headers,
534+
follow=True
529535
)
530-
531-
self.assertIn("mocked response", response.content.decode())
536+
self.assertContains(response, "mocked response")
532537

533538
def test_generate_gpt_input_title_empty(self):
534539
headers = {"HTTP_HX-Trigger": "generate-title"}

0 commit comments

Comments
 (0)