示例#1
0
文件: fields.py 项目: oioudina/zing
def to_python(value):
    """Reconstruct a multistring from the database string representation."""
    if not value:
        return multistring("", encoding="UTF-8")
    elif isinstance(value, multistring):
        return value
    elif isinstance(value, str):
        return parse_multistring(value)
    elif isinstance(value, dict):
        return multistring([val for __, val in sorted(value.items())],
                           encoding="UTF-8")
    else:
        return multistring(value, encoding="UTF-8")
示例#2
0
def to_python(value):
    """Reconstruct a multistring from the database string representation."""
    if not value:
        return multistring("", encoding="UTF-8")
    elif isinstance(value, multistring):
        return value
    elif isinstance(value, basestring):
        return parse_multistring(value)
    elif isinstance(value, dict):
        return multistring([val for __, val in sorted(value.items())],
                           encoding="UTF-8")
    else:
        return multistring(value, encoding="UTF-8")
示例#3
0
def test_parse_multistring(db_string, expected_ms, is_plural):
    parsed_ms = parse_multistring(db_string)
    assert parsed_ms == expected_ms
    assert parsed_ms.plural == is_plural
示例#4
0
def test_parse_multistring_invalid(invalid_value):
    """Tests parsing doesn't support non-string values"""
    with pytest.raises(ValueError):
        parse_multistring(invalid_value)
示例#5
0
def test_parse_multistring(db_string, expected_ms, is_plural):
    parsed_ms = parse_multistring(db_string)
    assert parsed_ms == expected_ms
    assert parsed_ms.plural == is_plural
示例#6
0
def test_parse_multistring_invalid(invalid_value):
    """Tests parsing doesn't support non-string values"""
    with pytest.raises(ValueError):
        parse_multistring(invalid_value)