From 7c3593d066d8d1f846aaff0954acc333a0013a57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Ur=C3=ADa?= Date: Sun, 15 Feb 2026 16:34:43 +0100 Subject: [PATCH] [UPD] Delete Library --- app/controller/__init__.py | 2 +- main.py | 2 +- tests/test_controller.py | 11 ++++++++--- tests/test_db.py | 12 ++++++++++-- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/app/controller/__init__.py b/app/controller/__init__.py index d75747b..80b3a81 100644 --- a/app/controller/__init__.py +++ b/app/controller/__init__.py @@ -80,6 +80,6 @@ class LibraryController: self.session.commit() def delete(self): - delete(self.session, self) + delete(self.session, self.data) del(self) diff --git a/main.py b/main.py index 990a848..6971ceb 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,4 @@ -__version__ = "0.2.0.dev" + from app import app from app.config import config diff --git a/tests/test_controller.py b/tests/test_controller.py index 645189e..2c78385 100644 --- a/tests/test_controller.py +++ b/tests/test_controller.py @@ -1,7 +1,7 @@ import os import unittest -from sqlalchemy.orm import sessionmaker +from sqlalchemy.exc import NoResultFound from app.api.actions import install from app.schema.library import Library, Tag, Book, BookTag, Path, Env @@ -135,8 +135,13 @@ class TestDB(unittest.TestCase): self.assertEqual(book.name, self.library.data.books[0].name) self.assertNotEqual(book.name, "Test book") - self.assertEqual(book.name, "Another Book on the shelf") - + self.assertEqual(book.name, "Another Book on the shelf") + + def test_delete_library(self): + library = LibraryController(1, engine=self.engine) + library.delete() + + self.assertRaises(NoResultFound, LibraryController, 1, engine=self.engine) if __name__ == "__main__": unittest.main() \ No newline at end of file diff --git a/tests/test_db.py b/tests/test_db.py index 9c374f0..cf2785d 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -2,11 +2,13 @@ import os import unittest from sqlalchemy.orm import sessionmaker +from sqlalchemy.exc import NoResultFound from app.api.actions import install -from app.api.cruds.base import create, read, update +from app.api.cruds.base import create, read, update, delete from app.schema.library import Library, Path, Env, Book, Tag, BookTag + import logging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) @@ -135,7 +137,13 @@ class TestDB(unittest.TestCase): self.assertEqual(book.name, self.library.books[0].name) self.assertNotEqual(book.name, "Test book") - self.assertEqual(book.name, "Another Book on the shelf") + self.assertEqual(book.name, "Another Book on the shelf") + + def test_delete_library(self): + library = read(self.session, 1, Library) + delete(self.session, library) + + self.assertRaises(NoResultFound, read, self.session, 1, Library) if __name__ == "__main__":