def test_can_convert_to_json_dict():
    state = FeatureFlagsState(True)
    flag1 = { 'key': 'key1', 'version': 100, 'offVariation': 0, 'variations': [ 'value1' ], 'trackEvents': False }
    flag2 = { 'key': 'key2', 'version': 200, 'offVariation': 1, 'variations': [ 'x', 'value2' ], 'trackEvents': True, 'debugEventsUntilDate': 1000 }
    state.add_flag(flag1, 'value1', 0, None, False)
    state.add_flag(flag2, 'value2', 1, None, False)

    result = state.to_json_dict()
    assert result == {
        'key1': 'value1',
        'key2': 'value2',
        '$flagsState': {
            'key1': {
                'variation': 0,
                'version': 100
            },
            'key2': {
                'variation': 1,
                'version': 200,
                'trackEvents': True,
                'debugEventsUntilDate': 1000
            }
        },
        '$valid': True
    }
def test_can_serialize_with_jsonpickle():
    state = FeatureFlagsState(True)
    flag1 = { 'key': 'key1', 'version': 100, 'offVariation': 0, 'variations': [ 'value1' ], 'trackEvents': False }
    flag2 = { 'key': 'key2', 'version': 200, 'offVariation': 1, 'variations': [ 'x', 'value2' ], 'trackEvents': True, 'debugEventsUntilDate': 1000 }
    state.add_flag(flag1, 'value1', 0, None, False)
    state.add_flag(flag2, 'value2', 1, None, False)

    obj = state.to_json_dict()
    str = jsonpickle.encode(state, unpicklable=False)
    assert json.loads(str) == obj
def test_can_convert_to_json_string():
    state = FeatureFlagsState(True)
    flag1 = { 'key': 'key1', 'version': 100, 'offVariation': 0, 'variations': [ 'value1' ], 'trackEvents': False }
    flag2 = { 'key': 'key2', 'version': 200, 'offVariation': 1, 'variations': [ 'x', 'value2' ], 'trackEvents': True, 'debugEventsUntilDate': 1000 }
    state.add_flag(flag1, 'value1', 0, None, False)
    state.add_flag(flag2, 'value2', 1, None, False)

    obj = state.to_json_dict()
    str = state.to_json_string()
    assert json.loads(str) == obj
示例#4
0
def test_can_convert_to_json_dict():
    state = FeatureFlagsState(True)
    flag1 = {
        'key': 'key1',
        'version': 100,
        'offVariation': 0,
        'variations': ['value1'],
        'trackEvents': False
    }
    flag2 = {
        'key': 'key2',
        'version': 200,
        'offVariation': 1,
        'variations': ['x', 'value2'],
        'trackEvents': True,
        'debugEventsUntilDate': 1000
    }
    state.add_flag(flag1, 'value1', 0, None)
    state.add_flag(flag2, 'value2', 1, None)

    result = state.to_json_dict()
    assert result == {
        'key1': 'value1',
        'key2': 'value2',
        '$flagsState': {
            'key1': {
                'variation': 0,
                'version': 100,
                'trackEvents': False
            },
            'key2': {
                'variation': 1,
                'version': 200,
                'trackEvents': True,
                'debugEventsUntilDate': 1000
            }
        },
        '$valid': True
    }
示例#5
0
def test_can_serialize_with_jsonpickle():
    state = FeatureFlagsState(True)
    flag1 = {
        'key': 'key1',
        'version': 100,
        'offVariation': 0,
        'variations': ['value1'],
        'trackEvents': False
    }
    flag2 = {
        'key': 'key2',
        'version': 200,
        'offVariation': 1,
        'variations': ['x', 'value2'],
        'trackEvents': True,
        'debugEventsUntilDate': 1000
    }
    state.add_flag(flag1, 'value1', 0, None, False)
    state.add_flag(flag2, 'value2', 1, None, False)

    obj = state.to_json_dict()
    str = jsonpickle.encode(state, unpicklable=False)
    assert json.loads(str) == obj
示例#6
0
def test_can_convert_to_json_string():
    state = FeatureFlagsState(True)
    flag1 = {
        'key': 'key1',
        'version': 100,
        'offVariation': 0,
        'variations': ['value1'],
        'trackEvents': False
    }
    flag2 = {
        'key': 'key2',
        'version': 200,
        'offVariation': 1,
        'variations': ['x', 'value2'],
        'trackEvents': True,
        'debugEventsUntilDate': 1000
    }
    state.add_flag(flag1, 'value1', 0, None, False)
    state.add_flag(flag2, 'value2', 1, None, False)

    obj = state.to_json_dict()
    str = state.to_json_string()
    assert json.loads(str) == obj