Example #1
0
def test_forward_compat_serdes_new_enum_field():
    _TEST_WHITELIST_MAP = _initial_whitelist_map()

    @_whitelist_for_serdes(whitelist_map=_TEST_WHITELIST_MAP)
    class Corge(Enum):
        FOO = 1
        BAR = 2

    assert "Corge" in _TEST_WHITELIST_MAP["types"]["enum"]

    corge = Corge.FOO

    packed = _pack_value(corge, whitelist_map=_TEST_WHITELIST_MAP)

    # pylint: disable=function-redefined
    @_whitelist_for_serdes(whitelist_map=_TEST_WHITELIST_MAP)
    class Corge(Enum):
        FOO = 1
        BAR = 2
        BAZ = 3

    unpacked = _unpack_value(packed, whitelist_map=_TEST_WHITELIST_MAP)

    assert unpacked != corge
    assert unpacked.name == corge.name
    assert unpacked.value == corge.value
Example #2
0
def test_forward_compat_serdes_new_enum_field():
    _TEST_TUPLE_MAP = {}
    _TEST_ENUM_MAP = {}

    @_whitelist_for_serdes(tuple_map=_TEST_TUPLE_MAP, enum_map=_TEST_ENUM_MAP)
    class Corge(Enum):
        FOO = 1
        BAR = 2

    assert 'Corge' in _TEST_ENUM_MAP

    corge = Corge.FOO

    packed = _pack_value(corge,
                         tuple_map=_TEST_TUPLE_MAP,
                         enum_map=_TEST_ENUM_MAP)

    @_whitelist_for_serdes(tuple_map=_TEST_TUPLE_MAP, enum_map=_TEST_ENUM_MAP)  # pylint: disable=function-redefined
    class Corge(Enum):
        FOO = 1
        BAR = 2
        BAZ = 3

    unpacked = _unpack_value(packed,
                             tuple_map=_TEST_TUPLE_MAP,
                             enum_map=_TEST_ENUM_MAP)

    assert unpacked != corge
    assert unpacked.name == corge.name
    assert unpacked.value == corge.value