Beispiel #1
0
class StructTest(unittest.TestCase):
    DB = import_as_dict(
        os.environ["GRAMPS_RESOURCES"] + "/example/gramps/data.gramps", User())

    def __init__(self, *args, **kwargs):
        self.dbi = DBI(StructTest.DB, None)  # no document here
        self.dbi.flat = True
        self.dbi.sdb = SimpleAccess(StructTest.DB)
        self.pcount = len(StructTest.DB._tables["Person"]["handles_func"]())
        unittest.TestCase.__init__(self, *args, **kwargs)

    def runTest(self):  # for python -i
        pass

    def test_struct1(self):
        with StructTest.DB._tables["Person"]["cursor_func"]() as cursor:
            for handle, person in cursor:
                p = StructTest.DB._tables["Person"]["class_func"](person)
                if p and len(p.parent_family_list) > 0:
                    person_with_parents = p
                    break
        to_struct = person_with_parents.to_struct()
        struct = Struct(to_struct, StructTest.DB)
        self.assertTrue(
            len(struct.parent_family_list) > 0,
            "Size not correct: %s is not > than %s" %
            (len(struct.parent_family_list), 0))

        self.assertTrue(
            struct.parent_family_list[0].private == False,
            "Inproper value of private: %s != %s" %
            (struct.parent_family_list[0].private, False))

    def test_struct2(self):
        with StructTest.DB._tables["Person"]["cursor_func"]() as cursor:
            for handle, person in cursor:
                p = StructTest.DB._tables["Person"]["class_func"](person)
                if p and len(p.event_ref_list) > 0:
                    person_with_events = p
                    break
        to_struct = person_with_events.to_struct()
        struct = Struct(to_struct, StructTest.DB)
        self.assertTrue(
            len(struct.event_ref_list) > 0,
            "Size not correct: %s is not > than %s" %
            (len(struct.event_ref_list), 0))

        self.assertTrue(
            struct.event_ref_list[0] is not None,
            "not None: %s is not %s" % (struct.event_ref_list[0], None))
