示例#1
0
    def setUp(self):
        self.it = IndexItemsTable()
        self.it.clear_tables()  # in case db was not cleaned last time the tests were run

        self.in_file_path = os.path.join(os.path.dirname(__file__), 'test-index-in.yaml')
        self.in_file_path = "/repositories/betainstl/svn/instl/index.yaml"
        self.out_file_path = os.path.join(os.path.dirname(__file__), 'test-index-out.yaml')
        self.ref_file_path = os.path.join(os.path.dirname(__file__), 'test-index-ref.yaml')

        self.it.read_yaml_file(self.in_file_path)
        self.it.resolve_inheritance()
示例#2
0
    def setUp(self):
        self.it = IndexItemsTable()
        self.it.clear_tables()  # in case db was not cleaned last time the tests were run

        D = index_item_t(iid="D", inherit_resolved=True)
        D.original_details.extend([index_item_detail_t(os="common", detail_name="detail-1-D", detail_value="value-1-D"),
                                   index_item_detail_t(os="common", detail_name="detail-2-D", detail_value="value-2-D")])
        self.it.session.add(D)

        self.it.session.add(index_item_t(iid="A", inherit_resolved=False))
        self.it.session.add(index_item_t(iid="C", inherit_resolved=False))
        self.it.session.add(index_item_t(iid="B", inherit_resolved=False))

        DD_detail_1 = index_item_detail_t(os="common", detail_name="detail-1-D", detail_value="value-1-DD")
        DD_detail_1.item = index_item_t(iid="DD", inherit_resolved=False)
        DD_detail_2 = index_item_detail_t(os="common", detail_name="detail-2-D", detail_value="value-2-DD")
        DD_detail_2.item = DD_detail_1.item
        self.it.session.add(DD_detail_1)
        self.it.session.add(DD_detail_2)

        self.it.session.commit()
示例#3
0
class TestReadWrite(unittest.TestCase):
    @timing
    def setUp(self):
        self.it = IndexItemsTable()
        self.it.clear_tables()  # in case db was not cleaned last time the tests were run

        self.in_file_path = os.path.join(os.path.dirname(__file__), 'test-index-in.yaml')
        self.in_file_path = "/repositories/betainstl/svn/instl/index.yaml"
        self.out_file_path = os.path.join(os.path.dirname(__file__), 'test-index-out.yaml')
        self.ref_file_path = os.path.join(os.path.dirname(__file__), 'test-index-ref.yaml')

        self.it.read_yaml_file(self.in_file_path)
        self.it.resolve_inheritance()

    def tearDown(self):
        #self.it.clear_tables()
        pass

    def test_00(self):
        # dummy test to check setUp/tearDown on their own
        pass
