63 lines
1.3 KiB
Python
63 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
# type: ignore
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from pytest_mock import MockerFixture
|
|
|
|
from keep_it_secret import fields
|
|
from keep_it_secret.secrets import Secrets
|
|
|
|
|
|
def test_init():
|
|
# When
|
|
_ = fields.AbstractField()
|
|
|
|
# Then
|
|
assert True # Nothing to test here ;)
|
|
|
|
|
|
def test_init_with_field_options():
|
|
# When
|
|
result = fields.AbstractField(
|
|
as_type=int, required=False, description='spameggs',
|
|
)
|
|
|
|
# Then
|
|
assert result.as_type == int
|
|
assert result.required is False
|
|
assert result.description == 'spameggs'
|
|
|
|
|
|
def test_new(mocker: MockerFixture):
|
|
# Given
|
|
mock_init = mocker.patch.object(
|
|
fields.AbstractField, '__init__', return_value=None,
|
|
)
|
|
|
|
# When
|
|
_ = fields.AbstractField.new(
|
|
as_type=int,
|
|
required=False,
|
|
description='spameggs',
|
|
)
|
|
|
|
# Then
|
|
mock_init.assert_called_once_with(
|
|
as_type=int,
|
|
required=False,
|
|
description='spameggs',
|
|
)
|
|
|
|
|
|
def test_get_value(testing_secrets: Secrets):
|
|
# Given
|
|
field = fields.AbstractField()
|
|
|
|
with pytest.raises(NotImplementedError) as exception_info:
|
|
# When
|
|
_ = field.get_value(testing_secrets)
|
|
|
|
# Then
|
|
assert field.name in exception_info.value.args[0]
|