Beispiel #2
0
    def write_report(self):
        """ The short method that runs through each month and creates a page. """
        self.doc.start_paragraph('DIFF-Title') 
        self.doc.write_text("Database Differences Report")
        self.doc.end_paragraph()

        self.doc.start_table('DiffTable','DIFF-Table2')
        self.doc.start_row()
        self.doc.start_cell('DIFF-TableCellNoBorder')
        self.doc.start_paragraph('DIFF-TableHeading')
        self.doc.write_text("Database:")
        self.doc.end_paragraph()
        self.doc.end_cell()
        self.doc.start_cell('DIFF-TableCellNoBorder')
        self.doc.start_paragraph('DIFF-Text')
        self.doc.write_text(str(self.database.get_dbname()))
        self.doc.end_paragraph()
        self.doc.end_cell()
        self.doc.end_row()
        self.doc.start_row()
        self.doc.start_cell('DIFF-TableCellNoBorder')
        self.doc.start_paragraph('DIFF-TableHeading')
        self.doc.write_text("File:")
        self.doc.end_paragraph()
        self.doc.end_cell()
        self.doc.start_cell('DIFF-TableCellNoBorder')
        self.doc.start_paragraph('DIFF-Text')
        self.doc.write_text(self.filename)
        self.doc.end_paragraph()
        self.doc.end_cell()
        self.doc.end_row()
        self.doc.end_table()
        self.doc.start_paragraph('DIFF-Heading') 
        self.doc.write_text("")
        self.doc.end_paragraph()
        self.database2 = import_as_dict(self.filename, self._user)
        self.sa = [SimpleAccess(self.database), SimpleAccess(self.database2)]
        diffs, added, missing = diff_dbs(self.database, self.database2, self._user)
        if self.show_diff:
            self.doc.start_paragraph('DIFF-Heading') 
            self.doc.write_text("Differences between Database and File")
            self.doc.end_paragraph()
            last_object = None
            if diffs:
                self._user.begin_progress(_('Family Tree Differences'), 
                                          _('Processing...'), len(diffs))
                for diff in diffs:
                    self._user.step_progress()
                    obj_type, item1, item2 = diff
                    if last_object != item1:
                        if last_object != None:
                            self.doc.end_table()
                            self.doc.start_paragraph('DIFF-Heading') 
                            self.doc.write_text("")
                            self.doc.end_paragraph()
                        self.doc.start_table('DiffTable','DIFF-Table3')
                    last_object = item1
                    if hasattr(item1, "gramps_id"):
                        self.start_list(self.doc, "%s: %s" % (obj_type, item1.gramps_id), 
                                        "Database", "File")
                    else:
                        self.start_list(self.doc, "%s: %s" % (obj_type, item1.get_name()), 
                                        "Database", "File")
                    self.report_diff(obj_type, item1.to_struct(), item2.to_struct(), self.doc)
                self.doc.end_table()
            else:
                self.doc.start_table('DiffTable','DIFF-Table3')
                self.start_list(self.doc, "No differences", "", "") 
                self.doc.end_table()
            self.doc.start_paragraph('DIFF-Heading') 
            self.doc.write_text("")
            self.doc.end_paragraph()
        if self.show_missing:
            self.doc.start_paragraph('DIFF-Heading') 
            self.doc.write_text("Missing items in File that are added in Database")
            self.doc.end_paragraph()
            if missing:
                for pair in missing:
                    obj_type, item = pair
                    self.doc.start_paragraph('DIFF-Text') 
                    self.doc.write_text("Missing %s: %s" % (obj_type, self.sa[0].describe(item)))
                    self.doc.end_paragraph()
            else:
                self.doc.start_paragraph('DIFF-Text') 
                self.doc.write_text("Nothing missing")
                self.doc.end_paragraph()
            self.doc.start_paragraph('DIFF-Heading') 
            self.doc.write_text("")
            self.doc.end_paragraph()
        if self.show_added:
            self.doc.start_paragraph('DIFF-Heading') 
            self.doc.write_text("Added items in File that are missing in Database")
            self.doc.end_paragraph()
            if added:
                for pair in added:
                    obj_type, item = pair
                    self.doc.start_paragraph('DIFF-Text') 
                    self.doc.write_text("Added %s: %s " % (obj_type, self.sa[1].describe(item)))
                    self.doc.end_paragraph()
            else:
                self.doc.start_paragraph('DIFF-Text') 
                self.doc.write_text("Nothing added")
                self.doc.end_paragraph()
            self.doc.start_paragraph('DIFF-Heading') 
            self.doc.write_text("")
            self.doc.end_paragraph()
        self._user.end_progress()
Beispiel #3
0
    struct = obj.to_struct()
    serialized = obj.__class__.from_struct(struct)

    def test(self):
        self.assertEqual(obj.serialize(), serialized)

    name = "test_serialize_%s_%s" % (obj.__class__.__name__, obj.handle)
    setattr(DatabaseCheck, name, test)
    ####
    #def test2(self):
    #    self.assertEqual(obj.serialize(), from_struct(struct).serialize())
    #name = "test_create_%s_%s" % (obj.__class__.__name__, obj.handle)
    #setattr(DatabaseCheck, name, test2)


db = import_as_dict("example/gramps/example.gramps", User())
for table in db._tables.keys():
    for handle in db._tables[table]["handles_func"]():
        obj = db._tables[table]["handle_func"](handle)
        generate_case(obj)


class StructTest(unittest.TestCase):
    def test(self):
        family = db.get_family_from_gramps_id("F0001")
        s = Struct(family.to_struct(), db)
        self.assertEqual(s["gramps_id"], "F0001")
        s["gramps_id"] = "TEST"
        self.assertEqual(s["gramps_id"], "TEST")
        self.assertEqual(s.father_handle.primary_name.first_name, "Allen Carl")
        s["father_handle.primary_name.first_name"] = "Edward"
 def setUpClass(cls):
     cls.db = import_as_dict("example/gramps/example.gramps", User())
