コード例 #1
0
ファイル: test_sql_step.py プロジェクト: pombredanne/arbalest
    def test_execute_statements_and_rollback_on_validate(self):
        database = Mock()
        select_with_where = (
            'SELECT * FROM some_table WHERE some_column1 = %s', "some_value")
        select = ('SELECT * FROM some_table')
        step = SqlStep(database, select_with_where, select)

        step.validate()

        database.open.assert_called_once_with()
        self.assert_sql(database, select, select_with_where)
        database.rollback.assert_called_once_with()
コード例 #2
0
ファイル: test_sql_step.py プロジェクト: bpmilne/arbalest
    def test_execute(self):
        self.database.open()
        sql = SqlStep(self.database)
        sql.execute(("INSERT INTO %s VALUES('%s')", TABLE_NAME, 1))
        sql.execute(("INSERT INTO %s VALUES('%s')", TABLE_NAME, 2))
        sql.execute(("INSERT INTO {0} VALUES ('3')".format(TABLE_NAME)))
        self.database.commit()

        self.database.open()
        self.database.execute(
            "SELECT COUNT(*) FROM %s",
            (AsIs(TABLE_NAME),))
        count = int(self.database.cursor.fetchone()[0])

        self.assertEqual(3, count)

        self.database.execute(
            "SELECT * FROM %s",
            (AsIs(TABLE_NAME),))
        values = list(self.database.cursor.fetchall())

        self.assertEqual([('1',), ('2',), ('3',)], values)
コード例 #3
0
ファイル: test_sql_step.py プロジェクト: pombredanne/arbalest
    def test_run(self):
        SqlStep(self.database, ("INSERT INTO %s VALUES('%s')", TABLE_NAME, 1),
                ("INSERT INTO %s VALUES('%s')", TABLE_NAME, 2),
                ("INSERT INTO {0} VALUES ('3')".format(TABLE_NAME))).run()

        self.database.open()
        self.database.execute("SELECT COUNT(*) FROM %s", (AsIs(TABLE_NAME), ))
        count = int(self.database.cursor.fetchone()[0])

        self.assertEqual(3, count)

        self.database.execute("SELECT * FROM %s", (AsIs(TABLE_NAME), ))
        values = list(self.database.cursor.fetchall())

        self.assertEqual([('1', ), ('2', ), ('3', )], values)
コード例 #4
0
ファイル: test_sql_step.py プロジェクト: pombredanne/arbalest
    def test_execute(self):
        database = Mock()
        select_with_where = (
            'SELECT * FROM some_table WHERE some_column1 = %s', "some_value")
        select = ('SELECT * FROM some_table')
        step = SqlStep(database)

        step.execute((select_with_where))
        step.execute(select)

        self.assert_sql(database, select, select_with_where)
コード例 #5
0
    def test_add_sql(self):
        bucket = Mock()
        database = create_autospec(Database)
        expected = SqlStep(database,
                           ("INSERT INTO %s VALUES('%s')", TABLE_NAME, 1),
                           ("INSERT INTO %s VALUES('%s')", TABLE_NAME, 2),
                           ("INSERT INTO {0} VALUES ('3')".format(TABLE_NAME)))

        pipeline = S3BulkCopyPipeline(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY,
                                      bucket, database)

        pipeline.sql(("INSERT INTO %s VALUES('%s')", TABLE_NAME, 1),
                     ("INSERT INTO %s VALUES('%s')", TABLE_NAME, 2),
                     ("INSERT INTO {0} VALUES ('3')".format(TABLE_NAME)))

        step = pipeline.steps()[0]

        self.assertEqual(expected.statements, step.statements)
コード例 #6
0
ファイル: __init__.py プロジェクト: pombredanne/arbalest
 def sql(self, *args):
     self.steps().append(SqlStep(self.database, *args))
     return self