pyceo/tests/ceod/db/test_mysql.py

61 lines
1.4 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,
)
2021-08-26 15:42:18 -04:00
def test_mysql_passwd_reset():
pass
# test with curl
# test with invalid perms for curl
# test perms
# test with dup user
# test with invalid perms for db
# test with invalid host for db
2021-08-25 21:49:51 -04:00
# 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