From 541465d1030ca11c7dd33a71aaa2aea170f3e148 Mon Sep 17 00:00:00 2001 From: kedod Date: Thu, 13 Jun 2019 16:00:10 +0200 Subject: [PATCH 1/4] modify tests --- .../app/app/tests/api/api_v1/test_users.py | 14 +++++++------- .../backend/app/app/tests/crud/test_user.py | 18 +++++++++--------- .../backend/app/app/tests/utils/user.py | 4 ++-- .../backend/app/app/tests/utils/utils.py | 5 ++++- .../backend/tests.dockerfile | 2 +- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/{{cookiecutter.project_slug}}/backend/app/app/tests/api/api_v1/test_users.py b/{{cookiecutter.project_slug}}/backend/app/app/tests/api/api_v1/test_users.py index 4d8b3bc101..abb7b87d03 100644 --- a/{{cookiecutter.project_slug}}/backend/app/app/tests/api/api_v1/test_users.py +++ b/{{cookiecutter.project_slug}}/backend/app/app/tests/api/api_v1/test_users.py @@ -4,7 +4,7 @@ from app.core import config from app.db.session import db_session from app.schemas.user import UserCreate -from app.tests.utils.utils import get_server_api, random_lower_string +from app.tests.utils.utils import get_server_api, random_lower_string, random_email def test_get_users_superuser_me(superuser_token_headers): @@ -33,7 +33,7 @@ def test_get_users_normal_user_me(normal_user_token_headers): def test_create_user_new_email(superuser_token_headers): server_api = get_server_api() - username = random_lower_string() + username = random_email() password = random_lower_string() data = {"email": username, "password": password} r = requests.post( @@ -49,7 +49,7 @@ def test_create_user_new_email(superuser_token_headers): def test_get_existing_user(superuser_token_headers): server_api = get_server_api() - username = random_lower_string() + username = random_email() password = random_lower_string() user_in = UserCreate(email=username, password=password) user = crud.user.create(db_session, obj_in=user_in) @@ -66,7 +66,7 @@ def test_get_existing_user(superuser_token_headers): def test_create_user_existing_username(superuser_token_headers): server_api = get_server_api() - username = random_lower_string() + username = random_email() # username = email password = random_lower_string() user_in = UserCreate(email=username, password=password) @@ -84,7 +84,7 @@ def test_create_user_existing_username(superuser_token_headers): def test_create_user_by_normal_user(normal_user_token_headers): server_api = get_server_api() - username = random_lower_string() + username = random_email() password = random_lower_string() data = {"email": username, "password": password} r = requests.post( @@ -97,12 +97,12 @@ def test_create_user_by_normal_user(normal_user_token_headers): def test_retrieve_users(superuser_token_headers): server_api = get_server_api() - username = random_lower_string() + username = random_email() password = random_lower_string() user_in = UserCreate(email=username, password=password) user = crud.user.create(db_session, obj_in=user_in) - username2 = random_lower_string() + username2 = random_email() password2 = random_lower_string() user_in2 = UserCreate(email=username2, password=password2) crud.user.create(db_session, obj_in=user_in2) diff --git a/{{cookiecutter.project_slug}}/backend/app/app/tests/crud/test_user.py b/{{cookiecutter.project_slug}}/backend/app/app/tests/crud/test_user.py index b4e73396c0..39cbf33e29 100644 --- a/{{cookiecutter.project_slug}}/backend/app/app/tests/crud/test_user.py +++ b/{{cookiecutter.project_slug}}/backend/app/app/tests/crud/test_user.py @@ -3,11 +3,11 @@ from app import crud from app.db.session import db_session from app.schemas.user import UserCreate -from app.tests.utils.utils import random_lower_string +from app.tests.utils.utils import random_lower_string, random_email def test_create_user(): - email = random_lower_string() + email = random_email() password = random_lower_string() user_in = UserCreate(email=email, password=password) user = crud.user.create(db_session, obj_in=user_in) @@ -16,7 +16,7 @@ def test_create_user(): def test_authenticate_user(): - email = random_lower_string() + email = random_email() password = random_lower_string() user_in = UserCreate(email=email, password=password) user = crud.user.create(db_session, obj_in=user_in) @@ -28,14 +28,14 @@ def test_authenticate_user(): def test_not_authenticate_user(): - email = random_lower_string() + email = random_email() password = random_lower_string() user = crud.user.authenticate(db_session, email=email, password=password) assert user is None def test_check_if_user_is_active(): - email = random_lower_string() + email = random_email() password = random_lower_string() user_in = UserCreate(email=email, password=password) user = crud.user.create(db_session, obj_in=user_in) @@ -44,7 +44,7 @@ def test_check_if_user_is_active(): def test_check_if_user_is_active_inactive(): - email = random_lower_string() + email = random_email() password = random_lower_string() user_in = UserCreate(email=email, password=password, disabled=True) user = crud.user.create(db_session, obj_in=user_in) @@ -53,7 +53,7 @@ def test_check_if_user_is_active_inactive(): def test_check_if_user_is_superuser(): - email = random_lower_string() + email = random_email() password = random_lower_string() user_in = UserCreate(email=email, password=password, is_superuser=True) user = crud.user.create(db_session, obj_in=user_in) @@ -62,7 +62,7 @@ def test_check_if_user_is_superuser(): def test_check_if_user_is_superuser_normal_user(): - username = random_lower_string() + username = random_email() password = random_lower_string() user_in = UserCreate(email=username, password=password) user = crud.user.create(db_session, obj_in=user_in) @@ -72,7 +72,7 @@ def test_check_if_user_is_superuser_normal_user(): def test_get_user(): password = random_lower_string() - username = random_lower_string() + username = random_email() user_in = UserCreate(email=username, password=password, is_superuser=True) user = crud.user.create(db_session, obj_in=user_in) user_2 = crud.user.get(db_session, id=user.id) diff --git a/{{cookiecutter.project_slug}}/backend/app/app/tests/utils/user.py b/{{cookiecutter.project_slug}}/backend/app/app/tests/utils/user.py index d8856607d3..f64b2e4b16 100644 --- a/{{cookiecutter.project_slug}}/backend/app/app/tests/utils/user.py +++ b/{{cookiecutter.project_slug}}/backend/app/app/tests/utils/user.py @@ -4,7 +4,7 @@ from app.core import config from app.db.session import db_session from app.schemas.user import UserCreate, UserUpdate -from app.tests.utils.utils import get_server_api, random_lower_string +from app.tests.utils.utils import get_server_api, random_lower_string, random_email def user_authentication_headers(server_api, email, password): @@ -18,7 +18,7 @@ def user_authentication_headers(server_api, email, password): def create_random_user(): - email = random_lower_string() + email = random_email() password = random_lower_string() user_in = UserCreate(username=email, email=email, password=password) user = crud.user.create(db_session=db_session, obj_in=user_in) diff --git a/{{cookiecutter.project_slug}}/backend/app/app/tests/utils/utils.py b/{{cookiecutter.project_slug}}/backend/app/app/tests/utils/utils.py index 9a8dd16952..36ae352c1e 100644 --- a/{{cookiecutter.project_slug}}/backend/app/app/tests/utils/utils.py +++ b/{{cookiecutter.project_slug}}/backend/app/app/tests/utils/utils.py @@ -2,7 +2,6 @@ import string import requests - from app.core import config @@ -10,6 +9,10 @@ def random_lower_string(): return "".join(random.choices(string.ascii_lowercase, k=32)) +def random_email(): + return f"{''.join(random.choices(string.ascii_lowercase, k=32))}@mail.com" + + def get_server_api(): server_name = f"http://{config.SERVER_NAME}" return server_name diff --git a/{{cookiecutter.project_slug}}/backend/tests.dockerfile b/{{cookiecutter.project_slug}}/backend/tests.dockerfile index 838dfcc7a9..d2e67a8177 100644 --- a/{{cookiecutter.project_slug}}/backend/tests.dockerfile +++ b/{{cookiecutter.project_slug}}/backend/tests.dockerfile @@ -1,6 +1,6 @@ FROM python:3.7 -RUN pip install requests pytest tenacity passlib[bcrypt] "fastapi>=0.16.0" psycopg2-binary SQLAlchemy +RUN pip install requests pytest tenacity passlib[bcrypt] "fastapi>=0.16.0" psycopg2-binary SQLAlchemy email_validator # For development, Jupyter remote kernel, Hydrogen # Using inside the container: From 0d8929bc6a7c1e58963c459bf233ba0c9a430942 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 6 Apr 2020 11:25:28 +0200 Subject: [PATCH 2/4] :heavy_plus_sign: Add email-validator to Dockerfiles --- {{cookiecutter.project_slug}}/backend/backend.dockerfile | 2 +- {{cookiecutter.project_slug}}/backend/celeryworker.dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/{{cookiecutter.project_slug}}/backend/backend.dockerfile b/{{cookiecutter.project_slug}}/backend/backend.dockerfile index e9aa21b9f3..4853dd56ff 100644 --- a/{{cookiecutter.project_slug}}/backend/backend.dockerfile +++ b/{{cookiecutter.project_slug}}/backend/backend.dockerfile @@ -1,6 +1,6 @@ FROM tiangolo/uvicorn-gunicorn-fastapi:python3.7 -RUN pip install celery~=4.3 passlib[bcrypt] tenacity requests emails "fastapi>=0.47.0" "uvicorn>=0.11.1" gunicorn pyjwt python-multipart email_validator jinja2 psycopg2-binary alembic SQLAlchemy +RUN pip install celery~=4.3 passlib[bcrypt] tenacity requests emails "fastapi>=0.47.0" "uvicorn>=0.11.1" gunicorn pyjwt python-multipart email_validator jinja2 psycopg2-binary alembic SQLAlchemy email_validator # For development, Jupyter remote kernel, Hydrogen # Using inside the container: diff --git a/{{cookiecutter.project_slug}}/backend/celeryworker.dockerfile b/{{cookiecutter.project_slug}}/backend/celeryworker.dockerfile index e2ac4a8881..0285ca8c06 100644 --- a/{{cookiecutter.project_slug}}/backend/celeryworker.dockerfile +++ b/{{cookiecutter.project_slug}}/backend/celeryworker.dockerfile @@ -1,6 +1,6 @@ FROM python:3.7 -RUN pip install raven celery~=4.3 passlib[bcrypt] tenacity requests "fastapi>=0.16.0" emails pyjwt email_validator jinja2 psycopg2-binary alembic SQLAlchemy +RUN pip install raven celery~=4.3 passlib[bcrypt] tenacity requests "fastapi>=0.16.0" emails pyjwt email_validator jinja2 psycopg2-binary alembic SQLAlchemy email_validator # For development, Jupyter remote kernel, Hydrogen # Using inside the container: From f9000d102840bc3e00f41f214c24645444b53d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 6 Apr 2020 11:25:44 +0200 Subject: [PATCH 3/4] :recycle: Update random email generation --- .../backend/app/app/tests/utils/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/{{cookiecutter.project_slug}}/backend/app/app/tests/utils/utils.py b/{{cookiecutter.project_slug}}/backend/app/app/tests/utils/utils.py index 36ae352c1e..20764695a6 100644 --- a/{{cookiecutter.project_slug}}/backend/app/app/tests/utils/utils.py +++ b/{{cookiecutter.project_slug}}/backend/app/app/tests/utils/utils.py @@ -10,7 +10,7 @@ def random_lower_string(): def random_email(): - return f"{''.join(random.choices(string.ascii_lowercase, k=32))}@mail.com" + return f"{random_lower_string()}@{random_lower_string()}.com" def get_server_api(): From 5aa4522d2956fe9afd9e69b48c3468f53973e7c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Ram=C3=ADrez?= Date: Mon, 6 Apr 2020 11:26:02 +0200 Subject: [PATCH 4/4] :recycle: Re-apply email validation after rebase --- .../backend/app/app/schemas/user.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/{{cookiecutter.project_slug}}/backend/app/app/schemas/user.py b/{{cookiecutter.project_slug}}/backend/app/app/schemas/user.py index ed776c53ad..d80e9066c1 100644 --- a/{{cookiecutter.project_slug}}/backend/app/app/schemas/user.py +++ b/{{cookiecutter.project_slug}}/backend/app/app/schemas/user.py @@ -1,11 +1,11 @@ from typing import Optional -from pydantic import BaseModel +from pydantic import BaseModel, EmailStr # Shared properties class UserBase(BaseModel): - email: Optional[str] = None + email: Optional[EmailStr] = None is_active: Optional[bool] = True is_superuser: Optional[bool] = False full_name: Optional[str] = None @@ -20,7 +20,7 @@ class Config: # Properties to receive via API on creation class UserCreate(UserBaseInDB): - email: str + email: EmailStr password: str