*: improve general tests

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2023-01-04 22:26:55 +01:00
parent 24e8915e0a
commit 730139e43c
No known key found for this signature in database
7 changed files with 15 additions and 13 deletions

View File

@ -9,9 +9,7 @@ ENV_GIT_HASH_KEY = "GIT_BUILD_HASH"
def get_build_hash(fallback: Optional[str] = None) -> str: def get_build_hash(fallback: Optional[str] = None) -> str:
"""Get build hash""" """Get build hash"""
build_hash = environ.get(ENV_GIT_HASH_KEY, fallback if fallback else "") build_hash = environ.get(ENV_GIT_HASH_KEY, fallback if fallback else "")
if build_hash == "" and fallback: return fallback if build_hash == "" and fallback else build_hash
return fallback
return build_hash
def get_full_version() -> str: def get_full_version() -> str:

View File

@ -68,7 +68,7 @@ class ConfigView(APIView):
caps.append(Capabilities.CAN_GEO_IP) caps.append(Capabilities.CAN_GEO_IP)
if CONFIG.y_bool("impersonation"): if CONFIG.y_bool("impersonation"):
caps.append(Capabilities.CAN_IMPERSONATE) caps.append(Capabilities.CAN_IMPERSONATE)
if settings.DEBUG: if settings.DEBUG: # pragma: no cover
caps.append(Capabilities.CAN_DEBUG) caps.append(Capabilities.CAN_DEBUG)
return caps return caps

View File

@ -16,7 +16,7 @@ def serializer_tester_factory(test_model: Type[SerializerModel]) -> Callable:
"""Test serializer""" """Test serializer"""
def tester(self: TestModels): def tester(self: TestModels):
if test_model._meta.abstract: if test_model._meta.abstract: # pragma: no cover
return return
model_class = test_model() model_class = test_model()
self.assertTrue(isinstance(model_class, SerializerModel)) self.assertTrue(isinstance(model_class, SerializerModel))

View File

@ -26,8 +26,8 @@ class TestBlueprintOCI(TransactionTestCase):
self.assertEqual( self.assertEqual(
BlueprintInstance( BlueprintInstance(
path="https://ghcr.io/goauthentik/blueprints/test:latest" path="oci://ghcr.io/goauthentik/blueprints/test:latest"
).retrieve_oci(), ).retrieve(),
"foo", "foo",
) )
@ -40,7 +40,7 @@ class TestBlueprintOCI(TransactionTestCase):
with self.assertRaises(BlueprintRetrievalFailed): with self.assertRaises(BlueprintRetrievalFailed):
BlueprintInstance( BlueprintInstance(
path="https://ghcr.io/goauthentik/blueprints/test:latest" path="oci://ghcr.io/goauthentik/blueprints/test:latest"
).retrieve_oci() ).retrieve_oci()
def test_manifests_error_response(self): def test_manifests_error_response(self):
@ -53,7 +53,7 @@ class TestBlueprintOCI(TransactionTestCase):
with self.assertRaises(BlueprintRetrievalFailed): with self.assertRaises(BlueprintRetrievalFailed):
BlueprintInstance( BlueprintInstance(
path="https://ghcr.io/goauthentik/blueprints/test:latest" path="oci://ghcr.io/goauthentik/blueprints/test:latest"
).retrieve_oci() ).retrieve_oci()
def test_no_matching_blob(self): def test_no_matching_blob(self):
@ -72,7 +72,7 @@ class TestBlueprintOCI(TransactionTestCase):
) )
with self.assertRaises(BlueprintRetrievalFailed): with self.assertRaises(BlueprintRetrievalFailed):
BlueprintInstance( BlueprintInstance(
path="https://ghcr.io/goauthentik/blueprints/test:latest" path="oci://ghcr.io/goauthentik/blueprints/test:latest"
).retrieve_oci() ).retrieve_oci()
def test_blob_error(self): def test_blob_error(self):
@ -93,5 +93,5 @@ class TestBlueprintOCI(TransactionTestCase):
with self.assertRaises(BlueprintRetrievalFailed): with self.assertRaises(BlueprintRetrievalFailed):
BlueprintInstance( BlueprintInstance(
path="https://ghcr.io/goauthentik/blueprints/test:latest" path="oci://ghcr.io/goauthentik/blueprints/test:latest"
).retrieve_oci() ).retrieve_oci()

View File

@ -35,7 +35,7 @@ def source_tester_factory(test_model: type[Stage]) -> Callable:
def tester(self: TestModels): def tester(self: TestModels):
model_class = None model_class = None
if test_model._meta.abstract: if test_model._meta.abstract: # pragma: no cover
model_class = test_model.__bases__[0]() model_class = test_model.__bases__[0]()
else: else:
model_class = test_model() model_class = test_model()

View File

@ -19,7 +19,7 @@ def model_tester_factory(test_model: type[Stage]) -> Callable:
def tester(self: TestModels): def tester(self: TestModels):
try: try:
model_class = None model_class = None
if test_model._meta.abstract: if test_model._meta.abstract: # pragma: no cover
return return
model_class = test_model() model_class = test_model()
self.assertTrue(issubclass(model_class.serializer, BaseSerializer)) self.assertTrue(issubclass(model_class.serializer, BaseSerializer))

View File

@ -73,6 +73,9 @@ class TestUserWriteStage(FlowTestCase):
"username": "test-user-new", "username": "test-user-new",
"password": new_password, "password": new_password,
"attributes.some.custom-attribute": "test", "attributes.some.custom-attribute": "test",
"attributes": {
"foo": "bar",
},
"some_ignored_attribute": "bar", "some_ignored_attribute": "bar",
} }
session = self.client.session session = self.client.session
@ -89,6 +92,7 @@ class TestUserWriteStage(FlowTestCase):
self.assertTrue(user_qs.exists()) self.assertTrue(user_qs.exists())
self.assertTrue(user_qs.first().check_password(new_password)) self.assertTrue(user_qs.first().check_password(new_password))
self.assertEqual(user_qs.first().attributes["some"]["custom-attribute"], "test") self.assertEqual(user_qs.first().attributes["some"]["custom-attribute"], "test")
self.assertEqual(user_qs.first().attributes["foo"], "bar")
self.assertNotIn("some_ignored_attribute", user_qs.first().attributes) self.assertNotIn("some_ignored_attribute", user_qs.first().attributes)
@patch( @patch(