Exemple #1
0
    def test_define_changes_status(self):
        root_dto = RootDto()

        version1 = Version()
        version1.name = "v1"
        version1.major = 1
        version1 = VersionDto(version1)
        version2 = Version()
        version2.name = "v2"
        version2.major = 2
        version2 = VersionDto(version2)

        category1 = MethodCategory(Category("c1"))
        category2 = TypeCategory(Category("c2"))

        method1 = Method()
        method1.changes_status = {"v1": MultiVersion.Changes.none}
        method2 = Method()
        method2.changes_status = {"v1": MultiVersion.Changes.new}
        method3 = Method()
        method3.changes_status = {"v2": MultiVersion.Changes.new}

        category1.methods = [method1, method2, method3]

        root_dto.versions = [version1, version2]
        root_dto.method_categories = [category1]
        root_dto.type_categories = [category2]

        self.factory.define_changes_status(root_dto)

        self.assertEqual(MultiVersion.Changes.new, method1.changes_status["v1"])
        self.assertEqual(MultiVersion.Changes.deleted, method2.changes_status["v2"])
        self.assertEqual(MultiVersion.Changes.none, method3.changes_status["v1"])
Exemple #2
0
    def test_define_changes_status__updated(self):
        root_dto = RootDto()

        version1 = Version()
        version1.name = "v1"
        version1.major = 1
        version1 = VersionDto(version1)
        version2 = Version()
        version2.name = "v2"
        version2.major = 2
        version2 = VersionDto(version2)

        category1 = MethodCategory(Category("c1"))

        method1 = Method()
        method1.changes_status = {"v1": MultiVersion.Changes.new, "v2": MultiVersion.Changes.updated}

        category1.methods = [method1]

        root_dto.versions = [version1, version2]
        root_dto.method_categories = [category1]

        self.factory.define_changes_status(root_dto)

        self.assertEqual(MultiVersion.Changes.new, method1.changes_status["v1"])
        self.assertEqual(MultiVersion.Changes.updated, method1.changes_status["v2"])
Exemple #3
0
    def test_define_changes_status__updated(self):
        root_dto = RootDto()

        version1 = Version()
        version1.name = "v1"
        version1.major = 1
        version1 = VersionDto(version1)
        version2 = Version()
        version2.name = "v2"
        version2.major = 2
        version2 = VersionDto(version2)

        category1 = MethodCategory(Category("c1"))

        method1 = Method()
        method1.changes_status = {
            "v1": MultiVersion.Changes.new,
            "v2": MultiVersion.Changes.updated
        }

        category1.methods = [method1]

        root_dto.versions = [version1, version2]
        root_dto.method_categories = [category1]

        self.factory.define_changes_status(root_dto)

        self.assertEqual(MultiVersion.Changes.new,
                         method1.changes_status["v1"])
        self.assertEqual(MultiVersion.Changes.updated,
                         method1.changes_status["v2"])
Exemple #4
0
    def test_render__remote(self):
        source = Root()
        config = Config()
        config["output"]["componants"] = "remote"

        template_dir = self.template.env.loader.searchpath[0]
        if os.path.exists(
                os.path.join(template_dir, "resource", "js", "combined.js")):
            shutil.move(
                os.path.join(template_dir, "resource", "js", "combined.js"),
                "/tmp/apidoc_combined.js")

        try:
            self.template.output = os.path.join(self.temp_dir, "foo",
                                                "index.html")
            self.template.render(source, config)

            files = [f for f in os.listdir(os.path.join(self.temp_dir, "foo"))]
            self.assertIn("index.html", files)
            self.assertIn("font", files)
            self.assertIn("css", files)
            self.assertIn("js", files)
            files_js = [
                f for f in os.listdir(os.path.join(self.temp_dir, "foo", "js"))
            ]
            self.assertNotIn("jquery.min.js", files_js)
        finally:
            if os.path.exists("/tmp/apidoc_combined.js"):
                shutil.move(
                    "/tmp/apidoc_combined.js",
                    os.path.join(template_dir, "resource", "js",
                                 "combined.js"))