Beispiel #5
0
 def setUpClass(cls):
     """
     Import example database.
     """
     cls.db = import_as_dict(EXAMPLE, User())
Beispiel #6
0
 def setUpClass(cls):
     """
     Import example database.
     """
     cls.db = import_as_dict(EXAMPLE, User())
Beispiel #7
0
 def setUpClass(cls):
     """
     Import example database.
     """
     cls.db = import_as_dict("example/gramps/example.gramps", User())
Beispiel #8
0
    struct = obj.to_struct()
    serialized = obj.__class__.from_struct(struct)

    def test(self):
        self.assertEqual(obj.serialize(), serialized)

    name = "test_serialize_%s_%s" % (obj.__class__.__name__, obj.handle)
    setattr(DatabaseCheck, name, test)
    ####
    #def test2(self):
    #    self.assertEqual(obj.serialize(), from_struct(struct).serialize())
    #name = "test_create_%s_%s" % (obj.__class__.__name__, obj.handle)
    #setattr(DatabaseCheck, name, test2)


db = import_as_dict(EXAMPLE, User())
for table in db.get_table_func():
    for handle in db.get_table_func(table, "handles_func")():
        obj = db.get_table_func(table, "handle_func")(handle)
        generate_case(obj)


class StructTest(unittest.TestCase):
    def test(self):
        family = db.get_family_from_gramps_id("F0001")
        s = Struct(family.to_struct(), db)
        self.assertEqual(s["gramps_id"], "F0001")
        s["gramps_id"] = "TEST"
        self.assertEqual(s["gramps_id"], "TEST")
        self.assertEqual(s.father_handle.primary_name.first_name, "Allen Carl")
        s["father_handle.primary_name.first_name"] = "Edward"
Beispiel #9
0
    """
    Dynamically generate tests and attach to DatabaseCheck.
    """
    struct = obj.to_struct()
    serialized = obj.__class__.from_struct(struct)
    def test(self):
        self.assertEqual(obj.serialize(), serialized)
    name = "test_serialize_%s_%s" % (obj.__class__.__name__, obj.handle)
    setattr(DatabaseCheck, name, test)
    ####
    #def test2(self):
    #    self.assertEqual(obj.serialize(), from_struct(struct).serialize())
    #name = "test_create_%s_%s" % (obj.__class__.__name__, obj.handle)
    #setattr(DatabaseCheck, name, test2)

db = import_as_dict("example/gramps/example.gramps", User())
for table in db._tables.keys():
    for handle in db._tables[table]["handles_func"]():
        obj = db._tables[table]["handle_func"](handle)
        generate_case(obj)

class StructTest(unittest.TestCase):
    def test(self):
        family = db.get_family_from_gramps_id("F0001")
        s = Struct(family.to_struct(), db)
        self.assertEqual(s["gramps_id"], "F0001")
        s["gramps_id"] = "TEST"
        self.assertEqual(s["gramps_id"], "TEST")
        self.assertEqual(s.father_handle.primary_name.first_name,
                         "Allen Carl")
        s["father_handle.primary_name.first_name"] = "Edward"
