From a666ab386089ef4fdc249c111ce2bf6d04f5064b Mon Sep 17 00:00:00 2001 From: Awakhiwe Khabo Date: Mon, 11 Mar 2024 16:42:53 +0000 Subject: [PATCH] Test User detail view for code 200, if url exists, if a valid user is returned --- backend/api/tests.py | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/backend/api/tests.py b/backend/api/tests.py index c1dc999..6888757 100644 --- a/backend/api/tests.py +++ b/backend/api/tests.py @@ -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="test_user@example.com", + 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"], "test_user@example.com") +