def test_invalid_item(): """ When given an invalid value the ListOrItemField validate method should raise a ValidationError. """ field = ListOrItemField(child=CharField(max_length=5)) with pytest.raises(ValidationError): field.to_internal_value('123456')
def test_validate_required_missing(): """ When given a None value the ListOrItemField validate method should raise a ValidationError. """ field = ListOrItemField(child=DateField(format=ISO_8601)) with pytest.raises(ValidationError): field.to_internal_value(None)
def test_to_internal_value_item(): """ When given a valid item, the ListOrItemField to_internal_value method should utilize the item from-native logic. """ field = ListOrItemField(child=DateField(format=ISO_8601)) data = field.to_internal_value(date.today().isoformat()) assert date.today() == data
def test_to_internal_value_list(): """ When given a valid list, the ListOrItemField to_internal_value method should utilize the list from-native logic. """ field = ListOrItemField(child=DateField(format=ISO_8601)) data = field.to_internal_value([date.today().isoformat()]) assert [date.today()] == data