def test_ensure_no_missing_objects_schema_expansion_works(mockdbcontext): mockdbcontext.get_all_raw_object_attributes = lambda: { ObjectAttributes('tables', 'schema0', ObjectName('schema0', 'table1'), 'owner1', False), ObjectAttributes('tables', 'schema0', ObjectName('schema0', 'table2'), 'owner3', False), } mockdbcontext.get_all_object_attributes = lambda: { 'tables': { 'schema0': { ObjectName('schema0', 'table1'): { 'owner': 'owner1', 'is_dependent': False }, ObjectName('schema0', 'table2'): { 'owner': 'owner2', 'is_dependent': False }, }, }, } spec_yaml = """ role0: owns: tables: - schema0.* """ unconverted_spec = yaml.load(spec_yaml) spec = spec_inspector.convert_spec_to_objectnames(unconverted_spec) errors = spec_inspector.ensure_no_missing_objects(spec, mockdbcontext, 'tables') assert errors == []
def test_ensure_no_missing_objects_with_personal_schemas(mockdbcontext): mockdbcontext.get_all_raw_object_attributes = lambda: { ObjectAttributes('tables', 'role0', ObjectName('role0', 'table1'), 'role0', False), ObjectAttributes('tables', 'role0', ObjectName('role0', 'table2'), 'role0', False), } mockdbcontext.get_all_object_attributes = lambda: { 'tables': { 'role0': { ObjectName('role0', 'table1'): { 'owner': 'role0', 'is_dependent': False }, ObjectName('role0', 'table2'): { 'owner': 'role0', 'is_dependent': False }, }, }, } spec_yaml = """ role0: has_personal_schema: true """ unconverted_spec = yaml.load(spec_yaml) spec = spec_inspector.convert_spec_to_objectnames(unconverted_spec) errors = spec_inspector.ensure_no_missing_objects(spec, mockdbcontext, 'tables') assert errors == []
def test_ensure_no_missing_objects_missing_in_spec(mockdbcontext): mockdbcontext.get_all_raw_object_attributes = lambda: { ObjectAttributes('tables', 'schema0', ObjectName('schema0', 'table1'), 'owner1', False), ObjectAttributes('tables', 'schema0', ObjectName('schema0', 'table2'), 'owner1', False), ObjectAttributes('tables', 'schema0', ObjectName('schema0', 'table3'), 'owner3', False), ObjectAttributes('tables', 'schema0', ObjectName('schema0', 'table4'), 'owner3', False), # This should be skipped as it is dependent ObjectAttributes('tables', 'schema0', 'schema0."table5"', 'owner3', True), } mockdbcontext.get_all_object_attributes = lambda: { 'tables': { 'schema0': { ObjectName('schema0', 'table1'): {'owner': 'owner1', 'is_dependent': False}, ObjectName('schema0', 'table2'): {'owner': 'owner1', 'is_dependent': False}, ObjectName('schema0', 'table3'): {'owner': 'owner3', 'is_dependent': False}, ObjectName('schema0', 'table4'): {'owner': 'owner3', 'is_dependent': False}, ObjectName('schema0', 'table5'): {'owner': 'owner3', 'is_dependent': True}, }, }, } spec_yaml = """ role0: owns: tables: # Ensure function can handle some objects being quoted and some not - schema0."table1" - schema0.table3 """ unconverted_spec = yaml.safe_load(spec_yaml) spec = spec_inspector.convert_spec_to_objectnames(unconverted_spec) errors = spec_inspector.ensure_no_missing_objects(spec, mockdbcontext, 'tables') expected = spec_inspector.UNOWNED_OBJECTS_MSG.format(objkind='tables', unowned_objects='schema0."table2", schema0."table4"') assert errors == [expected]
def test_ensure_no_missing_objects_missing_in_db(mockdbcontext): mockdbcontext.get_all_raw_object_attributes = lambda: { ObjectAttributes('tables', 'schema0', 'schema0."table1"', 'owner1', False), ObjectAttributes('tables', 'schema0', 'schema0."table3"', 'owner3', False), } mockdbcontext.get_all_object_attributes = lambda: { 'tables': { 'schema0': { 'schema0."table1"': { 'owner': 'owner1', 'is_dependent': False }, 'schema0."table3"': { 'owner': 'owner3', 'is_dependent': False }, }, }, } spec_yaml = """ role0: owns: tables: # Ensure function can handle some objects being quoted and some not - schema0."table1" - schema0."table2" - schema0.table3 - schema0.table4 """ spec = yaml.load(spec_yaml) errors = spec_inspector.ensure_no_missing_objects(spec, mockdbcontext, 'tables') expected = spec_inspector.UNKNOWN_OBJECTS_MSG.format( objkind='tables', unknown_objects='schema0."table2", schema0."table4"') assert errors == [expected]