def setUp(self): self.value = { 'currency': 'USD', 'value': 100, } self.field = currency_fields.AmountRequestDictionary( description='An amount', valid_currencies=['JPY', 'USD'], )
def test_operator_less_than_or_equal_to(self): # type: () -> None field = currency_fields.AmountRequestDictionary(lte=100) self.assertEqual(field.errors(self.value), []) field = currency_fields.AmountRequestDictionary(lte=99) errors = field.errors(self.value) self.assertEqual(len(errors), 1) error = errors[0] self.assertEqual( error.code, ERROR_CODE_INVALID, ) self.assertEqual( error.message, 'Value not <= 99', ) self.assertEqual( error.pointer, 'value', )
def test_constructor(self): # type: () -> None with pytest.raises(TypeError): # noinspection PyTypeChecker currency_fields.AmountRequestDictionary( valid_currencies=1234) # type: ignore with pytest.raises(TypeError): # noinspection PyTypeChecker currency_fields.AmountRequestDictionary( valid_currencies=[1, 2, 3, 4]) # type: ignore with pytest.raises(TypeError): # noinspection PyTypeChecker currency_fields.AmountRequestDictionary( gt='not an int') # type: ignore with pytest.raises(TypeError): # noinspection PyTypeChecker currency_fields.AmountRequestDictionary( gte='not an int') # type: ignore with pytest.raises(TypeError): # noinspection PyTypeChecker currency_fields.AmountRequestDictionary( lt='not an int') # type: ignore with pytest.raises(TypeError): # noinspection PyTypeChecker currency_fields.AmountRequestDictionary( lte='not an int') # type: ignore with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always', DeprecationWarning) currency_fields.AmountRequestDictionary( description='An amount', valid_currencies=['JPY', 'USD'], allow_extra_keys=True, ) assert w assert len(w) == 1 assert issubclass(w[-1].category, DeprecationWarning) assert ( '*args and **kwargs are deprecated in AmountRequestDictionary and will be removed in Conformity 2.0.' ) in str(w[-1].message)