예제 #1
0
 def cond(before, after):
     before(
         len(mmo.find(self.model, ["test", "dept", "street_address"]))
         == 1)
     after(
         len(
             mmo.find(self.model,
                      ["test", "dept", "number_and_street_name"])) == 1)
예제 #2
0
 def cond(before, after):
     before(
         any([
             m.tag == tagname and m.mapping == oldfk
             for m in mmo.find(self.model, oldfk)
         ]))
     after(
         any([
             m.tag == tagname and m.mapping == newfk
             for m in mmo.find(self.model, newfk)
         ]))
예제 #3
0
 def cond(before, after):
     before(
         any([
             m.tag == tag.source_definitions
             and m.mapping == 'personnel'
             for m in mmo.find(self.model, oldfk)
         ]))
     after(
         any([
             m.tag == tag.source_definitions
             and m.mapping == 'personnel'
             for m in mmo.find(self.model, newfk)
         ]))
예제 #4
0
 def cond(before, after):
     before(
         any([
             m.tag == tag.visible_columns
             and isinstance(m.mapping, dict)
             for m in mmo.find(self.model, oldfk)
         ]))
     after(
         any([
             m.tag == tag.visible_columns
             and isinstance(m.mapping, dict)
             for m in mmo.find(self.model, newfk)
         ]))
예제 #5
0
    def test_project_prune_fkey(self):
        src_key_name = ['test', 'person_dept_fkey']
        new_key_name = ['test', f'{self.unittest_tname}_dept_fkey']

        # verify found in source model
        matches = mmo.find(self.model, src_key_name)
        self.assertTrue(len(matches) > 0)

        # this projection does not include the fkey's columns and so it will be pruned from the computed relation
        temp = self.model.schemas['test'].create_table_as(
            self.unittest_tname,
            self.model.schemas['test'].tables['person'].select('last_name'))

        matches = mmo.find(self.model, new_key_name)
        self.assertTrue(len(matches) == 0)
예제 #6
0
    def test_project_prune_col_simple(self):
        """Prunes a column that directly appears in annotation without any fkey traversal."""
        cname = 'name'

        # verify found in source model
        matches = mmo.find(self.model, ['test', 'person', cname])
        self.assertTrue(len(matches) > 0)

        # select columns besides 'cname'
        temp = self.model.schemas['test'].create_table_as(
            self.unittest_tname,
            self.model.schemas['test'].tables['person'].select('RID', 'dept'))

        matches = mmo.find(self.model, ['test', self.unittest_tname, cname])
        self.assertTrue(len(matches) == 0)
예제 #7
0
    def test_project_prune_col_in_path(self):
        """Prunes a column that requires traversals of outbound and inbound fkeys."""
        cname = 'RID'

        # verify found in source model
        matches = mmo.find(self.model, ['test', 'person', cname])
        self.assertTrue(len(matches) > 0)

        # select columns besides 'cname'
        temp = self.model.schemas['test'].create_table_as(
            self.unittest_tname,
            self.model.schemas['test'].tables['person'].select('name', 'dept'))

        matches = mmo.find(self.model, ['test', self.unittest_tname, cname])
        self.assertTrue(len(matches) == 0)
예제 #8
0
    def test_reify_prune_key(self):
        src_key_name = ['test', 'person_RID_key']
        new_key_name = ['test', f'{self.unittest_tname}_RID_key']

        # verify found in source model
        matches = mmo.find(self.model, src_key_name)
        self.assertTrue(len(matches) > 0)

        # reify will project a subset of columns and form a new key, so the original key name mapping should be pruned
        temp = self.model.schemas['test'].create_table_as(
            self.unittest_tname,
            self.model.schemas['test'].tables['person'].reify(['name'],
                                                              'last_name'))

        matches = mmo.find(self.model, new_key_name)
        self.assertTrue(len(matches) == 0)
예제 #9
0
 def cond(assertion):
     matches = mmo.find(self.model, fkname)
     assertion(
         any([
             m.tag == tag.source_definitions and m.mapping == fkname
             for m in matches
         ]))
예제 #10
0
 def cond(assertion):
     matches = mmo.find(self.model, ["test", "dept", "name"])
     assertion(
         any([
             m.anchor.name == 'person' and m.tag == tag.visible_columns
             and isinstance(m.mapping, dict) for m in matches
         ]))
