diff --git a/passbook/crypto/tests.py b/passbook/crypto/tests.py new file mode 100644 index 000000000..d8b8c6920 --- /dev/null +++ b/passbook/crypto/tests.py @@ -0,0 +1,50 @@ +"""Crypto tests""" +from django.test import TestCase + +from passbook.crypto.api import CertificateKeyPairSerializer +from passbook.crypto.forms import CertificateKeyPairForm +from passbook.crypto.models import CertificateKeyPair + + +class TestCrypto(TestCase): + """Test Crypto validation""" + + def test_form(self): + """Test form validation""" + keypair = CertificateKeyPair.objects.first() + self.assertTrue( + CertificateKeyPairForm( + { + "name": keypair.name, + "certificate_data": keypair.certificate_data, + "key_data": keypair.key_data, + } + ).is_valid() + ) + self.assertFalse( + CertificateKeyPairForm( + {"name": keypair.name, "certificate_data": "test", "key_data": "test"} + ).is_valid() + ) + + def test_serializer(self): + """Test API Validation""" + keypair = CertificateKeyPair.objects.first() + self.assertTrue( + CertificateKeyPairSerializer( + data={ + "name": keypair.name, + "certificate_data": keypair.certificate_data, + "key_data": keypair.key_data, + } + ).is_valid() + ) + self.assertFalse( + CertificateKeyPairSerializer( + data={ + "name": keypair.name, + "certificate_data": "test", + "key_data": "test", + } + ).is_valid() + )