Skip to content

Instantly share code, notes, and snippets.

@waracci
Last active December 19, 2018 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waracci/93d2a3cecf6aa8dc4061a854538c1413 to your computer and use it in GitHub Desktop.
Save waracci/93d2a3cecf6aa8dc4061a854538c1413 to your computer and use it in GitHub Desktop.
Test that a user registers with correct details (Email and password)
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": "test_user@mail.com",
"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)
@sharkdevs
Copy link

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.

@waracci
Copy link
Author

waracci commented Dec 19, 2018

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.

@johnwayodi
Copy link

The User model imported seems not to have been used, consider removing it.

@Teatoller
Copy link

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.

@Paulvitalis200
Copy link

Paulvitalis200 commented Dec 19, 2018

Good work. However, the blank spaces within the methods should be removed as I think they do not conform to PEP 8 standards

@waracci
Copy link
Author

waracci commented Dec 19, 2018

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

@waracci
Copy link
Author

waracci commented Dec 19, 2018

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!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment