[REF] Refactor

This commit is contained in:
2026-02-13 13:35:18 +01:00
parent b00c35f19b
commit dc819b1674
29 changed files with 101 additions and 80 deletions

71
tests/test_db.py Normal file
View File

@@ -0,0 +1,71 @@
import os
import unittest
from sqlalchemy.orm import sessionmaker
from app.api.actions import install
from app.api.cruds.library import create, read
from app.schema.library import Library, Path, Env
import logging
logger = logging.getLogger(__name__)
class TestDB(unittest.TestCase):
def setUp(self):
os.environ["DEV_URIA_BIBLIOGAME_CONFIG_DB"] = "sqlite:///"
os.environ["DEV_URIA_BIBLIOGAME_DEBUG"] = "true"
self.engine = install()
self.library = Library(
name="Library Test",
notes="My duckling library test",
paths=[
Path(
path="/home/ivan/Documentos/ttprpg"
)
],
envs=[
Env(
key="ENVIRONMENT_VARIABLE",
value="Clearly an environment variable"
)
]
)
self.Session = sessionmaker(bind=self.engine)
self.session = self.Session()
create(self.session, self.library)
return super().setUp()
def test_install(self):
library_string = str(read(self.session, 1))
self.assertEqual(library_string, str(self.library))
def test_read_name(self):
library = read(self.session, 1)
logger.debug(f"Name: {library.name}")
self.assertEqual(library.name, self.library.name)
self.assertEqual(library.name, "Library Test")
def test_read_notes(self):
library = read(self.session, 1)
logger.debug(f"Notes: {library.notes}")
self.assertEqual(library.notes, self.library.notes)
self.assertEqual(library.notes, "My duckling library test")
def test_read_path(self):
library = read(self.session, 1)
logger.debug(f"PATH: {library.paths[0].path}")
self.assertEqual(library.paths[0].path, self.library.paths[0].path)
self.assertEqual(library.paths[0].path, "/home/ivan/Documentos/ttprpg")
def test_read_env(self):
library = read(self.session, 1)
logger.debug(f"ENV: {library.envs[0].key} - {library.envs[0].value}")
self.assertEqual(library.envs[0].key, self.library.envs[0].key)
self.assertEqual(library.envs[0].value, self.library.envs[0].value)
self.assertEqual(library.envs[0].key, "ENVIRONMENT_VARIABLE")
self.assertEqual(library.envs[0].value, "Clearly an environment variable")
if __name__ == "__main__":
unittest.main()