Beispiel #1
0
    def test_sub_schemas(self):
        imports = [
            Import(schema_location="../foo.xsd"),
            Import(schema_location="../bar.xsd"),
        ]
        includes = [
            Include(schema_location="common.xsd"),
            Include(schema_location="uncommon.xsd"),
        ]
        redefines = [
            Redefine(schema_location="a.xsd"),
            Redefine(schema_location="b.xsd"),
        ]
        overrides = [
            Override(schema_location="a.xsd"),
            Override(schema_location="b.xsd"),
        ]
        schema = Schema(imports=imports,
                        includes=includes,
                        redefines=redefines,
                        overrides=overrides)

        actual = schema.included()
        expected = imports + includes + redefines + overrides
        self.assertIsInstance(actual, Iterator)
        self.assertEqual(expected, list(actual))

        schema = Schema()
        self.assertEqual([], list(schema.included()))
Beispiel #2
0
    def test_add_default_imports(self):
        schema = Schema()
        schema.imports.append(Import(namespace="foo"))

        self.parser.add_default_imports(schema)
        self.assertEqual(1, len(schema.imports))

        xsi = Namespace.XSI.uri
        schema.ns_map["foo"] = xsi
        self.parser.add_default_imports(schema)
        self.assertEqual(2, len(schema.imports))
        self.assertEqual(Import(namespace=xsi), schema.imports[0])
Beispiel #3
0
    def test_wget_included(self, mock_wget):
        schema = Schema(
            imports=[
                Import(location="foo.xsd"),
                Import(),
                Import(location="foo.xsd", schema_location="../foo.xsd"),
            ]
        )

        self.downloader.wget_included(schema)
        mock_wget.assert_has_calls(
            [
                mock.call(schema.imports[0].location, None),
                mock.call(
                    schema.imports[2].location, schema.imports[2].schema_location
                ),
            ]
        )
Beispiel #4
0
    def test_convert_schema(self, mock_process_schema, mock_generate_classes):
        schema = Schema(target_namespace="thug", location="main")
        schema.includes.append(Include(location="foo"))
        schema.overrides.append(Override())
        schema.imports.append(Import(location="bar"))
        schema.imports.append(Import(location="fails"))

        mock_generate_classes.return_value = ClassFactory.list(2)

        self.transformer.convert_schema(schema)

        self.assertEqual(1, len(self.transformer.class_map))
        self.assertEqual(2, len(self.transformer.class_map["main"]))
        mock_process_schema.assert_has_calls([
            mock.call("bar", "thug"),
            mock.call("fails", "thug"),
            mock.call("foo", "thug"),
        ])
Beispiel #5
0
    def test_resolve_schemas_locations(
        self, mock_resolve_path, mock_resolve_local_path
    ):
        schema = Schema()
        self.parser.resolve_schemas_locations(schema)

        self.parser.location = Path.cwd()

        mock_resolve_path.side_effect = lambda x: Path.cwd().joinpath(x)
        mock_resolve_local_path.side_effect = lambda x, y: Path.cwd().joinpath(x)

        schema.overrides.append(Override(schema_location="o1"))
        schema.overrides.append(Override(schema_location="o2"))
        schema.redefines.append(Redefine(schema_location="r1"))
        schema.redefines.append(Redefine(schema_location="r2"))
        schema.includes.append(Include(schema_location="i1"))
        schema.includes.append(Include(schema_location="i2"))
        schema.imports.append(Import(schema_location="i3", namespace="ns_i3"))
        schema.imports.append(Import(schema_location="i4", namespace="ns_i4"))

        self.parser.resolve_schemas_locations(schema)

        mock_resolve_path.assert_has_calls(
            [
                mock.call("o1"),
                mock.call("o2"),
                mock.call("r1"),
                mock.call("r2"),
                mock.call("i1"),
                mock.call("i2"),
            ]
        )

        mock_resolve_local_path.assert_has_calls(
            [mock.call("i3", "ns_i3"), mock.call("i4", "ns_i4")]
        )

        for sub in schema.included():
            self.assertEqual(Path.cwd().joinpath(sub.location), sub.location)
Beispiel #6
0
    def test_parse_definitions(
        self,
        mock_load_resource,
        mock_definitions_parser,
        mock_definitions_merge,
        mock_process_schema,
    ):
        def_one = Definitions(imports=[
            Import(),
            Import(location="file://sub.wsdl"),
            Import(location="file://sub.wsdl"),
            Import(location="file://types.xsd"),
        ])
        def_two = Definitions()

        mock_load_resource.side_effect = ["a", "b", None]
        mock_definitions_parser.side_effect = [def_one, def_two]
        actual = self.transformer.parse_definitions("main.wsdl", "fooNS")

        self.assertEqual(def_one, actual)
        mock_definitions_merge.assert_called_once_with(def_two)
        mock_process_schema.assert_called_once_with("file://types.xsd")
Beispiel #7
0
    def test_process_schema(
        self,
        mock_parse_schema,
        mock_generate_classes,
        mock_logger_info,
    ):
        schema = Schema(target_namespace="thug")
        schema.includes.append(Include(location="foo"))
        schema.overrides.append(Override())
        schema.imports.append(Import(location="bar"))
        schema.imports.append(Import(location="fails"))
        schema_foo = Schema()
        schema_bar = Schema()

        mock_generate_classes.side_effect = [
            ClassFactory.list(1),
            ClassFactory.list(2),
            ClassFactory.list(3),
        ]

        mock_parse_schema.side_effect = [schema, schema_bar, None, schema_foo]

        self.transformer.process_schema("main", "foo-bar")

        self.assertEqual(["main", "bar", "fails", "foo"],
                         self.transformer.processed)

        self.assertEqual(3, len(self.transformer.class_map))
        self.assertEqual(3, len(self.transformer.class_map["main"]))
        self.assertEqual(2, len(self.transformer.class_map["foo"]))
        self.assertEqual(1, len(self.transformer.class_map["bar"]))

        mock_logger_info.assert_has_calls([
            mock.call("Parsing schema %s", "main"),
            mock.call("Parsing schema %s", "bar"),
            mock.call("Parsing schema %s", "fails"),
            mock.call("Parsing schema %s", "foo"),
        ])