lib: add more tests

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-27 15:20:23 +02:00
parent d2abe6d455
commit cad6c42fdd
3 changed files with 19 additions and 1 deletions

View File

@ -33,7 +33,7 @@ class CertificateBuilder:
def save(self) -> Optional[CertificateKeyPair]: def save(self) -> Optional[CertificateKeyPair]:
"""Save generated certificate as model""" """Save generated certificate as model"""
if not self.__certificate: if not self.__certificate:
return None raise ValueError("Certificated hasn't been built yet")
return CertificateKeyPair.objects.create( return CertificateKeyPair.objects.create(
name=self.common_name, name=self.common_name,
certificate_data=self.certificate, certificate_data=self.certificate,

View File

@ -37,6 +37,8 @@ class TestCrypto(TestCase):
"""Test Builder""" """Test Builder"""
builder = CertificateBuilder() builder = CertificateBuilder()
builder.common_name = "test-cert" builder.common_name = "test-cert"
with self.assertRaises(ValueError):
builder.save()
builder.build( builder.build(
subject_alt_names=[], subject_alt_names=[],
validity_days=3, validity_days=3,

View File

@ -0,0 +1,16 @@
"""Test Reflection utils"""
from datetime import datetime
from django.test import TestCase
from authentik.lib.utils.reflection import path_to_class
class TestReflectionUtils(TestCase):
"""Test Reflection-utils"""
def test_path_to_class(self):
"""Test path_to_class"""
self.assertIsNone(path_to_class(None))
self.assertEqual(path_to_class("datetime.datetime"), datetime)