diff --git a/tests/test_records.py b/tests/test_records.py index cefbaf1..7f42cb2 100644 --- a/tests/test_records.py +++ b/tests/test_records.py @@ -17,6 +17,7 @@ build_records, ) from gentoo_build_publisher.records.django_orm import RecordDB as DjangoDB +from gentoo_build_publisher.records.memory import ApiKeyDB as MemoryApiKeyDB from gentoo_build_publisher.records.memory import RecordDB as MemoryDB from gentoo_build_publisher.settings import Settings from gentoo_build_publisher.types import ApiKey, Build @@ -376,6 +377,28 @@ def test_delete_when_does_not_exist(self, backend: str) -> None: records.delete("bogus") +class ApiKeysTests(TestCase): + def test_returns_requested_class(self) -> None: + settings = Settings( + RECORDS_BACKEND="memory", + STORAGE_PATH=Path("/dev/null"), + JENKINS_BASE_URL="http://jenkins.invalid/", + ) + obj = api_keys(settings) + + self.assertIsInstance(obj, MemoryApiKeyDB) + + def test_raises_lookuperror(self) -> None: + settings = Settings( + RECORDS_BACKEND="bogus", + STORAGE_PATH=Path("/dev/null"), + JENKINS_BASE_URL="http://jenkins.invalid/", + ) + + with self.assertRaises(LookupError): + api_keys(settings) + + class RepoTests(TestCase): @parametrized(BACKENDS) def test_from_settings(self, backend: str) -> None: