예제 #1
0
def test_setitem_raise_on_invalid_value(patch_schema):
    patch_schema({'key': {'type': 'integer'}})
    context = Context({})
    with pytest.raises(DataError):
        context['key'] = 'invalid'
    assert 'key' not in context
    assert context.get('key') is None
예제 #2
0
def test_getitem(patch_schema):
    patch_schema({'key': {'type': 'string'}})
    context = Context({'key': 'value'})
    assert context['key'] == 'value'
    assert context.get('key') == 'value'
예제 #3
0
def test_get_should_return_default_if_dataerror(patch_schema):
    patch_schema({'key': {'type': 'integer'}})
    context = Context({'key': 'invalid'})
    assert context.get('key') is None
예제 #4
0
def test_get_should_return_default_if_key_is_missing(patch_schema):
    patch_schema({'key': {'type': 'integer'}})
    context = Context({})
    assert context.get('key') is None