Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions project/accounts/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.contrib.auth import views as auth_views
from django.test import TestCase
from django.urls import resolve, reverse
from threads.models import Civi, Thread


class BaseTestCase(TestCase):
Expand Down Expand Up @@ -215,3 +216,39 @@ def test_get_user_profile(self):
self.assertEqual(response.status_code, 200)
self.assertContains(response, self.user.username)
self.assertTemplateUsed(response, "account.html")


class UserProfileCivis(BaseTestCase):
"""A class to test user profiles following view"""

def setUp(self) -> None:
super(UserProfileCivis, self).setUp()

self.user2 = get_user_model().objects.create_user(
username="newuser2", email="[email protected]", password="password123"
)

thread = Thread(
author=self.user2, title="test thread", summary="this is a test thread"
)
thread.save()
civi = Civi(author=self.user, thread=thread, title="test civi title")
civi.save()

def test_get_my_civis(self):
"""Whether user_profile function works as expected"""

self.client.login(username="newuser", password="password123")
response = self.client.get(reverse("user-civis", args=["newuser"]))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "test civi title")
self.assertTemplateUsed(response, "user_civis.html")

def test_get_other_civis(self):
"""Whether user_profile function works as expected"""

self.client.login(username="newuser2", password="password123")
response = self.client.get(reverse("user-civis", args=["newuser"]))
self.assertEqual(response.status_code, 200)
self.assertContains(response, "test civi title")
self.assertTemplateUsed(response, "user_civis.html")