コード例 #1
0
    def test_value_not_scalar(self):
        input_str = "[1, 2, 3]"
        parent_alti_key = "parent_alti_key"
        field = EmbeddedScalarField()

        input_data = json.loads(input_str)
        with self.assertRaises(ScalarFieldValueNotAScalarException):
            field.parse(data=input_data,
                        context={"parent_alti_key": parent_alti_key})
コード例 #2
0
    def test_valid_input(self):
        input_data = "foo"
        parent_alti_key = "parent_alti_key"
        field = EmbeddedScalarField()

        link_collection = field.parse(
            data=input_data, context={"parent_alti_key": parent_alti_key})

        expected_link_collection = LinkCollection(simple_links=(SimpleLink(
            pred="parent_alti_key", obj="foo"), ), )
        self.assertEqual(link_collection, expected_link_collection)
コード例 #3
0
    def test_valid_input(self):
        input_data = "foo"
        parent_alti_key = "parent_alti_key"
        field = EmbeddedScalarField()
        expected_output_data = [{
            "pred": "parent_alti_key",
            "obj": "foo",
            "type": "simple"
        }]

        links = field.parse(data=input_data,
                            context={"parent_alti_key": parent_alti_key})
        output_data = [link.to_dict() for link in links]
        self.assertCountEqual(output_data, expected_output_data)
コード例 #4
0
    def test_missing_parent_alti_key_value(self):
        input_data = "foo"
        field = EmbeddedScalarField()

        with self.assertRaises(ParentKeyMissingException):
            field.parse(data=input_data, context={"parent_alti_key": None})