Exemplo n.º 1
0
def test_should_apply_no_camel_case_to_all(defaults):
    class Foo:
        def __init__(self, some_thing: str):
            self.some_thing = some_thing

    set_defaults(no_camel_case)

    assert serialize(Foo('bar')) == {'some_thing': 'bar'}
Exemplo n.º 2
0
def test_annotation_should_override_defaults(defaults):
    @use_camel_case
    class Foo:
        def __init__(self, some_thing: str):
            self.some_thing = some_thing

    set_defaults(no_camel_case)

    assert serialize(Foo('bar')) == {'someThing': 'bar'}
Exemplo n.º 3
0
def test_date_default(defaults):
    class Foo:
        def __init__(self, day: datetime):
            self.day = day

    set_defaults(date_formatter(ArrowStringFormatter()))

    assert serialize(Foo(datetime(2013, 5, 5, 12, 30, 45))) == {
        'day': '2013-05-05T12:30:45+00:00'
    }
Exemplo n.º 4
0
def test_should_apply_multiple_defaults(defaults):
    class Foo:
        def __init__(self, some_thing: str, other_thing: Optional[str]):
            self.some_thing = some_thing
            self.other_thing = other_thing

    set_defaults(no_camel_case, explicit_nulls)

    assert serialize(Foo('bar', None)) == {
        'some_thing': 'bar',
        'other_thing': None
    }
Exemplo n.º 5
0
def test_cannot_use_averything_at_a_default():
    with pytest.raises(ValueError):
        set_defaults(test_annotation_should_override_defaults)