pyceo/tests/ceod/db/test_mysql.py

47 lines
1.3 KiB
Python
Raw Normal View History

2021-08-24 22:31:50 -04:00
import pytest
2021-08-25 21:49:51 -04:00
from ceod.db.MySQLService import MySQLService
from ceo_common.errors import DatabaseConnectionError, DatabasePermissionError
from mysql.connector import connect
from mysql.connector.errors import InterfaceError, ProgrammingError
def test_mysql_db_create(cfg):
mysql_srv = MySQLService()
password = mysql_srv.create_db('test_jdoe')
with connect(
host=cfg.get('ceod_database_host'),
user='test_jdoe',
password=password,
) as con:
with con.cursor() as cur:
cur.execute("SHOW DATABASES")
response = cur.fetchall()
assert len(response) == 2
mysql_srv.delete_db('test_jdoe')
# user should be deleted
with pytest.raises(InterfaceError):
con = connect(
host=cfg.get('ceod_database_host'),
user='test_jdoe',
password=password,
)
# except InterfaceError:
# raise DatabaseConnectionError()
# except ProgrammingError:
# raise DatabasePermissionError()
2021-08-24 22:31:50 -04:00
# ask for mysql and postgres with proper postgres configs and no public schema
# tests are stateless
# each test should not require anything before or change anything
# this means you should delete user and databases created after done
# attempt to create database
# password reset
# recreate database (user dropped database)