def test_nonschemaanalyzer_expand_schema_objects(mockdbcontext): mockdbcontext.get_all_object_attributes = lambda: { 'tables': { SCHEMAS[0]: { quoted_object(SCHEMAS[0], TABLES[0]): { 'owner': DUMMY, 'is_dependent': False }, quoted_object(SCHEMAS[0], TABLES[1]): { 'owner': DUMMY, 'is_dependent': False }, quoted_object(SCHEMAS[0], TABLES[2]): { 'owner': DUMMY, 'is_dependent': True }, }, }, } nsa = own.NonschemaAnalyzer(rolename=ROLES[0], objname=DUMMY, objkind='tables', dbcontext=mockdbcontext) actual = nsa.expand_schema_objects(SCHEMAS[0]) expected = [ quoted_object(SCHEMAS[0], TABLES[0]), quoted_object(SCHEMAS[0], TABLES[1]) ] assert set(actual) == set(expected)
def test_nonschemaanalyzer_analyze_no_changed_needed(mockdbcontext): objname = quoted_object(SCHEMAS[0], TABLES[0]) mockdbcontext.get_all_object_attributes = lambda: { 'tables': { SCHEMAS[0]: { objname: { 'owner': ROLES[0], 'is_dependent': False }, }, }, } nsa = own.NonschemaAnalyzer(rolename=ROLES[0], objname=objname, objkind='tables', dbcontext=mockdbcontext) actual = nsa.analyze() assert actual == []
def test_nonschemaanalyzer_analyze_with_schema_expansion(mockdbcontext): mockdbcontext.get_all_object_attributes = lambda: { 'sequences': { SCHEMAS[0]: { ObjectName(SCHEMAS[0], SEQUENCES[0]): { 'owner': ROLES[1], 'is_dependent': False }, ObjectName(SCHEMAS[0], SEQUENCES[1]): { 'owner': ROLES[2], 'is_dependent': False }, # This will be skipped as the owner is correct ObjectName(SCHEMAS[0], SEQUENCES[2]): { 'owner': ROLES[0], 'is_dependent': False }, # This will be skipped as it is dependent ObjectName(SCHEMAS[0], SEQUENCES[3]): { 'owner': ROLES[1], 'is_dependent': True }, }, }, } nsa = own.NonschemaAnalyzer(rolename=ROLES[0], objname=ObjectName(SCHEMAS[0], '*'), objkind='sequences', dbcontext=mockdbcontext) actual = nsa.analyze() expected = [ own.Q_SET_OBJECT_OWNER.format( 'SEQUENCE', ObjectName(SCHEMAS[0], SEQUENCES[0]).qualified_name, ROLES[0], ROLES[1]), own.Q_SET_OBJECT_OWNER.format( 'SEQUENCE', ObjectName(SCHEMAS[0], SEQUENCES[1]).qualified_name, ROLES[0], ROLES[2]), ] assert set(actual) == set(expected)
def test_nonschemaanalyzer_analyze_without_schema_expansion(mockdbcontext): objname = quoted_object(SCHEMAS[0], TABLES[0]) mockdbcontext.get_all_object_attributes = lambda: { 'tables': { SCHEMAS[0]: { objname: { 'owner': ROLES[1], 'is_dependent': False }, }, }, } nsa = own.NonschemaAnalyzer(rolename=ROLES[0], objname=objname, objkind='tables', dbcontext=mockdbcontext) actual = nsa.analyze() expected = [ own.Q_SET_OBJECT_OWNER.format('TABLE', objname, ROLES[0], ROLES[1]) ] assert actual == expected