Ejemplo n.º 1
0
    def test_value_not_a_string(self):
        input_str = '{"FieldName": [1, 2, 3]}'
        field = ResourceLinkField("FieldName", TestResourceSpec)

        input_data = json.loads(input_str)
        with self.assertRaises(ResourceLinkFieldValueNotAStringException):
            field.parse(data=input_data, context={})
Ejemplo n.º 2
0
    def test_key_absent_without_optional(self):
        input_str = "{}"
        field = ResourceLinkField("FieldName", TestResourceSpec)

        input_data = json.loads(input_str)
        with self.assertRaises(ResourceLinkFieldSourceKeyNotFoundException):
            field.parse(data=input_data, context={})
Ejemplo n.º 3
0
    def test_key_absent_with_optional(self):
        input_str = "{}"
        field = ResourceLinkField("FieldName", TestResourceSpec, optional=True)
        expected_output_data = []

        input_data = json.loads(input_str)
        links = field.parse(data=input_data, context={})
        output_data = [link.to_dict() for link in links]
        self.assertCountEqual(output_data, expected_output_data)
Ejemplo n.º 4
0
    def test_key_present_with_optional(self):
        input_str = '{"FieldName": "Value"}'
        field = ResourceLinkField("FieldName", TestResourceSpec, optional=True)
        expected_output_data = [{
            "pred": "test_type_name",
            "obj": "test_type_name:Value",
            "type": "resource_link"
        }]

        input_data = json.loads(input_str)
        links = field.parse(data=input_data, context={})
        output_data = [link.to_dict() for link in links]
        self.assertCountEqual(output_data, expected_output_data)
Ejemplo n.º 5
0
    def test_valid_input_str_classname(self):
        input_str = '{"FieldName": "Value"}'
        field = ResourceLinkField("FieldName", "TestResourceSpec")
        expected_output_data = [{
            "pred": "test_type_name",
            "obj": "test_type_name:Value",
            "type": "resource_link"
        }]

        input_data = json.loads(input_str)
        links = field.parse(data=input_data, context={})
        output_data = [link.to_dict() for link in links]
        self.assertCountEqual(output_data, expected_output_data)