Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test User detail view #54

Merged
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
24 changes: 23 additions & 1 deletion backend/api/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ def test_post_create_view(self):
response, self.relative_profile_url, status_code=status.HTTP_201_CREATED
)


class APIRootTestCase(TestCase):
def test_root_status_code(self):
"""
Expand All @@ -79,5 +80,26 @@ 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]")
Loading