-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test User detail view for code 200, if url exists, if a valid user is…
… returned
- Loading branch information
1 parent
10ca9e7
commit a666ab3
Showing
1 changed file
with
23 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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]") | ||
|