-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #95 from fga-eps-mds/feature/43-user-signup
#43 Cadastro de usuário
- Loading branch information
Showing
6 changed files
with
189 additions
and
18 deletions.
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
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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
Django==2.2 | ||
Django==2.2.4 | ||
djangorestframework==3.10 | ||
django-phonenumber-field==3.0 | ||
phonenumbers==8.10 | ||
djangorestframework_simplejwt | ||
django-cors-headers | ||
psycopg2==2.8.3 | ||
django-cors-headers==3.1.0 | ||
djangorestframework-simplejwt | ||
coverage |
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
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 |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import importlib | ||
import os | ||
import time | ||
|
||
import logging | ||
|
||
SERVICES_STARTED = False | ||
|
||
log = logging.getLogger('ej') | ||
|
||
|
||
def start_services(): | ||
global SERVICES_STARTED | ||
|
||
if SERVICES_STARTED: | ||
return | ||
|
||
start_postgres() | ||
|
||
SERVICES_STARTED = True | ||
|
||
|
||
def start_postgres(): | ||
# settings_path = os.environ['DJANGO_SETTINGS_MODULE'] | ||
# settings = importlib.import_module(settings_path) | ||
|
||
# db = settings.DATABASES['default'] | ||
dbname = 'postgres' # db['NAME'] | ||
user = 'postgres' # db['USER'] | ||
password = '' # db['PASSWORD'] | ||
host = 'db' # db['HOST'] | ||
|
||
for _ in range(100): | ||
if can_connect(dbname, user, password, host): | ||
log.info("Postgres is available. Continuing...") | ||
return | ||
log.warning('Postgres is unavailable. Retrying in 0.5 seconds') | ||
time.sleep(0.5) | ||
|
||
log.critical('Maximum number of attempts connecting to postgres database') | ||
raise RuntimeError('could not connect to database') | ||
|
||
|
||
def can_connect(dbname, user, password, host): | ||
import psycopg2 | ||
|
||
try: | ||
psycopg2.connect( | ||
dbname=dbname, | ||
user=user, | ||
password=password, | ||
host=host | ||
) | ||
except psycopg2.OperationalError: | ||
return False | ||
return True |
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
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 |
---|---|---|
|
@@ -2,8 +2,109 @@ | |
|
||
from rest_framework.test import APITestCase | ||
from django.urls import reverse | ||
from django.db import IntegrityError | ||
|
||
|
||
class UserRegistrationAPIViewTestCase(APITestCase): | ||
url = reverse('users:register') | ||
|
||
def test_different_password_on_password_confirmation(self): | ||
""" | ||
Test to try to create a user with a wrong verification password | ||
""" | ||
|
||
user_data = { | ||
"username": "vitas", | ||
"email": "[email protected]", | ||
"password": "VitasIsNice", | ||
"confirm_password": "VitasIsAwesome" | ||
} | ||
|
||
response = self.client.post(self.url, user_data) | ||
self.assertEqual(400, response.status_code) | ||
|
||
|
||
def test_password_less_than_8_characters(self): | ||
""" | ||
Test to try to create a user with a password less than 8 characters | ||
""" | ||
|
||
user_data = { | ||
"username": "vitas", | ||
"email": "[email protected]", | ||
"password": "HiVitas", | ||
"confirm_password": "HiVitas" | ||
} | ||
|
||
response = self.client.post(self.url, user_data) | ||
self.assertEqual(400, response.status_code) | ||
|
||
|
||
def test_unique_email_validation(self): | ||
""" | ||
Test to try to create a user with a registered email | ||
""" | ||
|
||
user1_data = { | ||
"username": "vitas", | ||
"email": "[email protected]", | ||
"password": "VitasIsAwesome", | ||
"confirm_password": "VitasIsAwesome" | ||
} | ||
user2_data = { | ||
"username": "Reanu_Reves", | ||
"email": "[email protected]", | ||
"password": "cyberpunk2077", | ||
"confirm_password": "cyberpunk2077" | ||
} | ||
response = self.client.post(self.url, user1_data) | ||
self.assertEqual(201, response.status_code) | ||
with self.assertRaises(IntegrityError): | ||
response = self.client.post(self.url, user2_data) | ||
|
||
|
||
def test_unique_username_validation(self): | ||
""" | ||
Test to try to create a user with a registered username | ||
""" | ||
|
||
user_data = { | ||
"username": "vitas", | ||
"email": "[email protected]", | ||
"password": "VitasIsAwesome", | ||
"confirm_password": "VitasIsAwesome" | ||
} | ||
|
||
response = self.client.post(self.url, user_data) | ||
self.assertEqual(201, response.status_code) | ||
|
||
user_data = { | ||
"username": "vitas", | ||
"email": "[email protected]", | ||
"password": "cyberpunk2077", | ||
"confirm_password": "cyberpunk2077" | ||
} | ||
|
||
response = self.client.post(self.url, user_data) | ||
self.assertEqual(400, response.status_code) | ||
|
||
|
||
def test_user_registration(self): | ||
""" | ||
Test to create a user with valid data | ||
""" | ||
|
||
user_data = { | ||
"username": "keanu_reeves", | ||
"email": "[email protected]", | ||
"password": "cyberpunk2077", | ||
"confirm_password": "cyberpunk2077" | ||
} | ||
|
||
response = self.client.post(self.url, user_data) | ||
self.assertEqual(201, response.status_code) | ||
|
||
|
||
class UserAuthenticationAPIViewTestCase(APITestCase): | ||
|
||
# SETUP | ||
|