def test_from_db_value_none(): """Tests whether the :see:from_db_value function correctly handles None values.""" localized_value = LocalizedField().from_db_value(None) for lang_code, _ in settings.LANGUAGES: assert localized_value.get(lang_code) is None
def test_to_python(): """Tests whether the :see:to_python function produces the expected :see:LocalizedValue.""" input_data = get_init_values() localized_value = LocalizedField().to_python(input_data) for language, value in input_data.items(): assert localized_value.get(language) == value
def test_to_python_non_dict(): """Tests whether the :see:to_python function produces the expected :see:LocalizedValue when it is passed a non-dictionary value.""" localized_value = LocalizedField().to_python(list()) assert localized_value for lang_code, _ in settings.LANGUAGES: assert localized_value.get(lang_code) is None
def test_to_python_str(): """Tests whether the :see:to_python function produces the expected :see:LocalizedValue when it is passed serialized string value.""" serialized_str = json.dumps(get_init_values()) localized_value = LocalizedField().to_python(serialized_str) assert isinstance(localized_value, LocalizedValue) for language, value in get_init_values().items(): assert localized_value.get(language) == value assert getattr(localized_value, language) == value
def test_get_prep_value(): """"Tests whether the :see:get_prep_value function produces the expected dictionary.""" input_data = get_init_values() localized_value = LocalizedValue(input_data) output_data = LocalizedField().get_prep_value(localized_value) for language, value in input_data.items(): assert language in output_data assert output_data.get(language) == value
def test_to_python_non_json(): """Tests whether the :see:to_python function properly handles a string that is not JSON.""" localized_value = LocalizedField().to_python('my value') assert localized_value.get() == 'my value'