- Rename py/ directory to meld/ to eliminate PyPI 'py' package shadowing, which required conftest.py/path.py workarounds in the test suite - Remove meld/path.py (pytest stub no longer needed after rename) - Empty meld/__init__.py (removed redundant 'from . import path as path') - Replace 87-line conftest.py monkeypatch with minimal Package.setup() shim - Extract create_schema(cursor) from schema.py as single DDL source of truth, called by both init_db() and test helpers - Add permanent_delete, soft_delete, soft_delete_to_trash, restore_image, restore_image_with_rename, and collect_deleted_ancestors to repository.py to eliminate duplicated inline SQL across router.py and importer/service.py - Update all import paths, pyproject.toml, Makefile, CI config, and check_scripts to reference meld/ instead of py/
58 lines
1.9 KiB
Python
58 lines
1.9 KiB
Python
import unittest
|
|
|
|
from meld.image_manager.common.exceptions import (
|
|
ConflictError,
|
|
DatabaseError,
|
|
MeldError,
|
|
NotFoundError,
|
|
ValidationError,
|
|
)
|
|
|
|
|
|
class TestMeldErrorHierarchy(unittest.TestCase):
|
|
def test_meld_error_default_status_code(self) -> None:
|
|
self.assertEqual(MeldError.status_code, 500)
|
|
|
|
def test_not_found_error_status_code(self) -> None:
|
|
self.assertEqual(NotFoundError.status_code, 404)
|
|
|
|
def test_validation_error_status_code(self) -> None:
|
|
self.assertEqual(ValidationError.status_code, 400)
|
|
|
|
def test_conflict_error_status_code(self) -> None:
|
|
self.assertEqual(ConflictError.status_code, 409)
|
|
|
|
def test_database_error_status_code(self) -> None:
|
|
self.assertEqual(DatabaseError.status_code, 500)
|
|
|
|
def test_status_code_kwarg_override(self) -> None:
|
|
err = MeldError("custom", status_code=418)
|
|
self.assertEqual(err.status_code, 418)
|
|
|
|
def test_status_code_kwarg_override_subclass(self) -> None:
|
|
err = NotFoundError("not found", status_code=410)
|
|
self.assertEqual(err.status_code, 410)
|
|
|
|
def test_all_subclasses_are_meld_error(self) -> None:
|
|
for cls in (NotFoundError, ValidationError, ConflictError, DatabaseError):
|
|
with self.subTest(cls=cls):
|
|
instance = cls("msg")
|
|
self.assertIsInstance(instance, MeldError)
|
|
|
|
def test_meld_error_is_exception(self) -> None:
|
|
self.assertTrue(issubclass(MeldError, Exception))
|
|
|
|
def test_message_preserved(self) -> None:
|
|
err = ValidationError("bad input")
|
|
self.assertEqual(str(err), "bad input")
|
|
|
|
def test_instance_status_code_does_not_mutate_class(self) -> None:
|
|
original = NotFoundError.status_code
|
|
err = NotFoundError("test", status_code=410)
|
|
self.assertEqual(err.status_code, 410)
|
|
self.assertEqual(NotFoundError.status_code, original)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|