diff --git a/tests/conftest.py b/tests/conftest.py deleted file mode 100644 index 5ab8bb29..00000000 --- a/tests/conftest.py +++ /dev/null @@ -1,81 +0,0 @@ -import json -import os - -import pytest - -os.environ["ENV"] = "test" - -if os.getenv("ENV") not in ["test"]: - msg = f"ENV is not test, it is {os.getenv('ENV')}" - pytest.exit(msg) - -from fastapi.testclient import TestClient -from loguru import logger -from sqlmodel import SQLModel, create_engine - -from app.core.config import configs -from app.core.container import Container -from app.main import AppCreator -from app.model.post import Post -from app.model.user import User - - -def insert_default_data(conn): - user_default_file = open("./tests/test_data/users.json", "r") - user_default_data = json.load(user_default_file) - for user in user_default_data: - conn.execute( - User.__table__.insert(), - { - "email": user["email"], - "password": user["password"], - "user_token": user["user_token"], - "name": user["name"], - "is_active": user["is_active"], - "is_superuser": user["is_superuser"], - }, - ) - post_default_file = open("./tests/test_data/posts.json", "r") - post_default_data = json.load(post_default_file) - for post in post_default_data: - conn.execute( - Post.__table__.insert(), - { - "title": post["title"], - "content": post["content"], - "user_token": post["user_token"], - "is_published": post["is_published"], - }, - ) - - -def reset_db(): - engine = create_engine(configs.DATABASE_URI) - logger.info(engine) - with engine.begin() as conn: - if "test" in configs.DATABASE_URI: - SQLModel.metadata.drop_all(conn) - SQLModel.metadata.create_all(conn) - insert_default_data(conn) - else: - raise Exception("Not in test environment") - return engine - - -@pytest.fixture -def client(): - reset_db() - app_creator = AppCreator() - app = app_creator.app - with TestClient(app) as client: - yield client - - -@pytest.fixture -def container(): - return Container() - - -@pytest.fixture -def test_name(request): - return request.node.name diff --git a/tests/integration_tests/test_auth_router.py b/tests/integration_tests/test_auth_router.py deleted file mode 100644 index d5986fac..00000000 --- a/tests/integration_tests/test_auth_router.py +++ /dev/null @@ -1,24 +0,0 @@ -def test_sign_up_and_sign_in(client): - response = client.post( - "/api/v1/auth/sign-up", - json={"email": "test", "password": "test", "name": "test"}, - ) - assert response.status_code == 200 - response_json = response.json() - assert response_json["email"] == "test" - assert response_json["name"] == "test" - assert response_json["id"] > 0 - user_token = response_json["user_token"] - - response = client.post( - "/api/v1/auth/sign-in", - json={"email__eq": "test", "password": "test"}, - ) - - assert response.status_code == 200 - response_json = response.json() - assert response_json["user_info"]["email"] == "test" - assert response_json["user_info"]["name"] == "test" - assert response_json["user_info"]["id"] > 0 - assert response_json["user_info"]["user_token"] == user_token - assert response_json["access_token"] is not None diff --git a/tests/integration_tests/test_client.py b/tests/integration_tests/test_client.py deleted file mode 100644 index da9badd3..00000000 --- a/tests/integration_tests/test_client.py +++ /dev/null @@ -1,4 +0,0 @@ -def test_client(client): - response = client.get("/") - assert response.status_code == 200 - assert response.json() == "service is working" diff --git a/tests/test_data/posts.json b/tests/test_data/posts.json deleted file mode 100644 index 4a2451c7..00000000 --- a/tests/test_data/posts.json +++ /dev/null @@ -1,20 +0,0 @@ -[ - { - "user_token": "test1", - "title": "test1", - "content": "test1", - "is_published": true - }, - { - "user_token": "test2", - "title": "test2", - "content": "test2", - "is_published": true - }, - { - "user_token": "test_super", - "title": "test_super", - "content": "test_super", - "is_published": true - } -] diff --git a/tests/test_data/users.json b/tests/test_data/users.json deleted file mode 100644 index c7565fa2..00000000 --- a/tests/test_data/users.json +++ /dev/null @@ -1,26 +0,0 @@ -[ - { - "name": "test1", - "email": "test1@test1.com", - "user_token": "test1", - "password": "test1", - "is_active": true, - "is_superuser": false - }, - { - "name": "test2", - "email": "test2@test2.com", - "user_token": "test2", - "password": "test2", - "is_active": true, - "is_superuser": false - }, - { - "name": "test_super", - "email": "test_super@test_super.com", - "user_token": "test_super", - "password": "test_super", - "is_active": true, - "is_superuser": true - } -] diff --git a/tests/unit_tests/model/base_model.test.py b/tests/unit_tests/model/base_model.test.py new file mode 100644 index 00000000..e1c4bd5d --- /dev/null +++ b/tests/unit_tests/model/base_model.test.py @@ -0,0 +1,54 @@ +import pytest +from uuid import UUID +# Asegúrate de importar correctamente tu clase BaseModel +from app.model.base_model import BaseModel + + +def test_base_model_instantiation(): + model_instance = BaseModel() + assert isinstance(model_instance.id, UUID) + assert model_instance.created_at is not None + assert model_instance.updated_at is not None + + +def test_base_model_equality(): + model_instance1 = BaseModel() + model_instance2 = BaseModel() + assert model_instance1 != model_instance2 + + # Simular que model_instance2 es igual a model_instance1 + model_instance2.id = model_instance1.id + model_instance2.created_at = model_instance1.created_at + model_instance2.updated_at = model_instance1.updated_at + assert model_instance1 == model_instance2 + + +def test_base_model_ordering(): + model_instance1 = BaseModel() + model_instance2 = BaseModel() + assert model_instance1 != model_instance2 + assert (model_instance1 < model_instance2) or ( + model_instance1 > model_instance2) + + +def test_base_model_representation(): + model_instance = BaseModel() + str_representation = ( + f"BaseModel: {model_instance.id}, {model_instance.created_at}, " + "{model_instance.updated_at}" + ) + assert str(model_instance) == str_representation + assert repr(model_instance) == str_representation + + +def test_base_model_hash(): + model_instance = BaseModel() + assert isinstance(hash(model_instance), int) + + +@pytest.mark.parametrize("model_instance1,model_instance2,expected", [ + (BaseModel(), BaseModel(), False), + (BaseModel(), "not_a_model_instance", False), +]) +def test_base_model_inequality(model_instance1, model_instance2, expected): + assert (model_instance1 != model_instance2) is expected diff --git a/tests/unit_tests/test_container.py b/tests/unit_tests/test_container.py deleted file mode 100644 index 94a23a94..00000000 --- a/tests/unit_tests/test_container.py +++ /dev/null @@ -1,12 +0,0 @@ -from app.core.exceptions import NotFoundError - - -# It must raise an error -def test_container_with_intended_exception(container): - auth_service = container.auth_service() - try: - found_user = auth_service.get_by_id(1) - except NotFoundError as e: - assert True - return - # assert False diff --git a/tests/unit_tests/test_fixture.py b/tests/unit_tests/test_fixture.py deleted file mode 100644 index ac443aab..00000000 --- a/tests/unit_tests/test_fixture.py +++ /dev/null @@ -1,2 +0,0 @@ -def test_test_name_fixture(test_name): - assert test_name == "test_test_name_fixture"