def testGetOrderedPartitionList(): """ testGetOrderedPartitionList(): - check that the full list is what we expect - check that each table has expected dependencies """ global me lookup = {} expected = { 'frames': set(['frames', 'reports']), 'extensions': set(['extensions', 'reports']), 'dumps': set(['dumps', 'reports']), } allTables = schema.getOrderedSetupList() for t in allTables: n = t(logger=me.logger).name lookup[t] = n allTables = schema.getOrderedSetupList() for t in allTables: tableName = lookup[t] gotValue = set([lookup[x] for x in schema.getOrderedPartitionList([t])]) if tableName in expected: assert expected[tableName] == gotValue, 'Expected %s, got %s'%(expected[tableName],gotValue) else: assert set([tableName]) == gotValue, 'Expected %s, got %s'%(set([tableName]),gotValue)
def testGetOrderedPartitionList(): """ testGetOrderedPartitionList(): - check that the full list is what we expect - check that each table has expected dependencies """ global me lookup = {} expected = { "frames": set(["frames", "reports"]), "extensions": set(["extensions", "reports"]), "plugins_reports": set(["plugins_reports", "reports"]), "reports_more": set(["reports", "reports_more"]), } allTables = schema.getOrderedSetupList() for t in allTables: n = t(logger=me.logger).name lookup[t] = n allTables = schema.getOrderedSetupList() for t in allTables: tableName = lookup[t] gotValue = set([lookup[x] for x in schema.getOrderedPartitionList([t])]) if tableName in expected: assert expected[tableName] == gotValue, "Expected %s, got %s" % (expected[tableName], gotValue) else: assert set([tableName]) == gotValue, "Expected %s, got %s" % (set([tableName]), gotValue)
def testGetOrderedSetupList(): """ testGetOrderedSetupList() - check that the full list is what we expect - check that each table has expected dependencies - check that (maybe buggy) non-existent table has only self as dependency """ global me lookup = {} allTables = schema.getOrderedSetupList() for t in allTables: try: n = t(logger=me.logger).name lookup[t] = n except: lookup[t] = t gotTableNames = set(lookup.values()) expected = set(me.hardCodedSchemaClasses.keys()) got = set(allTables) assert expected == got,'Expected %s\n got %s\n ex-got=%s\ngot-ex=%s'%(expected,got,expected-got, got-expected) gotDependencies = {} for t in allTables: gotDependencies[t] = set([lookup[x] for x in schema.getOrderedSetupList((t,))]) expectedDependencies = dict([(t,me.hardCodedSchemaClasses[t][1]) for t in me.hardCodedSchemaClasses]) # get better reporting than a simple assert ==, First assert same keys() then same values per key #assert expectedDependencies == gotDependencies, "Expected:\n %s\nGot\n %s"%(expectedDependencies,gotDependencies) exKeys = set(expectedDependencies.keys()) gotKeys = set(gotDependencies.keys()) assert exKeys == gotKeys, "Oops. ex-got = %s\ngot-x = %s"%(exKeys-gotKeys, gotKeys - exKeys) for t in exKeys: assert expectedDependencies[t] == gotDependencies[t], 'for %s\nexpected: %s\ngot %s'%(t,expectedDependencies[t], gotDependencies[t]) assert ['woohoo'] == schema.getOrderedSetupList(['woohoo'])
def testGetOrderedPartitionList(): """ testGetOrderedPartitionList(): - check that the full list is what we expect - check that each table has expected dependencies """ global me lookup = {} expected = { 'frames': set(['frames', 'reports']), 'extensions': set(['extensions', 'reports']), 'plugins_reports': set(['plugins_reports', 'reports']), 'reports_more': set(['reports', 'reports_more']), } allTables = schema.getOrderedSetupList() for t in allTables: n = t(logger=me.logger).name lookup[t] = n allTables = schema.getOrderedSetupList() for t in allTables: tableName = lookup[t] gotValue = set( [lookup[x] for x in schema.getOrderedPartitionList([t])]) if tableName in expected: assert expected[tableName] == gotValue, 'Expected %s, got %s' % ( expected[tableName], gotValue) else: assert set([tableName]) == gotValue, 'Expected %s, got %s' % (set( [tableName]), gotValue)
def checkOneClass(aClass,aType): global me connection = psycopg2.connect(me.dsn) cursor = connection.cursor() table = aClass(logger = me.logger) expectedList = [] expectedTableClasses = schema.getOrderedSetupList([aClass]) for t in expectedTableClasses: expectedList.append(t(logger = me.logger)) try: schema.teardownDatabase(me.config,me.logger) matchingTables = [x for x in socorro_psg.tablesMatchingPattern(table.name+'%',cursor) if not x.endswith('_id_seq')] assert [] == matchingTables ,'For class %s saw %s'%(table.name,matchingTables) # call create before = set(socorro_psg.tablesMatchingPattern('%',cursor)) ignore = [x for x in before if (x.startswith('pg_toast') or x.endswith('id_seq'))] before -= set(ignore) table.create(cursor) connection.commit() after = set(socorro_psg.tablesMatchingPattern('%',cursor)) ignore = [x for x in after if (x.startswith('pg_toast') or x.endswith('id_seq'))] after -= set(ignore) expectedDiff = hardCodedSchemaClasses[aClass][1] assert expectedDiff == after - before, 'for %s: after-before=\n got:%s\nwanted:%s'%(table.name,after-before,expectedDiff) # call drop table.drop(cursor) connection.commit() afterDrop = set(socorro_psg.tablesMatchingPattern('%',cursor)) assert not table.name in afterDrop finally: cursor.execute("DROP TABLE IF EXISTS %s CASCADE"%(','.join([x.name for x in expectedList]))) connection.commit() connection.close()
def checkOneClass(aClass,aType): global me connection = psycopg2.connect(me.dsn) cursor = connection.cursor() table = aClass(logger = me.logger) expectedList = [] expectedTableClasses = schema.getOrderedSetupList([aClass]) for t in expectedTableClasses: expectedList.append(t(logger = me.logger)) try: schema.teardownDatabase(me.config,me.logger) matchingTables = [x for x in socorro_psg.tablesMatchingPattern(table.name+'%',cursor) if not x.endswith('_id_seq')] assert [] == matchingTables ,'For class %s saw %s'%(table.name,matchingTables) # call create before = set(socorro_psg.tablesMatchingPattern('%',cursor)) print 'creating: ', table.name table.create(cursor) connection.commit() after = set(socorro_psg.tablesMatchingPattern('%',cursor)) expected = me.hardCodedSchemaClasses[aClass][1] - set(['release_enum']) assertSameTableDiff(table.name,expected,before,after) # call drop table.drop(cursor) connection.commit() afterDrop = set(socorro_psg.tablesMatchingPattern('%',cursor)) assert not table.name in afterDrop finally: cursor.execute("DROP TABLE IF EXISTS %s CASCADE"%(','.join([x.name for x in expectedList]))) connection.commit() connection.close()
def testGetOrderedSetupList(): """ testGetOrderedSetupList() - check that the full list is what we expect - check that each table has expected dependencies - check that (maybe buggy) non-existent table has only self as dependency """ global me lookup = {} allTables = schema.getOrderedSetupList() for t in allTables: try: n = t(logger=me.logger).name lookup[t] = n except: lookup[t] = t gotTableNames = set(lookup.values()) assert me.expectedTableNames == gotTableNames, "Expected:\n %s\nGot:\n %s"%(me.expectedTableNames,gotTableNames) gotDependencies = {} for t in allTables: gotDependencies[lookup[t]] = set([lookup[x] for x in schema.getOrderedSetupList((t,))]) assert me.expectedTableDependencies == gotDependencies, "Expected:\n %s\nGot\n %s"%(expectedDependencies,gotDependencies) assert ['woohoo'] == schema.getOrderedSetupList(['woohoo'])
def testGetOrderedSetupList(): """ testGetOrderedSetupList() - check that the full list is what we expect - check that each table has expected dependencies - check that (maybe buggy) non-existent table has only self as dependency """ global me lookup = {} allTables = schema.getOrderedSetupList() for t in allTables: try: n = t(logger=me.logger).name lookup[t] = n except: lookup[t] = t gotTableNames = set(lookup.values()) expected = set(me.hardCodedSchemaClasses.keys()) got = set(allTables) assert expected == got, 'Expected %s\n got %s\n ex-got=%s\ngot-ex=%s' % ( expected, got, expected - got, got - expected) gotDependencies = {} for t in allTables: gotDependencies[t] = set( [lookup[x] for x in schema.getOrderedSetupList((t, ))]) expectedDependencies = dict([(t, me.hardCodedSchemaClasses[t][1]) for t in me.hardCodedSchemaClasses]) # get better reporting than a simple assert ==, First assert same keys() then same values per key #assert expectedDependencies == gotDependencies, "Expected:\n %s\nGot\n %s"%(expectedDependencies,gotDependencies) exKeys = set(expectedDependencies.keys()) gotKeys = set(gotDependencies.keys()) assert exKeys == gotKeys, "Oops. ex-got = %s\ngot-x = %s" % ( exKeys - gotKeys, gotKeys - exKeys) for t in exKeys: assert expectedDependencies[t] == gotDependencies[ t], 'for %s\nexpected: %s\ngot %s' % ( t, expectedDependencies[t], gotDependencies[t]) assert ['woohoo'] == schema.getOrderedSetupList(['woohoo'])
def testFillDimsTables_MyData(): global me cursor = me.connection.cursor() dimsTables = [db_schema.ProductDimsTable, db_schema.UrlDimsTable, db_schema.OsDimsTable] toBeCleanedInstances = [x(logger) for x in db_schema.getOrderedSetupList(dimsTables)] data = { 'productdims':[ {'product':'P1','version':'V1','release':'major','branch':'b1'}, {'product':'P2','version':'V2','release':'milestone','branch':'b2'}, {'product':'P1','version':'V3','release':'development','branch':'b3'} ], 'urldims':[ {'domain':'www.woot.com','url':'http://www.woot.com/patootie#bleep'}, {'domain':'google.com','url':'http://google.com/search'} ], 'osdims':[ {'os_name':'AnOS','os_version':'6.6.6'} ], } try: dbtu.fillDimsTables(cursor,data) for table,filler in data.items(): got = [] colList = filler[0].keys() cols = ','.join(colList) cursor.execute("SELECT %s from %s ORDER BY id"%(cols,table)) me.connection.commit() gotData = cursor.fetchall() for d in gotData: got.append(dict(zip(colList,d))) assert data[table] == got, 'expected %s, got %s'%(data[table],got) finally: for inst in toBeCleanedInstances: inst.drop(cursor) me.connection.commit() for inst in toBeCleanedInstances: inst._createSelf(cursor) me.connection.commit()
def checkOneClass(aClass, aType): global me connection = psycopg2.connect(me.dsn) cursor = connection.cursor() table = aClass(logger=me.logger) expectedList = [] expectedTableClasses = schema.getOrderedSetupList([aClass]) for t in expectedTableClasses: expectedList.append(t(logger=me.logger)) try: schema.teardownDatabase(me.config, me.logger) matchingTables = [ x for x in socorro_psg.tablesMatchingPattern(table.name + '%', cursor) if not x.endswith('_id_seq') ] assert [] == matchingTables, 'For class %s saw %s' % (table.name, matchingTables) # call create before = set(socorro_psg.tablesMatchingPattern('%', cursor)) print 'creating: ', table.name table.create(cursor) connection.commit() after = set(socorro_psg.tablesMatchingPattern('%', cursor)) expected = me.hardCodedSchemaClasses[aClass][1] - set(['release_enum']) assertSameTableDiff(table.name, expected, before, after) # call drop table.drop(cursor) connection.commit() afterDrop = set(socorro_psg.tablesMatchingPattern('%', cursor)) assert not table.name in afterDrop finally: cursor.execute("DROP TABLE IF EXISTS %s CASCADE" % (','.join([x.name for x in expectedList]))) connection.commit() connection.close()
def testFillDimsTables_Default(): global me cursor = me.connection.cursor() dimsTables = [db_schema.ProductDimsTable, db_schema.UrlDimsTable, db_schema.OsDimsTable] toBeCleanedInstances = [x(logger) for x in db_schema.getOrderedSetupList(dimsTables)] try: dbtu.fillDimsTables(cursor) for table,filler in dbtu.dimsData.items(): got = [] colList = filler[0].keys() cols = ','.join(colList) cursor.execute("SELECT %s from %s ORDER BY id"%(cols,table)) gotData = cursor.fetchall() for d in gotData: got.append(dict(zip(colList,d))) assert dbtu.dimsData[table] == got me.connection.commit() finally: for inst in toBeCleanedInstances: inst.drop(cursor) me.connection.commit() for inst in toBeCleanedInstances: inst._createSelf(cursor) me.connection.commit()