Example #1
0
    def test_remove_prefix(self):
        """Tests the utils.remove_prefix function"""

        self.assertEqual(
            ['b'],
            utils.remove_prefix('a', ['a.b', 'b.c', 'b', 'b.b', 'c.c', 'c.d']))
        self.assertEqual(
            ['c', 'b'],
            utils.remove_prefix('b', ['a.b', 'b.c', 'b', 'b.b', 'c.c', 'c.d']))
        self.assertEqual(
            ['c', 'd'],
            utils.remove_prefix('c', ['a.b', 'b.c', 'b', 'b.b', 'c.c', 'c.d']))
        self.assertEqual(
            [],
            utils.remove_prefix('d', ['a.b', 'b.c', 'b', 'b.b', 'c.c', 'c.d']))
        self.assertEqual(
            [],
            utils.remove_prefix('', ['a.b', 'b.c', 'b', 'b.b', 'c.c', 'c.d']))
Example #2
0
def create_items(connection, items, include, exclude, substitutes):
    results_pre = []
    results_post = []
    includes = {}

    check_excludes(items, exclude)

    item = None
    for item in items:
        for i in include:
            process_item(item, i, includes)

    if item is not None:
        for fk in includes.keys():
            if fk.a.table.name == item.table.name:
                # forward references, must be in pre
                results_pre += create_items(
                    connection,
                    connection.rows(
                        fk.b.table,
                        QueryFilter(fk.b.name, 'in', includes[fk]),
                        limit=-1,
                        simplify=False),
                    remove_prefix(fk.a.name, include),
                    remove_prefix(fk.a.name, exclude),
                    remove_prefix(fk.a.name, substitutes))
            else:
                # backward reference, must be in post
                results_post += create_items(
                    connection,
                    connection.rows(
                        fk.a.table,
                        QueryFilter(fk.a.name, 'in', includes[fk]),
                        limit=-1,
                        simplify=False),
                    remove_prefix(fk.a.table.name, include),
                    remove_prefix(fk.a.table.name, exclude),
                    remove_prefix(fk.a.table.name, substitutes))

    return results_pre + map(
        lambda i: RowItem(
            to_dto(i),
            prefixes(include),
            prefixes(exclude),
            prefixes(substitutes)),
        items) + results_post
Example #3
0
def create_items(connection, items, include, exclude, substitutes):
    results_pre = []
    results_post = []
    includes = {}

    check_excludes(items, exclude)

    item = None
    for item in items:
        for i in include:
            process_item(item, i, includes)

    if item is not None:
        for fk in includes.keys():
            if fk.a.table.name == item.table.name:
                # forward references, must be in pre
                results_pre += create_items(
                    connection,
                    connection.rows(fk.b.table,
                                    QueryFilter(fk.b.name, 'in', includes[fk]),
                                    limit=-1,
                                    simplify=False),
                    remove_prefix(fk.a.name, include),
                    remove_prefix(fk.a.name, exclude),
                    remove_prefix(fk.a.name, substitutes))
            else:
                # backward reference, must be in post
                results_post += create_items(
                    connection,
                    connection.rows(fk.a.table,
                                    QueryFilter(fk.a.name, 'in', includes[fk]),
                                    limit=-1,
                                    simplify=False),
                    remove_prefix(fk.a.table.name, include),
                    remove_prefix(fk.a.table.name, exclude),
                    remove_prefix(fk.a.table.name, substitutes))

    return results_pre + map(
        lambda i: RowItem(to_dto(i), prefixes(include), prefixes(exclude),
                          prefixes(substitutes)), items) + results_post