Skip to content

Commit

Permalink
modify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kedod committed Jun 13, 2019
1 parent a36ec99 commit c0da7bd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from app.db.session import db_session
from app.models.user import UserCreate
from app.tests.utils.user import user_authentication_headers
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):
Expand All @@ -22,7 +22,7 @@ def test_get_users_superuser_me(superuser_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(
Expand All @@ -38,7 +38,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, user_in=user_in)
Expand All @@ -55,7 +55,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)
Expand All @@ -73,7 +73,7 @@ def test_create_user_existing_username(superuser_token_headers):

def test_create_user_by_normal_user():
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, user_in=user_in)
Expand All @@ -87,12 +87,12 @@ def test_create_user_by_normal_user():

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, user_in=user_in)

username2 = random_lower_string()
username2 = random_email()
password2 = random_lower_string()
user_in2 = UserCreate(email=username2, password=password2)
user2 = crud.user.create(db_session, user_in=user_in2)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
from app import crud
from app.db.session import db_session
from app.models.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, user_in=user_in)
Expand All @@ -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, user_in=user_in)
Expand All @@ -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, user_in=user_in)
Expand All @@ -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)
print(user_in)
Expand All @@ -56,7 +56,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, user_in=user_in)
Expand All @@ -65,7 +65,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, user_in=user_in)
Expand All @@ -75,7 +75,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, user_in=user_in)
user_2 = crud.user.get(db_session, user_id=user.id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from app.core import config
from app.db.session import db_session
from app.models.user import UserCreate
from app.tests.utils.utils import random_lower_string
from app.tests.utils.utils import random_lower_string, random_email


def user_authentication_headers(server_api, email, password):
Expand All @@ -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, user_in=user_in)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
import string

import requests

from app.core import config


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
Expand Down
2 changes: 1 addition & 1 deletion {{cookiecutter.project_slug}}/backend/tests.dockerfile
Original file line number Diff line number Diff line change
@@ -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:
Expand Down

0 comments on commit c0da7bd

Please sign in to comment.