def test_execute_query2(self): m_execute = Mock() expected = [] returns = [None] def foo(*args): r = returns.pop(0) return r m_fetchone = Mock(side_effect=foo) m_cursor = MagicMock() m_cursor.execute = m_execute m_cursor.fetchone = m_fetchone conn = MagicMock() conn.cursor.return_value.__enter__.return_value = m_cursor zipped = zip( dbutil.execute_query_iter(conn, "select * from somewhere"), expected) for x, y in zipped: assert x == y assert conn.cursor.call_count == 1 assert m_cursor.execute.call_count == 1 m_cursor.execute.assert_called_once_with("select * from somewhere", None)
def test_execute_query2(self): m_execute = Mock() expected = [] returns = [None] def foo(*args): r = returns.pop(0) return r m_fetchone = Mock(side_effect=foo) m_cursor = MagicMock() m_cursor.execute = m_execute m_cursor.fetchone = m_fetchone conn = MagicMock() conn.cursor.return_value.__enter__.return_value = m_cursor zipped = zip(dbutil.execute_query_iter(conn, "select * from somewhere"), expected) for x, y in zipped: assert x == y assert conn.cursor.call_count == 1 assert m_cursor.execute.call_count == 1 m_cursor.execute.assert_called_once_with("select * from somewhere", None)
def copy(self): with transaction_context(self.database_class) as connection: sql = """SELECT app_name, next_run, first_run, last_run, last_success, depends_on, error_count, last_error, ongoing FROM cron_job """ columns = ('app_name', 'next_run', 'first_run', 'last_run', 'last_success', 'depends_on', 'error_count', 'last_error', 'ongoing') all = {} for record in execute_query_iter(connection, sql): row = dict(zip(columns, record)) all[row.pop('app_name')] = row return all
def copy(self): with transaction_context(self.database_class) as connection: sql = """SELECT app_name, next_run, first_run, last_run, last_success, depends_on, error_count, last_error, ongoing FROM cron_job """ columns = ( 'app_name', 'next_run', 'first_run', 'last_run', 'last_success', 'depends_on', 'error_count', 'last_error', 'ongoing' ) all = {} for record in execute_query_iter(connection, sql): row = dict(zip(columns, record)) all[row.pop('app_name')] = row return all