From 1c21aeb1fe7d58529597e92e4d250c48597727c3 Mon Sep 17 00:00:00 2001 From: Albert Hopkins Date: Mon, 3 Jun 2024 17:34:44 -0500 Subject: [PATCH] tests: add tests for records.api_keys --- tests/test_records.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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: