Skip to content

Commit

Permalink
Test User detail view for code 200, if url exists, if a valid user is…
Browse files Browse the repository at this point in the history
… returned
  • Loading branch information
Awakhiwekyle committed Mar 11, 2024
1 parent 10ca9e7 commit a666ab3
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion backend/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,27 @@ def test_root_status_code(self):
url = reverse("api:api-root")
response = self.client.get(url, HTTP_HOST="example.com")
self.assertEqual(response.status_code, status.HTTP_200_OK)
# Assert that the response isn't empty and contains links
self.assertTrue(response.content)

class UserTestCase(TestCase):
def setUp(self):
self.user = CustomUser.objects.create(
username="test_user",
email="[email protected]",
password="test_password",
)

self.client.force_login(self.user)

def test_user_detail_view(self):
"""
Test User detail view for user information.
"""
url = reverse("api:user-detail", kwargs={"pk": self.user.pk})
response = self.client.get(url)

self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(url, f'/api/users/{self.user.pk}/')
self.assertEqual(response.json()["username"], "test_user")
self.assertEqual(response.json()["email"], "[email protected]")

0 comments on commit a666ab3

Please sign in to comment.