def test_get_all_nonschema_objects_and_owners(cursor): dbcontext = context.DatabaseContext(cursor, verbose=True) expected = { SCHEMAS[0]: [ context.ObjectInfo('tables', quoted_object(SCHEMAS[0], TABLES[0]), ROLES[0], False), context.ObjectInfo('sequences', quoted_object(SCHEMAS[0], SEQUENCES[1]), ROLES[0], False), ], SCHEMAS[1]: [ context.ObjectInfo('tables', quoted_object(SCHEMAS[1], TABLES[0]), ROLES[1], False), context.ObjectInfo('sequences', quoted_object(SCHEMAS[1], SEQUENCES[2]), ROLES[1], False), ], } actual = dbcontext.get_all_nonschema_objects_and_owners() # We are deliberately not checking pg_catalog or information_schema here since that's a # lot of work and those should not be touched for k, v in expected.items(): assert set(v) == set(actual[k]) # Make sure that this data is cached for future use cursor.close() actual_again = dbcontext.get_all_nonschema_objects_and_owners() assert actual_again == actual
def test_get_schema_objects_no_entry(): dbcontext = context.DatabaseContext(cursor=DUMMY, verbose=False) dbcontext._cache['get_all_nonschema_objects_and_owners'] = lambda: { 'foo': [ context.ObjectInfo('tables', quoted_object(SCHEMAS[0], TABLES[0]), ROLES[0], False), context.ObjectInfo('sequences', quoted_object(SCHEMAS[0], SEQUENCES[1]), ROLES[0], False), ], } actual = dbcontext.get_schema_objects('key_not_in_response') assert actual == []
def test_get_schema_objects(): schema = 'foo' expected = [ context.ObjectInfo('tables', quoted_object(SCHEMAS[0], TABLES[0]), ROLES[0], False), context.ObjectInfo('sequences', quoted_object(SCHEMAS[0], SEQUENCES[1]), ROLES[0], False), ] dbcontext = context.DatabaseContext(cursor=DUMMY, verbose=False) dbcontext._cache['get_all_nonschema_objects_and_owners'] = lambda: {schema: expected} actual = dbcontext.get_schema_objects(schema) assert actual == expected