def setUp(self): self.value = { 'currency': 'USD', 'value': 100, } self.field = currency_fields.AmountDictionary( description='An amount', valid_currencies=['JPY', 'USD'], )
def test_operator_less_than_or_equal_to(self): # type: () -> None field = currency_fields.AmountDictionary(lte=100) self.assertEqual(field.errors(self.value), []) field = currency_fields.AmountDictionary(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_operator_greater_than(self): # type: () -> None field = currency_fields.AmountDictionary(gt=99) self.assertEqual(field.errors(self.value), []) field = currency_fields.AmountDictionary(gt=100) 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 > 100', ) self.assertEqual( error.pointer, 'value', )
def test_operator_less_than(self): field = currency_fields.AmountDictionary(lt=101) self.assertEqual(field.errors(self.value), []) field = currency_fields.AmountDictionary(lt=100) 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 < 100', ) self.assertEqual( error.pointer, 'value', )
def test_operator_greater_than_or_equal_to(self): field = currency_fields.AmountDictionary(gte=100) self.assertEqual(field.errors(self.value), []) field = currency_fields.AmountDictionary(gte=101) 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 >= 101', ) self.assertEqual( error.pointer, 'value', )
def test_constructor(self): # type: () -> None with pytest.raises(TypeError): # noinspection PyTypeChecker currency_fields.AmountDictionary( valid_currencies=1234) # type: ignore with pytest.raises(TypeError): # noinspection PyTypeChecker currency_fields.AmountDictionary( valid_currencies=[1, 2, 3, 4]) # type: ignore with pytest.raises(TypeError): # noinspection PyTypeChecker currency_fields.AmountDictionary(gt='not an int') # type: ignore with pytest.raises(TypeError): # noinspection PyTypeChecker currency_fields.AmountDictionary(gte='not an int') # type: ignore with pytest.raises(TypeError): # noinspection PyTypeChecker currency_fields.AmountDictionary(lt='not an int') # type: ignore with pytest.raises(TypeError): # noinspection PyTypeChecker currency_fields.AmountDictionary(lte='not an int') # type: ignore
def test_deprecated_amount_dictionary_constructor_warning(self): with warnings.catch_warnings(record=True) as w: warnings.simplefilter('always', DeprecationWarning) # noinspection PyDeprecation currency_fields.AmountDictionary( description='An amount', valid_currencies=['JPY', 'USD'], ) assert w assert len(w) == 1 assert issubclass(w[-1].category, DeprecationWarning) assert ( 'AmountDictionary is deprecated and will be removed in Conformity 2.0. ' 'Use AmountRequestDictionary, instead.') in str(w[-1].message)