示例#4
0
class TestItemTable(unittest.TestCase):
    def setUp(self):
        self.it = IndexItemsTable()
        self.it.clear_tables()  # in case db was not cleaned last time the tests were run

        D = index_item_t(iid="D", inherit_resolved=True)
        D.original_details.extend([index_item_detail_t(os="common", detail_name="detail-1-D", detail_value="value-1-D"),
                                   index_item_detail_t(os="common", detail_name="detail-2-D", detail_value="value-2-D")])
        self.it.session.add(D)

        self.it.session.add(index_item_t(iid="A", inherit_resolved=False))
        self.it.session.add(index_item_t(iid="C", inherit_resolved=False))
        self.it.session.add(index_item_t(iid="B", inherit_resolved=False))

        DD_detail_1 = index_item_detail_t(os="common", detail_name="detail-1-D", detail_value="value-1-DD")
        DD_detail_1.item = index_item_t(iid="DD", inherit_resolved=False)
        DD_detail_2 = index_item_detail_t(os="common", detail_name="detail-2-D", detail_value="value-2-DD")
        DD_detail_2.item = DD_detail_1.item
        self.it.session.add(DD_detail_1)
        self.it.session.add(DD_detail_2)

        self.it.session.commit()

    def tearDown(self):
        self.it.clear_tables()

    def test_00_empty_tables(self):
        self.it.clear_tables()
        the_items = self.it.get_all_index_items()
        self.assertEqual(the_items, [])

    def test_01_num_items(self):
        the_items = self.it.get_all_index_items()
        self.assertEqual(len(the_items), 5)
        the_details = self.it.get_original_details()
        self.assertEqual(len(the_details), 4)

    def test_02_IndexItemRow_get_item(self):
        the_item1 = self.it.get_index_item("B")
        self.assertEqual(the_item1.iid, "B")

        the_item2 = self.it.get_index_item("A")
        self.assertEqual(the_item2.iid, "A")

        self.assertNotEqual(the_item1, the_item2)

        the_item3 = self.it.get_index_item("B")
        self.assertIs(the_item1, the_item3, "same object should be returned by two calls with same iid")

        the_item3 = self.it.get_index_item("Z")
        self.assertIs(the_item3, None, "None should be returned for non existing index_item_t")

    def test_03_IndexItemRow_get_all_items(self):
        the_items1 = self.it.get_all_index_items()
        self.assertEqual(the_items1[0].iid, "D")
        self.assertEqual(the_items1[1].iid, "A")
        self.assertEqual(the_items1[2].iid, "C")
        self.assertEqual(the_items1[3].iid, "B")
        the_items2 = self.it.get_all_index_items()
        self.assertEqual(the_items1, the_items2, "same list should be returned by two calls")

    def test_04_get_item_by_resolve_status(self):
        a1 = self.it.get_index_item("A")
        a2 = self.it.get_item_by_resolve_status("A", False)
        self.assertIs(a1, a2)
        a3 = self.it.get_item_by_resolve_status("A", True)
        self.assertIs(a3, None)
        a1 = self.it.get_index_item("D")
        a2 = self.it.get_item_by_resolve_status("D", True)
        self.assertIs(a1, a2)
        a3 = self.it.get_item_by_resolve_status("D", False)
        self.assertIs(a3, None)
        a4 = self.it.get_item_by_resolve_status("Z", False)
        self.assertIs(a4, None)
        a5 = self.it.get_item_by_resolve_status("Z", True)
        self.assertIs(a5, None)

    def test_05_get_items_by_resolve_status(self):
        a = self.it.get_index_item("A")
        b = self.it.get_index_item("B")
        c = self.it.get_index_item("C")
        dd = self.it.get_index_item("DD")
        l1 = self.it.get_items_by_resolve_status(False)
        self.assertEqual(l1, [a, b, c, dd])

        d = self.it.get_index_item("D")
        l2 = self.it.get_items_by_resolve_status(True)
        self.assertEqual(l2, [d])

    def test_06_get_all_iids(self):
        all_iids1 = self.it.get_all_iids()
        self.assertEqual(all_iids1, ["A", "B", "C", "D", "DD"])
        all_iids2 = self.it.get_all_iids()
        self.assertEqual(all_iids1, all_iids2)

    def test_07_get_original_details_for_item(self):
        ds_for_D = self.it.get_original_details("D")
        self.assertEqual(str(ds_for_D[0]), "1) 1, common, detail-1-D: value-1-D")
        self.assertEqual(str(ds_for_D[1]), "2) 1, common, detail-2-D: value-2-D")
        ds_for_Z = self.it.get_original_details("Z")
        self.assertEqual(ds_for_Z, [])

    def test_08_get_original_details_all(self):
        all_details = self.it.get_original_details()
        self.assertEqual(len(all_details), 4)
        self.assertEqual(str(all_details[0]), "1) 1, common, detail-1-D: value-1-D")
        self.assertEqual(str(all_details[1]), "2) 1, common, detail-2-D: value-2-D")
        self.assertEqual(str(all_details[2]), "3) 5, common, detail-1-D: value-1-DD")
        self.assertEqual(str(all_details[3]), "4) 5, common, detail-2-D: value-2-DD")

    def test_09_get_original_details_by_name(self):
        ds_for_D = self.it.get_original_details(detail_name="detail-1-D")
        self.assertEqual(str(ds_for_D[0]), "1) 1, common, detail-1-D: value-1-D")
        self.assertEqual(str(ds_for_D[1]), "3) 5, common, detail-1-D: value-1-DD")
        ds_for_Z = self.it.get_original_details(detail_name="some-bullshit-detail-name")
        self.assertEqual(ds_for_Z, [])

    def test_10_get_original_details_for_item_by_name(self):
        ds_for_D = self.it.get_original_details("D", "detail-1-D")
        self.assertEqual(str(ds_for_D[0]), "1) 1, common, detail-1-D: value-1-D")
        ds_for_D = self.it.get_original_details("D", "some-bullshit-detail-name")
        self.assertEqual(ds_for_D, [])
        ds_for_D = self.it.get_original_details("some-bullshit-item", "detail-1-D")
        self.assertEqual(ds_for_D, [])