Beispiel #1
0
 def test_insertion(self):
     mydb = connection.connect()
     mycursor = mydb.cursor()
     schema_prod = devconfig.Dev("dev").connect_db()
     schema_test = devconfig.Dev("test").connect_db()
     mycursor.execute(
         "select column_name from information_schema.columns where table_name='"
         + self.tables + "' limit 1")
     data = mycursor.fetchone()
     data = str(data).split(",")[0].replace("(", "").replace("'", "")
     mycursor.execute(
         "select column_name from information_schema.columns where table_name='test_"
         + self.tables + "'limit 1")
     data1 = mycursor.fetchone()
     data1 = str(data1).split(",")[0].replace("(", "").replace("'", "")
     mycursor.execute("select * from " + schema_test[3] + ".test_" +
                      self.tables + " where " + data1 + " not in (select " +
                      data + " from " + schema_prod[3] + "." + self.tables +
                      ")")
     comp = mycursor.fetchall()
     mycursor.execute("select * from " + schema_prod[3] + "." +
                      self.tables + " where " + data + " not in (select " +
                      data1 + " from " + schema_test[3] + ".test_" +
                      self.tables + ")")
     comp1 = mycursor.fetchall()
     self.assertEqual(comp == [], True, msg=self.tables + " " + str(comp))
     self.assertEqual(comp1 == [], True, msg=self.tables + " " + str(comp1))
Beispiel #2
0
 def test(self):
     mydb = connection.connect()
     mycursor = mydb.cursor()
     schema_prod = devconfig.Dev("dev").connect_db()
     schema_test = devconfig.Dev("test").connect_db()
     del sys.path[:]
     sys.path.append(
         os.path.join(os.path.dirname(os.path.dirname(__file__)), 'files',
                      'ddl', table + '.sql'))
     for file_path in sys.path:
         mycursor.execute("desc " + schema_prod[3] + "." + table)
         data = mycursor.fetchall()
         b = []
         for i in data:
             a = list(i)
             b.append((str(a[0]) + " " + str(a[1])).upper().replace(
                 "B'", "").replace("'", ""))
         #print(b)
     for file_path in sys.path:
         mycursor.execute("desc " + schema_test[3] + "." + table)
         data = mycursor.fetchall()
         c = []
         for i in data:
             a = list(i)
             c.append((str(a[0]) + " " + str(a[1])).upper().replace(
                 "B'", "").replace("'", ""))
         #print(c)
         self.assertEqual(
             (collections.Counter(b) == collections.Counter(c)),
             True,
             msg=table + " " + str(set(c) - set(b)))
Beispiel #3
0
 def test(self):
     mydb = connection.connect()
     mycursor = mydb.cursor()
     schema_prod = devconfig.Dev("dev").connect_db()
     schema_test = devconfig.Dev("test").connect_db()
     mycursor.execute(
         "select distinct column_name from information_schema.columns where table_schema = 'student' and table_name='"
         + table + "'")
     data = mycursor.fetchall()
     data_cp = []
     for i in data:
         if str(i).count("START_DATE") < 1:
             if str(i).count("END_DATE") < 1:
                 a = list(i)
                 data_cp.append("".join(a))
     # for i in data:
     #     a = list(i)
     #     data_cp.append("".join(a))
     #data_cp = data_cp[:len(data_cp) - 3]
     data_cp = ",".join(data_cp)
     mycursor.execute(
         "select distinct column_name from information_schema.columns where table_name='test_"
         + table + "'")
     data1 = mycursor.fetchall()
     # print(data1)
     data1_cp = []
     for i in data1:
         if str(i).count("START_DATE") < 1:
             if str(i).count("END_DATE") < 1:
                 a = list(i)
                 data1_cp.append("".join(a))
     # data1_cp = data1_cp[:len(data1_cp) - 3]
     data1_cp = ",".join(data1_cp)
     if "dimension" in table:
         temp = data_cp.split(",")
         temp1 = data1_cp.split(",")
         mycursor.execute("select " + data_cp + " from " + schema_test[3] +
                          ".test_" + table)
         comp = mycursor.fetchall()
         mycursor.execute("select " + data1_cp + " from " + schema_prod[3] +
                          "." + table)
         comp1 = mycursor.fetchall()
     else:
         mycursor.execute("select " + data1_cp + " from " + schema_test[3] +
                          ".test_" + table)
         comp = mycursor.fetchall()
         mycursor.execute("select " + data_cp + " from " + schema_prod[3] +
                          "." + table)
         comp1 = mycursor.fetchall()
     # for i in comp1:
     #     print(i)
     # for i in comp:
     #     print(i)
     diff = list(set(comp1) - set(comp))
     diff1 = list(set(comp) - set(comp1))
     self.assertEqual(diff == diff1,
                      True,
                      msg=table + " " + str(set(diff) - set(diff1)))
Beispiel #4
0
def connect():
    obj = devconfig.Dev("dev")
    host, user, pwd, db = obj.connect_db()
    mydb = mysql.connector.connect(host=host,
                                   user=user,
                                   password=pwd,
                                   database=db)
    #print(host, user, pwd, db)
    return mydb