def test_with_multi_join_serialize(): s1 = Simple(value="12") s2 = Simple(value="22") wmj = WithMultiJoin(value="13", join=[s1, s2]) wmj_ser = wmj.serialize() assert wmj_ser["id"] is None assert wmj_ser["value"] == "13" assert len(wmj_ser["join"]) == 2 assert isinstance(wmj_ser["join"][0], Simple) assert isinstance(wmj_ser["join"][1], Simple)
def test_with_join_id_simple_id_repr(): s = Simple(id="2", value="12") wj = WithJoin(id="1", value="13", join=s) assert re.search( r"<conftest\.WithJoin object at 0x.*>{'id': '1', 'value': '13', 'join': '2'", repr(wj))
def test_with_join_id_str(): s = Simple(value="12") wj = WithJoin(id="1", value="13", join=s) assert re.search( r"{'id': '1', 'value': '13', 'join': '<conftest\.Simple object at 0x.*>'}", str(wj))
def test_with_multi_join_id_serialize_simple_id(): s1 = Simple(id="2", value="12") s2 = Simple(id="3", value="22") wmj = WithMultiJoin(id="1", value="13", join=[s1, s2]) assert wmj.serialize() == {"id": "1", "join": ['2', '3'], "value": "13"} assert wmj.serialize(depth=1) == { "id": "1", "join": [{ 'id': '2', 'value': '12' }, { 'id': '3', 'value': '22' }], "value": "13" }
def test_with_join_serialize(): s = Simple(value="12") wj = WithJoin(value="13", join=s) wj_ser = wj.serialize() assert wj_ser["id"] is None assert wj_ser["value"] == "13" assert isinstance(wj_ser["join"], Simple)
def test_with_join_serialize_id_simple_id(): s = Simple(id="2", value="12") wj = WithJoin(id="1", value="13", join=s) assert wj.serialize() == {"id": "1", "join": "2", "value": "13"} assert wj.serialize(depth=1) == { "id": "1", "join": { "id": "2", "value": "12" }, "value": "13" }
def test_simple_repr(): s = Simple(value="12") assert repr(s).startswith('<conftest.Simple') assert repr(s).endswith('>')
def test_simple_id_repr(): s = Simple(id="1", value="12") assert repr(s).startswith('<conftest.Simple') assert repr(s).endswith(">{'id': '1', 'value': '12'}")
def test_with_join_repr(): s = Simple(value="12") wj = WithJoin(value="13", join=s) assert repr(wj).startswith('<conftest.WithJoin') assert repr(wj).endswith('>')
def test_with_join_id_simple_id_str(): s = Simple(id="2", value="12") wj = WithJoin(id="1", value="13", join=s) assert str(wj) == "{'id': '1', 'value': '13', 'join': '2'}"
def test_simple_str(): s = Simple(value="12") assert str(s) == "{'id': None, 'value': '12'}"
def test_simple_id_str(): s = Simple(id="1", value="12") assert str(s) == "{'id': '1', 'value': '12'}"
def test_simple_id_serialize(): s = Simple(id="1", value="12") assert s.serialize() == {'id': "1", 'value': '12'}
def test_simple_serialize(): s = Simple(value="12") assert s.serialize() == {"id": None, "value": "12"}