-
-
Save waracci/93d2a3cecf6aa8dc4061a854538c1413 to your computer and use it in GitHub Desktop.
from django.test import TestCase | |
from rest_framework.test import APIClient | |
from rest_framework import status | |
class UserRegistrationTestCase(TestCase): | |
"""This class defines the test suite for the User authentication model.""" | |
def setUp(self): | |
"""Test setup for running tests.""" | |
self.registration_endpoint = "api/auth/v1/register" | |
self.client = APIClient() | |
self.user_data = { | |
"email": "[email protected]", | |
"password": "TestPassword1234", | |
"confirm_password": "TestPassword1234", | |
"username": "tested_user", | |
"bio": """I am passionate about tech, | |
collaborative initiatives and | |
building solutions that add value to society.""" | |
} | |
def test_user_can_register_successfully(self): | |
"""Test that the user can register successfully.""" | |
response = self.client.post( | |
self.registration_endpoint, | |
self.user_data, | |
format="json") | |
self.assertEqual(response.status_code, status.HTTP_201_CREATED) |
pep8 Compliant, except for some few issues on blank line spaces.
You can also define
api/auth/v1/
in the test setup and reuse it across the tests to ensure that you don't have multiple points of change in case the API endpoint changes.
Thanks @sharkdevs, let me ensure its pep8 compliant and also declare the endpoint as a variable.
The User model imported seems not to have been used, consider removing it.
Hi Warachi,
I can somehow follow your code though I realize that I have quite somethings to learn on DRF to be able to give you constructive feedback.
Good work. However, the blank spaces within the methods should be removed as I think they do not conform to PEP 8 standards
The User model imported seems not to have been used, consider removing it.
I noticed that too, I have removed it since it was not being used in my Tests
Good work. However, the blank spaces within the methods should be removed as I think they do not conform to PEP 8 standards
Thanks let me review accordingly!!!
pep8 Compliant, except for some few issues on blank line spaces.
You can also define
api/auth/v1/
in the test setup and reuse it across the tests to ensure that you don't have multiple points of change incase the API endpoint changes.