예제 #1
0
def test_from_json_invalid_syntax_raises_error() -> None:
    # given
    json_string = """{"name": "Liz" "age": 42}"""  # missing comma between fields

    # when - then
    with pytest.raises(DeserializationError):
        _ = from_json("TestDataClass", json_string)
예제 #2
0
def test_from_json_missing_root_raises_error() -> None:
    # given
    json_string = """{"name": "Liz", "age": 42}"""  # data not under "person" root

    # when - then
    with pytest.raises(DeserializationError):
        _ = from_json("TestDataClass", json_string, "person")
예제 #3
0
def test_from_json_valid_document_success() -> None:
    # given
    json_string = """{"name": "Liz", "age": 42}"""

    # when
    dic = from_json("TestDataClass", json_string)

    # then
    assert dic["name"] == "Liz"
    assert dic["age"] == 42
 def from_json(cls, json_string: str):
     dic = from_json(class_name=cls.__name__, json_string=json_string)
     required_fields = ["id", "device_name", "labels"]
     validate_fields(class_name=cls.__name__, required_fields=required_fields, dic=dic)
     labels = [LabelPayload.from_dict(item) for item in dic["labels"]]
     return cls(
         id=dic["id"],
         device_name=dic["device_name"],
         labels=labels,
     )
 def from_json(cls, json_string):
     dic = from_json(class_name=cls.__name__,
                     json_string=json_string,
                     root="site")
     return cls(site=from_dict(data_class=CreateResponse._Site, data=dic))
 def from_json(cls, json_string):
     dic = from_json(class_name=cls.__name__,
                     json_string=json_string,
                     root="sites")
     sites = [GetResponse.from_dict(item) for item in dic]
     return cls(sites=sites)
 def from_json(cls, json_string):
     dic = from_json(class_name=cls.__name__,
                     json_string=json_string,
                     root="site")
     return cls.from_dict(dic=dic)
 def from_json(cls, json_string):
     dic = from_json(class_name=cls.__name__, json_string=json_string)
     return cls(interface=InterfacePayload.from_dict(dic))
 def from_json(cls, json_string):
     dic = from_json(class_name=cls.__name__, json_string=json_string)
     interfaces = [GetResponse.from_dict(item) for item in dic]
     return cls(interfaces=interfaces)
 def from_json(cls, json_string):
     # for GET response the payload json is like: "interface": {...}
     dic = from_json(class_name=cls.__name__, json_string=json_string, root="interface")
     return cls.from_dict(dic)
 def from_json(cls, json_string):
     dic = from_json(cls.__name__, json_string)
     obj = cls()
     for i in dic:
         obj.append(from_dict(data_class=_Alarm, data=i))
     return obj
예제 #12
0
 def from_json(cls, json_string):
     dic = from_json(class_name=cls.__name__, json_string=json_string)
     return from_dict(data_class=cls, data=dic)
예제 #13
0
 def from_json(cls, json_string):
     dic = from_json(class_name=cls.__name__, json_string=json_string)
     return cls(**dic)