[UPD] Added LibraryController

This commit is contained in:
2026-02-14 18:37:48 +01:00
parent 5fc1dc1b82
commit 5f7b4102bc
13 changed files with 257 additions and 36 deletions

View File

@@ -4,7 +4,7 @@ import unittest
from sqlalchemy.orm import sessionmaker
from app.api.actions import install
from app.api.cruds.library import create, read, update
from app.api.cruds.base import create, read, update
from app.schema.library import Library, Path, Env, Book, Tag, BookTag
import logging
@@ -57,29 +57,29 @@ class TestDB(unittest.TestCase):
return super().setUp()
def test_install(self):
library_string = str(read(self.session, 1))
library_string = str(read(self.session, 1, Library))
self.assertEqual(library_string, str(self.library))
def test_read_name(self):
library = read(self.session, 1)
library = read(self.session, 1, Library)
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)
library = read(self.session, 1, Library)
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)
library = read(self.session, 1, Library)
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)
library = read(self.session, 1, Library)
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)
@@ -87,14 +87,14 @@ class TestDB(unittest.TestCase):
self.assertEqual(library.envs[0].value, "Clearly an environment variable")
def test_read_book(self):
library = read(self.session, 1)
library = read(self.session, 1, Library)
book = library.books[0]
logger.debug(f"BOOK: {book}")
self.assertEqual(book.name, self.library.books[0].name)
self.assertEqual(book.name, "Test book")
def test_read_tags(self):
library = read(self.session, 1)
library = read(self.session, 1, Library)
tags = library.tags
self.assertEqual(tags, self.library.tags)
self.assertEqual(tags, self.tags)
@@ -106,7 +106,7 @@ class TestDB(unittest.TestCase):
self.assertEqual(tags[1].name, "Bar")
def test_read_book_tags(self):
library = read(self.session, 1)
library = read(self.session, 1, Library)
book = library.books[0]
tags = library.tags
logger.debug(f"BOOK TAGS: {book.tags}")
@@ -117,7 +117,7 @@ class TestDB(unittest.TestCase):
self.assertNotEqual(book.tags[0].tag.name, "Bar")
def test_update_name(self):
library = read(self.session, 1)
library = read(self.session, 1, Library)
library.name = "Another Library"
update(self.session, library)
library1 = read(self.session, 1)
@@ -126,11 +126,11 @@ class TestDB(unittest.TestCase):
self.assertEqual(library1.name, "Another Library")
def test_update_name(self):
library = read(self.session, 1)
library = read(self.session, 1, Library)
library.books[0].name = "Another Book on the shelf"
update(self.session, library)
library1 = read(self.session, 1)
library1 = read(self.session, 1, Library)
book = library1.books[0]
self.assertEqual(book.name, self.library.books[0].name)