Beispiel #10
0
class SelectTest(unittest.TestCase):
    DB = import_as_dict(
        os.environ["GRAMPS_RESOURCES"] + "/example/gramps/data.gramps", User())

    def __init__(self, *args, **kwargs):
        self.dbi = DBI(SelectTest.DB, None)  # no document here
        self.dbi.flat = True
        self.dbi.sdb = SimpleAccess(SelectTest.DB)
        self.pcount = len(SelectTest.DB._tables["Person"]["handles_func"]())
        self.john_count = 0
        with SelectTest.DB._tables["Person"]["cursor_func"]() as cursor:
            for handle, person in cursor:
                name = SelectTest.DB._tables["Person"]["class_func"](
                    person).get_primary_name()
                if name and "John" in name.first_name:
                    self.john_count += 1
        unittest.TestCase.__init__(self, *args, **kwargs)

    def runTest(self):  # for python -i
        pass

    def do_query(self, test, string, count):
        self.dbi.parse(string)
        table = Table()
        self.dbi.process_table(table)
        self.assertTrue(
            len(table.data) == count,
            "Test #%d, Selected %d records from example.gramps; should have been %d: '%s'"
            % (test, len(table.data), count, string))
        return table

    def test_select1(self):
        self.do_query(1, "select * from person;", self.pcount)

    def test_select2(self):
        self.do_query(
            2, "select primary_name.first_name "
            "from person "
            "where 'John' in primary_name.first_name;", self.john_count)

    def test_select3(self):
        self.do_query(
            3, "update person SET primary_name.first_name='XXX' "
            "where 'John' in primary_name.first_name;", self.john_count)

    def test_select4(self):
        self.do_query(
            4, "select primary_name.first_name "
            "from person "
            "where primary_name.first_name == 'XXX';", self.john_count)

    def test_select5(self):
        self.do_query(
            5, "UPDATE person SET private = (False or False) "
            "from person "
            "where primary_name.first_name == 'XXX';", self.john_count)

    def test_select6(self):
        self.do_query(
            6, "select private, primary_name "
            "from person "
            "where primary_name.first_name == 'XXX' and private;", 0)

    def test_select7(self):
        self.do_query(
            7, "SELECT private, primary_name "
            "FROM person "
            "where primary_name.first_name == 'XXX' and not private;",
            self.john_count)

    def test_select8(self):
        self.do_query(
            8, "UPDATE person SET private = (False or True) "
            "from person "
            "where primary_name.first_name == 'XXX';", self.john_count)

    def test_select9(self):
        self.do_query(
            9, "select private, primary_name "
            "from person "
            "where primary_name.first_name == 'XXX' and private;",
            self.john_count)

    def test_select10(self):
        self.do_query(
            10, "select private, primary_name "
            "from person "
            "where primary_name.first_name == 'XXX' and not private;", 0)

    def test_select11(self):
        self.do_query(11, "SELECT * from person LIMIT 10, 20", 10)

    def test_select12(self):
        self.do_query(12, "SELECT * from person LIMIT 5", 5)

    def test_select13(self):
        self.do_query(13, "SELECT ROWNUM, random.random() from person LIMIT 5",
                      5)

    def test_select14(self):
        self.do_query(
            14,
            "select * from person where not parent_family_list[0].private;",
            38)

    def test_select15(self):
        self.do_query(
            15.1,
            "UPDATE person SET private=True WHERE not parent_family_list[0].private;",
            38)
        self.do_query(15.2, "SELECT * from person WHERE private;", 38)
        self.do_query(15.3, "UPDATE person SET private=False;", 60)
        self.do_query(15.4, "UPDATE person SET private=False WHERE private;",
                      0)
        self.do_query(15.5, "UPDATE person SET private=True;", 60)
        self.do_query(15.6,
                      "UPDATE person SET private=True where not private;", 0)

    def test_select16(self):
        table = self.do_query(16.1, "SELECT gramps_id as id from person;",
                              self.pcount)
        self.assertTrue(
            len(table.data) == 60, "Table should have selected 60 items")

    def test_select17(self):
        table = self.do_query(
            17.1, "SELECT gramps_id as id from person where id == 'I0004';", 1)
        self.assertTrue(
            table.data[0][0] == "I0004",
            "First row, first col is %s, should be %s" %
            (table.data[0][0], "I0004"))

        table = self.do_query(
            17.2, "SELECT gramps_id, father_handle.primary_name.first_name "
            "FROM family WHERE father_handle.primary_name.first_name;", 23)
        table.data = sorted(table.data)
        self.assertTrue(
            table.data[0][0] == "F0000",
            "First row, first col is %s, should be %s" %
            (table.data[0][0], "F0000"))
        self.assertTrue(
            table.data[0][1] == "Martin",
            "First row, second col is %s, should be %s" %
            (table.data[0][1], "Martin"))
        self.assertTrue(len(table.data) == 23, "Should have selected 23 rows")

        table = self.do_query(
            17.3,
            "UPDATE family SET father_handle.primary_name.first_name='Father' WHERE gramps_id == 'F0005';",
            1)
        self.assertTrue(
            table.data[0][0] == "F0005",
            "First row, first col is %s, should be %s" %
            (table.data[0][0], "F0005"))

        table = self.do_query(
            17.4,
            "SELECT gramps_id, father_handle.primary_name.first_name, father_handle.gramps_id "
            "FROM family WHERE gramps_id == 'F0005';", 1)
        self.assertTrue(
            table.data[0][0] == "F0005",
            "1 First row, first col is %s, should be %s" %
            (table.data[0][0], "F0005"))
        self.assertTrue(
            table.data[0][1] == "Father",
            "1 First row, second col is %s, should be %s" %
            (table.data[0][1], "Father"))
        self.assertTrue(
            table.data[0][2] == "I0012",
            "1 First row, third col is %s, should be %s" %
            (table.data[0][2], "I0012"))

        table = self.do_query(
            17.5, "SELECT gramps_id, primary_name.first_name "
            "FROM person WHERE gramps_id == 'I0012';", 1)
        self.assertTrue(
            table.data[0][0] == "I0012",
            "First row, first col is %s, should be %s" %
            (table.data[0][0], "I0012"))
        self.assertTrue(
            table.data[0][1] == "Father",
            "First row, second col is %s, should be %s" %
            (table.data[0][1], "Father"))

    def test_select18(self):
        table = self.do_query(
            18.1,
            "SELECT gramps_id, father_handle.GIVEN from family where gramps_id == 'F0005';",
            1)
        self.assertTrue(
            table.data[0][1] == "Father",
            "First row, second col is %s, should be %s" %
            (table.data[0][1], "Father"))
