1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
from __future__ import annotations
from typing import Generator
import pytest
from mysql.connector import connect
from harlequin_mysql.adapter import (
HarlequinMySQLAdapter,
HarlequinMySQLConnection,
)
@pytest.fixture
def connection() -> Generator[HarlequinMySQLConnection, None, None]:
mysqlconn = connect(
host="localhost",
user="root",
password="example",
database="mysql",
autocommit=True,
)
cur = mysqlconn.cursor()
cur.execute("drop database if exists test;")
cur.execute("drop database if exists one;")
cur.execute("drop database if exists two;")
cur.execute("drop database if exists three;")
cur.execute("create database test;")
cur.close()
conn = HarlequinMySQLAdapter(
conn_str=tuple(),
host="localhost",
user="root",
password="example",
database="test",
).connect()
yield conn
cur = mysqlconn.cursor()
cur.execute("drop database if exists test;")
cur.execute("drop database if exists one;")
cur.execute("drop database if exists two;")
cur.execute("drop database if exists three;")
cur.close()
|