예제 #11
0
 def cond(assertion):
     matches = mmo.find(self.model, ["test", "person", "RID"])
     assertion(
         any([
             m.tag == tag.source_definitions
             and m.mapping == 'dept_size' for m in matches
         ]))
예제 #12
0
    def test_project_replace_fkey(self):
        src_key_name = ['test', 'person_dept_fkey']
        new_key_name = ['test', f'{self.unittest_tname}_dept_fkey']

        # verify found in source model
        matches = mmo.find(self.model, src_key_name)
        self.assertTrue(len(matches) > 0)

        # projecting the 'dept' should also carry forward and rename the fkey name in the mappings
        temp = self.model.schemas['test'].create_table_as(
            self.unittest_tname,
            self.model.schemas['test'].tables['person'].select('dept'))

        matches = mmo.find(self.model, new_key_name)
        self.assertTrue(len(matches) > 0)
        self.assertTrue(all([m.anchor == temp for m in matches]))
예제 #13
0
 def cond(assertion):
     matches = mmo.find(self.model, fkname)
     assertion(
         any([
             m.tag == tag.visible_foreign_keys and m.mapping == fkname
             for m in matches
         ]))
예제 #14
0
    def test_canonicalize(self):
        old_cname, new_cname = 'dept', 'name'
        src_fkey_name = ['test', f'person_{old_cname}_fkey']
        new_fkey_name = ['test', f'{self.unittest_tname}_{new_cname}_fkey']

        # verify found in source model
        matches = mmo.find(self.model, src_fkey_name)
        self.assertTrue(len(matches) > 0)

        # canonicalizing 'dept' will rename it to 'name' but should preserve it as a foreign key
        temp = self.model.schemas['test'].create_table_as(
            self.unittest_tname, self.model.schemas['test'].tables['person'].
            columns[old_cname].to_domain())

        matches = mmo.find(self.model, new_fkey_name)
        self.assertTrue(len(matches) > 0)
        self.assertTrue(all([m.anchor == temp for m in matches]))
예제 #15
0
 def cond(assertion):
     matches = mmo.find(self.model, ["test", "person", "dept"])
     assertion(
         any([
             m.anchor.name == 'person'
             and m.tag == tag.source_definitions and m.mapping == 'dept'
             for m in matches
         ]))
예제 #16
0
    def test_atomize(self):
        # though the operation will rename the column and therefore the key, the new key will get dropped and pruned
        # from the model due to the unnest involved in the atomize operation
        src_key_name = ['test', f'person_RID_key']
        new_key_name = ['test', f'{self.unittest_tname}_person_RID_key']

        # verify found in source model
        matches = mmo.find(self.model, src_key_name)
        self.assertTrue(len(matches) > 0)

        # atomizing the column will invalidate all key columns from the original relation
        temp = self.model.schemas['test'].create_table_as(
            self.unittest_tname, self.model.schemas['test'].tables['person'].
            columns['name'].to_atoms())

        matches = mmo.find(self.model, new_key_name)
        self.assertTrue(len(matches) == 0)
        self.assertTrue(all([m.anchor == temp for m in matches]))
예제 #17
0
    def test_project_rename_col_in_path(self):
        """Renames a column that requires traversals of outbound and inbound fkeys."""
        src_cname = 'RID'
        new_cname = 'record_id'

        # verify found in source model
        matches = mmo.find(self.model, ['test', 'person', src_cname])
        self.assertTrue(len(matches) > 0)

        # select columns besides 'cname'
        temp = self.model.schemas['test'].create_table_as(
            self.unittest_tname,
            self.model.schemas['test'].tables['person'].select(
                self.model.schemas['test'].tables['person'].columns[src_cname].
                alias(new_cname), 'dept'))

        matches = mmo.find(self.model,
                           ['test', self.unittest_tname, new_cname])
        self.assertTrue(len(matches) > 0)
