83 lines
2.5 KiB
Python
83 lines
2.5 KiB
Python
|
# -*- coding: utf-8 -*-
|
||
|
# type: ignore
|
||
|
from __future__ import annotations
|
||
|
|
||
|
import types
|
||
|
|
||
|
from keep_it_secret import secrets
|
||
|
from keep_it_secret.fields import EnvField, LiteralField
|
||
|
|
||
|
|
||
|
class TestingSecrets(secrets.Secrets):
|
||
|
spam: str = LiteralField.new('spam')
|
||
|
|
||
|
something = False
|
||
|
|
||
|
def do_something(self):
|
||
|
return True
|
||
|
|
||
|
|
||
|
class SubclassSecrets(TestingSecrets):
|
||
|
spam: str = EnvField.new('KEEP_IT_SECRET_TESTS_SPAM')
|
||
|
eggs: str = LiteralField.new('eggs')
|
||
|
|
||
|
|
||
|
def test_generic_attribute_initialization():
|
||
|
# Then
|
||
|
assert TestingSecrets.__class__ is secrets.SecretsBase
|
||
|
assert isinstance(TestingSecrets.__init__, types.FunctionType)
|
||
|
|
||
|
|
||
|
def test_secrets_dunder_attribute_initialization():
|
||
|
# Then
|
||
|
assert hasattr(TestingSecrets, '__secrets_fields__')
|
||
|
|
||
|
assert 'spam' in TestingSecrets.__secrets_fields__
|
||
|
assert isinstance(TestingSecrets.__secrets_fields__['spam'], LiteralField) is True
|
||
|
assert TestingSecrets.__secrets_fields__['spam'].name == 'TestingSecrets.spam'
|
||
|
|
||
|
|
||
|
def test_secret_properties_initialization():
|
||
|
# Then
|
||
|
assert hasattr(TestingSecrets, 'spam')
|
||
|
assert isinstance(TestingSecrets.spam, property)
|
||
|
|
||
|
|
||
|
def test_subclass_attribute_initialization():
|
||
|
# Then
|
||
|
assert hasattr(TestingSecrets, 'something')
|
||
|
assert TestingSecrets.something is False
|
||
|
|
||
|
assert hasattr(TestingSecrets, 'do_something')
|
||
|
assert isinstance(TestingSecrets.do_something, types.FunctionType)
|
||
|
|
||
|
|
||
|
def test_inheritance():
|
||
|
# Then
|
||
|
assert isinstance(SubclassSecrets.__secrets_fields__['spam'], EnvField) is True
|
||
|
assert isinstance(SubclassSecrets.__secrets_fields__['eggs'], LiteralField) is True
|
||
|
|
||
|
assert hasattr(SubclassSecrets, 'do_something')
|
||
|
assert isinstance(SubclassSecrets.do_something, types.FunctionType)
|
||
|
|
||
|
|
||
|
def test_multiple_inheritance():
|
||
|
# Given
|
||
|
class TestingMixin:
|
||
|
def do_something_else(self):
|
||
|
return False
|
||
|
|
||
|
class SubclassWithMixin(TestingMixin, SubclassSecrets):
|
||
|
spameggs = LiteralField.new('spameggs')
|
||
|
|
||
|
# Then
|
||
|
assert isinstance(SubclassWithMixin.__secrets_fields__['spam'], EnvField) is True
|
||
|
assert isinstance(SubclassWithMixin.__secrets_fields__['eggs'], LiteralField) is True
|
||
|
assert isinstance(SubclassWithMixin.__secrets_fields__['spameggs'], LiteralField) is True
|
||
|
|
||
|
assert hasattr(SubclassWithMixin, 'do_something')
|
||
|
assert isinstance(SubclassWithMixin.do_something, types.FunctionType)
|
||
|
|
||
|
assert hasattr(SubclassWithMixin, 'do_something_else')
|
||
|
assert isinstance(SubclassWithMixin.do_something_else, types.FunctionType)
|