From ef2688b61af8555ae6b991dd6e9382cf6933219a Mon Sep 17 00:00:00 2001 From: yann Date: Fri, 22 Aug 2025 11:53:08 +0200 Subject: [PATCH] test dirs + fixture session/init in conftest --- tests/__init__.py | 0 tests/authentication/__init__.py | 0 tests/authentication/test_authentication.py | 9 ++++ tests/conftest.py | 53 +++++++++++++++++++++ tests/tools/__init__.py | 0 tests/tools/test_customertools.py | 6 +++ 6 files changed, 68 insertions(+) create mode 100644 tests/__init__.py create mode 100644 tests/authentication/__init__.py create mode 100644 tests/authentication/test_authentication.py create mode 100644 tests/conftest.py create mode 100644 tests/tools/__init__.py create mode 100644 tests/tools/test_customertools.py diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/authentication/__init__.py b/tests/authentication/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/authentication/test_authentication.py b/tests/authentication/test_authentication.py new file mode 100644 index 0000000..9b28724 --- /dev/null +++ b/tests/authentication/test_authentication.py @@ -0,0 +1,9 @@ + +class TestPasswordTool: + def test_check(self): + pass + + def get_by_name(self): + pass + + \ No newline at end of file diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 0000000..d74aa17 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,53 @@ +import pytest +from models import Base, Credentials, Collaborator, Customer, Contract, Event +from db import engine +from sqlalchemy.orm import Session +from passlib.hash import argon2 + +@pytest.fixture(scope="function") +def session(): + if not engine.url.get_backend_name() == "sqlite": + raise RuntimeError("Use SQLite backend to run tests\n" + "with command :\n" + "DB_URL=sqlite:///:memory: pytest -s -v .") + + Base.metadata.create_all(engine) + try: + with Session() as session: + yield session + finally: + Base.metadata.drop_all(engine) + + +@pytest.fixture(scope="function") +def seed(session): + session.add_all( + [ + Collaborator(name="Com", email="a", phone=1, team_id=1), + Collaborator(name="Man", email="b", phone=2, team_id=2), + Collaborator(name="Sup", email="c", phone=3, team_id=3), + Customer(name="Cust1", email="aa", phone=11, company="Cust1CO"), + Customer(name="Cust2", email="bb", phone=22, company="Cust2CO"), + ] + ) + session.commit() + session.add_all( + [ + Credentials(collaborator_id=1, + password_hash=argon2.hash("test")), + Credentials(collaborator_id=2, + password_hash=argon2.hash("test")), + Credentials(collaborator_id=3, + password_hash=argon2.hash("test")), + Contract(signed=0, amount=200000, customer_id=1, commercial_id=1), + ] + ) + session.commit() + session.add_all( + [ + Event(name="Event1", customer_contact="Test", + date_start="01.01.01", date_end="02.01.01", + location=".",contract_id=1, customer_id=1) + ] + ) + session.commit() \ No newline at end of file diff --git a/tests/tools/__init__.py b/tests/tools/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tests/tools/test_customertools.py b/tests/tools/test_customertools.py new file mode 100644 index 0000000..e4edebf --- /dev/null +++ b/tests/tools/test_customertools.py @@ -0,0 +1,6 @@ +from venv import create + +from sqlalchemy import delete + +class TestCustomerTools: + pass \ No newline at end of file