# Path: tests/test_case.py
# class TestCase:
#     """
#     Created TestCase to avoid duplicated code in the other tests
#     """
#     TEST_DB = SqliteDatabase(':memory:')
# 
#     @classmethod
#     def setup_class(cls):
#         """
#         When a Test is created override the ``database`` attribute for all
#         the tables with a SqliteDatabase in memory.
#         """
#         for table in TABLES:
#             table._meta.database = cls.TEST_DB
#             table.create_table(fail_silently=True)
# 
#         cls.app = app.test_client()
# 
#     def setup_method(self):
#         """
#         When setting up a new test method clear all the tables
#         """
#         for table in TABLES:
#             table.delete().execute()
# 
# Path: tests/test_utils.py
# def add_user(email, password, id=None, first_name='John', last_name='Doe'):
#     """
#     Create a single user in the test database.
#     If an email is provided it will be used, otherwise it will be generated
#     by the function before adding the User to the database.
#     """
#     email = email or 'johndoe{}@email.com'.format(int(random.random() * 100))
# 
#     return User.create(
#         first_name=first_name,
#         last_name=last_name,
#         email=email,
#         password=User.hash_password(password),
#         uuid=id or uuid.uuid4(),
#     )


import json
from http.client import BAD_REQUEST, OK, UNAUTHORIZED
from tests.test_case import TestCase
from tests.test_utils import add_user



AUTH_API_ENDPOINT = '/auth/login/'
TEST_USER_PASSWORD = 'user_password'
TEST_USER_WRONG_PASSWORD = 'wrong_password'


class TestAuth(TestCase):

    def test_post_auth__success(self):
        user = add_user('user@email.com', TEST_USER_PASSWORD)

        data = json.dumps({
            "email": user.email,
            "password": TEST_USER_PASSWORD,
        })

        resp = self.app.post(AUTH_API_ENDPOINT, data=data,
                             content_type='application/json')

        assert resp.status_code == OK

    def test_post_auth__wrong_password(self):

# Path: tests/test_case.py
# class TestCase:
#     """
#     Created TestCase to avoid duplicated code in the other tests
#     """
#     TEST_DB = SqliteDatabase(':memory:')
# 
#     @classmethod
#     def setup_class(cls):
#         """
#         When a Test is created override the ``database`` attribute for all
#         the tables with a SqliteDatabase in memory.
#         """
#         for table in TABLES:
#             table._meta.database = cls.TEST_DB
#             table.create_table(fail_silently=True)
# 
#         cls.app = app.test_client()
# 
#     def setup_method(self):
#         """
#         When setting up a new test method clear all the tables
#         """
#         for table in TABLES:
#             table.delete().execute()
# 
# Path: tests/test_utils.py
# def add_user(email, password, id=None, first_name='John', last_name='Doe'):
#     """
#     Create a single user in the test database.
#     If an email is provided it will be used, otherwise it will be generated
#     by the function before adding the User to the database.
#     """
#     email = email or 'johndoe{}@email.com'.format(int(random.random() * 100))
# 
#     return User.create(
#         first_name=first_name,
#         last_name=last_name,
#         email=email,
#         password=User.hash_password(password),
#         uuid=id or uuid.uuid4(),
#     )


# Path: tests/test_auth.py
import json
from http.client import BAD_REQUEST, OK, UNAUTHORIZED
from tests.test_case import TestCase
from tests.test_utils import add_user




AUTH_API_ENDPOINT = '/auth/login/'
TEST_USER_PASSWORD = 'user_password'
TEST_USER_WRONG_PASSWORD = 'wrong_password'


class TestAuth(TestCase):

    def test_post_auth__success(self):
        user = add_user('user@email.com', TEST_USER_PASSWORD)

        data = json.dumps({
            "email": user.email,
            "password": TEST_USER_PASSWORD,
        })

        resp = self.app.post(AUTH_API_ENDPOINT, data=data,
                             content_type='application/json')

        assert resp.status_code == OK

    def test_post_auth__wrong_password(self):

        user = add_user('user@email.com', TEST_USER_PASSWORD)