Пример #1
0
    def test_update_context_case5_re_none(self):
        conn_id = "conn_id"
        conn_name = "conn_name"
        comp_id = "comp_id"

        ids = process.gen_ids(create_event(conn_id, conn_name, comp_id))
        event = create_event(conn_id, conn_name, comp_id)

        expected_conn = ContextGraph.create_entity_dict(ids["conn_id"],
                                              conn_name,
                                              "connector",
                                              impact=[ids["comp_id"]])

        expected_comp = ContextGraph.create_entity_dict(ids["comp_id"],
                                              comp_id,
                                              "component",
                                              impact=[],
                                              depends=[ids["conn_id"]])

        comp = ContextGraph.create_entity_dict(comp_id,
                                     comp_id,
                                     "component",
                                     impact=[],
                                     depends=[])

        res = process.update_context_case5(ids, [comp], event)
        result_conn, result_comp, result_re = prepare_test_update_context(res)

        self.assertDictEqual(expected_conn, result_conn)
        self.assertDictEqual(expected_comp, result_comp)
Пример #2
0
    def test_gen_ids(self):
        conn_id = "conn_id"
        conn_name = "conn_name"
        comp_id = "comp_id"
        re_id = "re_id"

        event = create_event(conn_id, conn_name, comp_id, re_id)
        event_re_none = create_event(conn_id, conn_name, comp_id, None)

        expected = {"comp_id": comp_id,
                    "conn_id": "{0}/{1}".format(conn_id, conn_name),
                    "re_id": "{0}/{1}".format(re_id, comp_id)}

        expected_re_none = {"comp_id": comp_id,
                            "conn_id": "{0}/{1}".format(conn_id, conn_name),
                            "re_id": None}

        self.assertEqual(process.gen_ids(event), expected)
        self.assertEqual(process.gen_ids(event_re_none), expected_re_none)
Пример #3
0
    def test_info_field(self):

        conn_id = "conn_id"
        conn_name = "conn_name"
        comp_id = "comp_id"
        re_id = "re_id"

        event = create_event(conn_id, conn_name, comp_id, re_id)

        ids = process.gen_ids(event)

        expected_conn = ContextGraph.create_entity_dict(ids["conn_id"],
                                              conn_name,
                                              "connector",
                                              impact=sorted([ids["comp_id"],
                                                             ids["re_id"]]),
                                              infos={})

        expected_comp = ContextGraph.create_entity_dict(ids["comp_id"],
                                              comp_id,
                                              "component",
                                              depends=sorted([ids["conn_id"],
                                                              ids["re_id"]]),
                                              infos={})

        expected_re = ContextGraph.create_entity_dict(ids["re_id"],
                                            re_id,
                                            "resource",
                                            impact=[ids["comp_id"]],
                                            depends=[ids["conn_id"]],
                                            infos={})

        process.update_context((False, False, False),
                               ids,
                               [],
                               event)

        result_re = self.gctx_man.get_entities_by_id(ids["re_id"])[0]
        result_conn = self.gctx_man.get_entities_by_id(ids["conn_id"])[0]
        result_comp = self.gctx_man.get_entities_by_id(ids["comp_id"])[0]

        # A fields links is added in the entity returned  by the
        # get_entities_by_id methods. It is not relievent to this test and his
        # value fluctuate with specific configuration. So we delete it in the
        # entity returned by get_entities_by_id
        del result_comp["links"]
        del result_conn["links"]
        del result_re["links"]

        self.assertEqualEntities(expected_re, result_re)
        self.assertEqualEntities(expected_conn, result_conn)
        self.assertEqualEntities(expected_comp, result_comp)
Пример #4
0
    def test_update_context_case3(self):
        conn_id = "conn_id"
        conn_name = "conn_name"
        comp_id = "comp_id"
        re_id = "re_id"

        event = create_event(conn_id, conn_name, comp_id, re_id)
        ids = process.gen_ids(create_event(conn_id, conn_name, comp_id, re_id))

        expected_conn = ContextGraph.create_entity_dict(ids["conn_id"],
                                              conn_name,
                                              "connector",
                                              impact=sorted([ids["comp_id"],
                                                             ids["re_id"]]))

        expected_comp = ContextGraph.create_entity_dict(ids["comp_id"],
                                              comp_id,
                                              "component",
                                              depends=sorted([ids["conn_id"],
                                                              ids["re_id"]]))

        expected_re = ContextGraph.create_entity_dict(ids["re_id"],
                                            re_id,
                                            "resource",
                                            impact=[ids["comp_id"]],
                                            depends=[ids["conn_id"]])

        conn = ContextGraph.create_entity_dict("{0}/{1}".format(conn_id, conn_name),
                                     conn_name,
                                     "connector",
                                     impact=[comp_id],
                                     depends=[])

        comp = ContextGraph.create_entity_dict(comp_id,
                                     comp_id,
                                     "component",
                                     impact=[],
                                     depends=["{0}/{1}".format(conn_id,
                                                               conn_name)])

        res = process.update_context_case3(ids, [conn, comp], event)
        result_conn, result_comp, result_re = prepare_test_update_context(res)

        self.assertDictEqual(expected_conn, result_conn)
        self.assertDictEqual(expected_comp, result_comp)
        self.assertDictEqual(expected_re, result_re)
Пример #5
0
    def test_update_context_case1(self):
        conn_id = "conn_id"
        conn_name = "conn_name"
        comp_id = "comp_id"
        re_id = "re_id"

        event = create_event(conn_id, conn_name, comp_id, re_id)
        ids = process.gen_ids(event)

        impact = sorted([ids["comp_id"], ids["re_id"]])
        expected_conn = ContextGraph.create_entity_dict(ids["conn_id"],
                                                        conn_name,
                                                        "connector",
                                                        impact=impact)

        depends = sorted([ids["conn_id"], ids["re_id"]])
        expected_comp = ContextGraph.create_entity_dict(ids["comp_id"],
                                                        comp_id,
                                                        "component",
                                                        depends=depends)

        impact = [ids["comp_id"]]
        depends = [ids["conn_id"]]
        expected_re = ContextGraph.create_entity_dict(ids["re_id"],
                                                      re_id,
                                                      "resource",
                                                      impact=impact,
                                                      depends=depends)

        res = process.update_context_case1(ids, event)

        result_conn, result_comp, result_re = prepare_test_update_context(res)

        self.assertDictEqual(expected_comp, result_comp)
        self.assertDictEqual(expected_conn, result_conn)
        self.assertDictEqual(expected_re, result_re)