Beispiel #1
0
    def test_hydrate_type__with_known_category(self):

        root = Root()
        version = Version()
        version.name = "v"
        type = Type()
        type.category = "c"
        type.item = ObjectString()

        root.versions = {"v": version}
        version.types = {"m": type}
        version.types = {"m": type}

        category = Category("c")
        category.description = "d"

        root.categories = {"c": category}

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])

        hydrator.hydrate_type(root_dto, root, type)

        self.assertEqual("d", root_dto.type_categories[0].description)
Beispiel #2
0
    def test_remove_hidden_elements(self):
        root = Root()
        version1 = Version()
        version2 = Version()
        category1 = Category("c1")
        category2 = Category("c2")
        method1 = Method()
        method2 = Method()

        root.versions = {"v1": version1, "v2": version2}
        root.categories = {"c1": category1, "c2": category2}

        version1.methods = {"m1": method1, "m2": method2}
        version2.methods = {"m1": method1, "m2": method2}

        method1.category = "c1"
        method2.category = "c2"

        version1.display = False
        category2.display = False

        self.source.remove_hidden_elements(root)

        self.assertEqual(1, len(root.versions))
        self.assertEqual(version2, root.versions["v2"])
        self.assertEqual(1, len(root.versions["v2"].methods))
        self.assertEqual(method1, root.versions["v2"].methods["m1"])
Beispiel #3
0
    def create_from_dictionary(self, datas):
        """Return a populated Object Root from dictionnary datas
        """
        root = ObjectRoot()

        if "configuration" in datas and datas["configuration"] is not None:
            root.configuration = self.configuration_factory.create_from_dictionary(
                datas["configuration"])

        if "categories" in datas and datas["categories"] is not None:
            root.categories = self.category_factory.create_dictionary_of_element_from_dictionary(
                "categories", datas)

        root.versions = self.version_factory.create_dictionary_of_element_from_dictionary(
            "versions", datas)

        for version in root.versions.values():
            version.full_uri = "%s%s" % (root.configuration.uri
                                         or "", version.uri or "")
            for method in version.methods.values():
                method.absolute_uri = "%s%s" % (version.uri or "", method.uri
                                                or "")
                method.full_uri = "%s%s" % (version.full_uri or "", method.uri
                                            or "")

        return root
Beispiel #4
0
    def test_hydrate_type__with_known_category(self):

        root = Root()
        version = Version()
        version.name = "v"
        type = Type()
        type.category = "c"
        type.item = ObjectString()

        root.versions = {"v": version}
        version.types = {"m": type}
        version.types = {"m": type}

        category = Category("c")
        category.description = "d"

        root.categories = {"c": category}

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])

        hydrator.hydrate_type(root_dto, root, type)

        self.assertEqual("d", root_dto.type_categories[0].description)
Beispiel #5
0
    def test_hide_filtered_elements__category_exclude(self):
        root = Root()

        category1 = Category("c1")
        category2 = Category("c2")
        category3 = Category("c3")

        root.categories = {"c1": category1, "c2": category2, "c3": category3}

        config = ConfigObject()
        config["filter"]["categories"]["excludes"] = ["c1", "c3"]
        self.source.hide_filtered_elements(root, config["filter"])

        self.assertFalse(category1.display)
        self.assertTrue(category2.display)
        self.assertFalse(category3.display)
Beispiel #6
0
    def test_add_missing_categories(self):
        root = Root()
        version1 = Version()
        category1 = Category("c1")
        method1 = Method()
        method2 = Method()

        root.versions = {"v1": version1}
        root.categories = {"c1": category1}

        version1.methods = {"m1": method1, "m2": method2}

        method1.category = "c1"
        method2.category = "c2"

        self.source.add_missing_categories(root)

        self.assertEqual(2, len(root.categories))
        self.assertIsInstance(root.categories["c2"], Category)
Beispiel #7
0
    def test_hide_filtered_elements__category_include(self):
        root = Root()

        category1 = Category("c")
        category2 = Category("c")
        category3 = Category("c")
        category1.name = "v1"
        category2.name = "v2"
        category3.name = "v3"

        root.categories = {"s1": category1, "s2": category2, "s3": category3}

        config = ConfigObject()
        config["filter"]["categories"]["includes"] = ["v1", "v3"]
        self.source.hide_filtered_elements(root, config["filter"])

        self.assertTrue(category1.display)
        self.assertFalse(category2.display)
        self.assertTrue(category3.display)
Beispiel #8
0
    def create_from_dictionary(self, datas):
        """Return a populated Object Root from dictionnary datas
        """
        root = ObjectRoot()

        if "configuration" in datas and datas["configuration"] is not None:
            root.configuration = self.configuration_factory.create_from_dictionary(datas["configuration"])

        if "categories" in datas and datas["categories"] is not None:
            root.categories = self.category_factory.create_dictionary_of_element_from_dictionary("categories", datas)

        root.versions = self.version_factory.create_dictionary_of_element_from_dictionary("versions", datas)

        for version in root.versions.values():
            version.full_uri = "%s%s" % (root.configuration.uri or "", version.uri or "")
            for method in version.methods.values():
                method.absolute_uri = "%s%s" % (version.uri or "", method.uri or "")
                method.full_uri = "%s%s" % (version.full_uri or "", method.uri or "")

        return root
Beispiel #9
0
    def test_hydrate_method__with_known_category(self):

        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "c"

        root.versions = {"v": version}
        version.methods = {"m": method}
        version.types = {"m": type}

        category = Category("c")
        category.description = "d"

        root.categories = {"c": category}

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])

        hydrator.hydrate_method(root_dto, root, method)

        self.assertEqual("d", root_dto.method_categories[0].description)
Beispiel #10
0
    def test_hydrate_method__with_known_category(self):

        root = Root()
        version = Version()
        version.name = "v"
        method = Method()
        method.category = "c"

        root.versions = {"v": version}
        version.methods = {"m": method}
        version.types = {"m": type}

        category = Category("c")
        category.description = "d"

        root.categories = {"c": category}

        root_dto = RootDto()

        hydrator = Hydrator(version, {"v": version}, [])

        hydrator.hydrate_method(root_dto, root, method)

        self.assertEqual("d", root_dto.method_categories[0].description)