Beispiel #11
0
 def setUpClass(cls):
     """
     Import example database.
     """
     cls.db = import_as_dict("example/gramps/example.gramps", User())
Beispiel #12
0
    """
    Dynamically generate tests and attach to DatabaseCheck.
    """
    struct = obj.to_struct()
    serialized = obj.__class__.from_struct(struct)
    def test(self):
        self.assertEqual(obj.serialize(), serialized)
    name = "test_serialize_%s_%s" % (obj.__class__.__name__, obj.handle)
    setattr(DatabaseCheck, name, test)
    ####
    #def test2(self):
    #    self.assertEqual(obj.serialize(), from_struct(struct).serialize())
    #name = "test_create_%s_%s" % (obj.__class__.__name__, obj.handle)
    #setattr(DatabaseCheck, name, test2)

db = import_as_dict(EXAMPLE, User())
for table in db.get_table_func():
    for handle in db.get_table_func(table,"handles_func")():
        obj = db.get_table_func(table,"handle_func")(handle)
        generate_case(obj)

class StructTest(unittest.TestCase):
    def test(self):
        family = db.get_family_from_gramps_id("F0001")
        s = Struct(family.to_struct(), db)
        self.assertEqual(s["gramps_id"], "F0001")
        s["gramps_id"] = "TEST"
        self.assertEqual(s["gramps_id"], "TEST")
        self.assertEqual(s.father_handle.primary_name.first_name,
                         "Allen Carl")
        s["father_handle.primary_name.first_name"] = "Edward"