예제 #18
0
    def test_project_rename_col_simple(self):
        """Renames a column that directly appears in annotation without any fkey traversal."""
        src_cname = 'name'
        new_cname = 'full_name'

        # verify found in source model
        matches = mmo.find(self.model, ['test', 'person', src_cname])
        self.assertTrue(len(matches) > 0)

        # select columns besides 'cname'
        temp = self.model.schemas['test'].create_table_as(
            self.unittest_tname,
            self.model.schemas['test'].tables['person'].select(
                self.model.schemas['test'].tables['person'].columns[src_cname].
                alias(new_cname)))

        matches = mmo.find(self.model,
                           ['test', self.unittest_tname, new_cname])
        self.assertTrue(len(matches) > 0)
예제 #19
0
    def test_project_rename_and_replace_key(self):
        old_cname, new_cname = 'RID', 'record_id'
        src_key_name = ['test', f'person_{old_cname}_key']
        new_key_name = ['test', f'{self.unittest_tname}_{new_cname}_key']

        # verify found in source model
        matches = mmo.find(self.model, src_key_name)
        self.assertTrue(len(matches) > 0)

        # projecting the 'dept' should also carry forward and rename the fkey name in the mappings
        temp = self.model.schemas['test'].create_table_as(
            self.unittest_tname,
            self.model.schemas['test'].tables['person'].select(
                self.model.schemas['test'].tables['person'].columns[old_cname].
                alias(new_cname)))

        matches = mmo.find(self.model, new_key_name)
        self.assertTrue(len(matches) > 0)
        self.assertTrue(all([m.anchor == temp for m in matches]))
예제 #20
0
    def test_join(self):
        # dept RID column and key should be found in model
        matches = mmo.find(self.model, ['test', 'dept_RID_key'])
        self.assertTrue(len(matches) > 0)
        matches = mmo.find(self.model, ['test', 'dept', 'RID'])
        self.assertTrue(len(matches) > 0)

        # join will invalidate all key columns from the original relations and rename conflicting columns
        temp = self.model.schemas['test'].create_table_as(
            self.unittest_tname,
            self.model.schemas['test'].tables['dept'].join(
                self.model.schemas['test'].tables['person']))

        # now, left_RID should be found in model, but the key should not since keys are not preserved in a join
        matches = mmo.find(self.model,
                           ['test', f'{self.unittest_tname}_left_RID_key'])
        self.assertTrue(len(matches) == 0)
        matches = mmo.find(self.model,
                           ['test', self.unittest_tname, 'left_RID'])
        self.assertTrue(len(matches) > 0)
        self.assertTrue(all([m.anchor == temp for m in matches]))
예제 #21
0
 def cond(assertion):
     matches = mmo.find(self.model, cname)
     assertion(len(matches))
예제 #22
0
 def cond(before, after):
     before(
         len(mmo.find(self.model, ["test", "person", "last_name"])) ==
         1)
     after(
         len(mmo.find(self.model, ["test", "person", "surname"])) == 1)
예제 #23
0
 def cond(before, after):
     before(
         len(mmo.find(self.model, ["test", "dept", "postal_code"])) ==
         1)
     after(len(mmo.find(self.model, ["test", "dept", "zip"])) == 1)
예제 #24
0
 def cond(assertion):
     matches = mmo.find(self.model, ["test", "dept", "RMT"])
     assertion(len(matches) == 1)
예제 #25
0
 def cond(assertion):
     assertion(
         len(mmo.find(self.model, ["test", "person", "last_name"])) ==
         1)
예제 #26
0
 def cond(before, after):
     before(len(mmo.find(self.model, ["test", "dept", "country"])) == 1)
     after(
         len(mmo.find(self.model, ["test", "dept", "country_code"])) ==
         1)
예제 #27
0
 def cond(before, after):
     before(len(mmo.find(self.model, ["test", "dept", "state"])) == 1)
     after(
         len(mmo.find(self.model,
                      ["test", "dept", "state_or_province"])) == 1)
예제 #28
0
 def cond(before, after):
     before(len(mmo.find(self.model, ["test", "dept", "city"])) == 1)
     after(len(mmo.find(self.model, ["test", "dept", "township"])) == 1)
예제 #29
0
 def cond(before, after):
     before(len(mmo.find(self.model, ["test", "dept_RID_key"])) == 1)
     after(len(mmo.find(self.model, ["test", "dept_RID_key1"])) == 1)
예제 #30
0
 def cond(before, after):
     before(len(mmo.find(self.model, ["test", oldname])))
     after(len(mmo.find(self.model, ["test", newname])))