Example #1
0
    def drop_woocommerce_database(self):
        database = 'woocommerce_{date:%Y_%m_%d}'.format(date=self.date)
        query = 'DROP DATABASE IF EXISTS {db};'.format(db=database)

        mysql_db = MySqlTarget(
            host='{}:{}'.format(self.host, self.port),
            database=database,
            user=self.user,
            password=self.password,
            table='_removing_whole_database_',
            update_id=self.task_id
        )

        connection = mysql_db.connect()
        cur = connection.cursor()
        cur.execute(query)
        # we don't touch this connection here - we are marking the completeness in run method via PostgresTarget
        # commit and close connection
        connection.commit()
        connection.close()
Example #2
0
    def output(self):
        """
        Returns a MySqlTarget representing the inserted dataset.

        needed to override this to generate a unique update_id based on the run_id
        """
        input_obj = self.input()
        update_id = "{}_paypal".format(
            os.path.basename(os.path.dirname(input_obj[0].fn)))
        return MySqlTarget(host=self.host,
                           database=self.database,
                           user=self.user,
                           password=self.password,
                           table=self.table,
                           update_id=update_id)
Example #3
0
    def output(self):
        """
        Returns a MySqlTarget representing the executed query.

        Normally you don't override this.
        """

        self.database = 'woocommerce_{date:%Y_%m_%d}'.format(date=self.date)

        return MySqlTarget(host=self.host,
                           database=self.database,
                           user=self.user,
                           password=self.password,
                           table=self.table,
                           update_id=self.update_id)
Example #4
0
 def output(self):
     return MySqlTarget()
Example #5
0
username = None
password = None
table_updates = 'table_updates'


def _create_test_database():
    con = mysql.connector.connect(user=username,
                                  password=password,
                                  host=host,
                                  port=port,
                                  autocommit=True)
    con.cursor().execute('CREATE DATABASE IF NOT EXISTS %s' % database)


_create_test_database()
target = MySqlTarget(host, database, username, password, '', 'update_id')


class MySqlTargetTest(unittest.TestCase):
    def test_touch_and_exists(self):
        drop()
        self.assertFalse(target.exists(),
                         'Target should not exist before touching it')
        target.touch()
        self.assertTrue(target.exists(),
                        'Target should exist after touching it')


def drop():
    con = target.connect(autocommit=True)
    con.cursor().execute('DROP TABLE IF EXISTS %s' % table_updates)