Exemple #5
0
    def create_from_root(self, root_source):
        """Return a populated Object Root from dictionnary datas
        """

        root_dto = ObjectRoot()

        root_dto.configuration = root_source.configuration
        root_dto.versions = [Version(x) for x in root_source.versions.values()]

        for version in sorted(root_source.versions.values()):
            hydrator = Hydrator(version, root_source.versions, root_source.versions[version.name].types)
            for method in version.methods.values():
                hydrator.hydrate_method(root_dto, root_source, method)
            for type in version.types.values():
                hydrator.hydrate_type(root_dto, root_source, type)

        self.define_changes_status(root_dto)

        return root_dto
Exemple #6
0
    def create_from_root(self, root_source):
        """Return a populated Object Root from dictionnary datas
        """

        root_dto = ObjectRoot()

        root_dto.configuration = root_source.configuration
        root_dto.versions = [Version(x) for x in root_source.versions.values()]

        for version in sorted(root_source.versions.values()):
            hydrator = Hydrator(version, root_source.versions,
                                root_source.versions[version.name].types)
            for method in version.methods.values():
                hydrator.hydrate_method(root_dto, root_source, method)
            for type in version.types.values():
                hydrator.hydrate_type(root_dto, root_source, type)

        self.define_changes_status(root_dto)

        return root_dto
Exemple #7
0
    def test_render__output(self):
        source = Root()
        config = Config()

        self.template.output = "stdout"

        out = StringIO()
        self.template.render(source, config, out=out)
        output = out.getvalue().strip()

        files = [f for f in os.listdir(self.temp_dir)]
        self.assertEqual(0, len(files))
        self.assertNotEqual(0, len(output))
Exemple #8
0
    def test_render__template(self):
        source = Root()
        config = Config()
        config["output"]["template"] = __file__

        self.template.output = os.path.join(self.temp_dir, "index.html")
        self.template.render(source, config)

        files = [f for f in os.listdir(os.path.join(self.temp_dir))]
        self.assertIn("index.html", files)
        self.assertNotIn("font", files)
        self.assertNotIn("css", files)
        self.assertNotIn("js", files)
Exemple #9
0
    def test_define_changes_status(self):
        root_dto = RootDto()

        version1 = Version()
        version1.name = "v1"
        version1.major = 1
        version1 = VersionDto(version1)
        version2 = Version()
        version2.name = "v2"
        version2.major = 2
        version2 = VersionDto(version2)

        category1 = MethodCategory(Category("c1"))
        category2 = TypeCategory(Category("c2"))

        method1 = Method()
        method1.changes_status = {"v1": MultiVersion.Changes.none}
        method2 = Method()
        method2.changes_status = {"v1": MultiVersion.Changes.new}
        method3 = Method()
        method3.changes_status = {"v2": MultiVersion.Changes.new}

        category1.methods = [method1, method2, method3]

        root_dto.versions = [version1, version2]
        root_dto.method_categories = [category1]
        root_dto.type_categories = [category2]

        self.factory.define_changes_status(root_dto)

        self.assertEqual(MultiVersion.Changes.new,
                         method1.changes_status["v1"])
        self.assertEqual(MultiVersion.Changes.deleted,
                         method2.changes_status["v2"])
        self.assertEqual(MultiVersion.Changes.none,
                         method3.changes_status["v1"])
Exemple #10
0
    def test_render__remote(self):
        source = Root()
        config = Config()
        config["output"]["componants"] = "remote"

        self.template.output = os.path.join(self.temp_dir, "foo", "index.html")
        self.template.render(source, config)
        self.template.render(source, config)

        files = [f for f in os.listdir(os.path.join(self.temp_dir, "foo"))]
        self.assertIn("index.html", files)
        self.assertIn("font", files)
        self.assertIn("css", files)
        self.assertIn("js", files)
        files_js = [f for f in os.listdir(os.path.join(self.temp_dir, "foo", "js"))]
        self.assertNotIn("jquery.min.js", files_js)