def test_to_internal_value_invalid_choices(self): """Test that choices still matter, and you can't a) send the internal value or b) send an invalid value.""" field = ReverseChoiceField(choices=(('internal', 'human'),)) with self.assertRaises(serializers.ValidationError): field.to_internal_value('internal')
def test_to_internal_value(self): """Test that when a client sends data in human-readable format (e.g. a string constant), we convert it to the internal format when converting data to internal value.""" field = ReverseChoiceField(choices=(('internal', 'human'),)) assert field.to_internal_value('human') == 'internal'