Beispiel #13
0
    def write_report(self):
        """ The short method that runs through each month and creates a page. """
        self.doc.start_paragraph('DIFF-Title')
        self.doc.write_text("Database Differences Report")
        self.doc.end_paragraph()

        self.doc.start_table('DiffTable', 'DIFF-Table2')
        self.doc.start_row()
        self.doc.start_cell('DIFF-TableCellNoBorder')
        self.doc.start_paragraph('DIFF-TableHeading')
        self.doc.write_text("Database:")
        self.doc.end_paragraph()
        self.doc.end_cell()
        self.doc.start_cell('DIFF-TableCellNoBorder')
        self.doc.start_paragraph('DIFF-Text')
        self.doc.write_text(str(self.database.get_dbname()))
        self.doc.end_paragraph()
        self.doc.end_cell()
        self.doc.end_row()
        self.doc.start_row()
        self.doc.start_cell('DIFF-TableCellNoBorder')
        self.doc.start_paragraph('DIFF-TableHeading')
        self.doc.write_text("File:")
        self.doc.end_paragraph()
        self.doc.end_cell()
        self.doc.start_cell('DIFF-TableCellNoBorder')
        self.doc.start_paragraph('DIFF-Text')
        self.doc.write_text(self.filename)
        self.doc.end_paragraph()
        self.doc.end_cell()
        self.doc.end_row()
        self.doc.end_table()
        self.doc.start_paragraph('DIFF-Heading')
        self.doc.write_text("")
        self.doc.end_paragraph()
        self.database2 = import_as_dict(self.filename, self._user)
        if self.database2 is None:
            return
        self.sa = [SimpleAccess(self.database), SimpleAccess(self.database2)]
        diffs, added, missing = diff_dbs(self.database, self.database2,
                                         self._user)
        if self.show_diff:
            self.doc.start_paragraph('DIFF-Heading')
            self.doc.write_text("Differences between Database and File")
            self.doc.end_paragraph()
            last_object = None
            if diffs:
                self._user.begin_progress(_('Family Tree Differences'),
                                          _('Processing...'), len(diffs))
                for diff in diffs:
                    self._user.step_progress()
                    obj_type, item1, item2 = diff
                    if last_object != item1:
                        if last_object != None:
                            self.doc.end_table()
                            self.doc.start_paragraph('DIFF-Heading')
                            self.doc.write_text("")
                            self.doc.end_paragraph()
                        self.doc.start_table('DiffTable', 'DIFF-Table3')
                    last_object = item1
                    if hasattr(item1, "gramps_id"):
                        self.start_list(self.doc,
                                        "%s: %s" % (obj_type, item1.gramps_id),
                                        "Database", "File")
                    else:
                        self.start_list(
                            self.doc, "%s: %s" % (obj_type, item1.get_name()),
                            "Database", "File")
                    self.report_diff(obj_type, item1.to_struct(),
                                     item2.to_struct(), self.doc)
                self.doc.end_table()
            else:
                self.doc.start_table('DiffTable', 'DIFF-Table3')
                self.start_list(self.doc, "No differences", "", "")
                self.doc.end_table()
            self.doc.start_paragraph('DIFF-Heading')
            self.doc.write_text("")
            self.doc.end_paragraph()
        if self.show_missing:
            self.doc.start_paragraph('DIFF-Heading')
            self.doc.write_text(
                "Missing items in File that are added in Database")
            self.doc.end_paragraph()
            if missing:
                for pair in missing:
                    obj_type, item = pair
                    self.doc.start_paragraph('DIFF-Text')
                    self.doc.write_text("Missing %s: %s" %
                                        (obj_type, self.sa[0].describe(item)))
                    self.doc.end_paragraph()
            else:
                self.doc.start_paragraph('DIFF-Text')
                self.doc.write_text("Nothing missing")
                self.doc.end_paragraph()
            self.doc.start_paragraph('DIFF-Heading')
            self.doc.write_text("")
            self.doc.end_paragraph()
        if self.show_added:
            self.doc.start_paragraph('DIFF-Heading')
            self.doc.write_text(
                "Added items in File that are missing in Database")
            self.doc.end_paragraph()
            if added:
                for pair in added:
                    obj_type, item = pair
                    self.doc.start_paragraph('DIFF-Text')
                    self.doc.write_text("Added %s: %s " %
                                        (obj_type, self.sa[1].describe(item)))
                    self.doc.end_paragraph()
            else:
                self.doc.start_paragraph('DIFF-Text')
                self.doc.write_text("Nothing added")
                self.doc.end_paragraph()
            self.doc.start_paragraph('DIFF-Heading')
            self.doc.write_text("")
            self.doc.end_paragraph()
        self._user.end_progress()