testing
continuous-integration/drone/pr Build is failing
Details
continuous-integration/drone/pr Build is failing
Details
This commit is contained in:
parent
5893e561cd
commit
dc4d60fba2
|
@ -10,7 +10,7 @@ def http_request(method: str, path: str, **kwargs) -> requests.Response:
|
||||||
client = component.getUtility(IHTTPClient)
|
client = component.getUtility(IHTTPClient)
|
||||||
cfg = component.getUtility(IConfig)
|
cfg = component.getUtility(IConfig)
|
||||||
if path.startswith('/api/db'):
|
if path.startswith('/api/db'):
|
||||||
host = cfg.get('ceod_db_host')
|
host = cfg.get('ceod_database_host')
|
||||||
need_cred = False
|
need_cred = False
|
||||||
else:
|
else:
|
||||||
host = cfg.get('ceod_admin_host')
|
host = cfg.get('ceod_admin_host')
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
from zope.interface import Attribute, Interface
|
from zope.interface import Attribute, Interface
|
||||||
from .IUser import IUser
|
|
||||||
|
|
||||||
|
|
||||||
class IDatabaseService(Interface):
|
class IDatabaseService(Interface):
|
||||||
|
|
|
@ -8,3 +8,4 @@ from .IUWLDAPService import IUWLDAPService
|
||||||
from .IMailService import IMailService
|
from .IMailService import IMailService
|
||||||
from .IMailmanService import IMailmanService
|
from .IMailmanService import IMailmanService
|
||||||
from .IHTTPClient import IHTTPClient
|
from .IHTTPClient import IHTTPClient
|
||||||
|
from .IDatabaseService import IDatabaseService
|
||||||
|
|
|
@ -38,6 +38,10 @@ def create_app(flask_config={}):
|
||||||
from ceod.api import mailman
|
from ceod.api import mailman
|
||||||
app.register_blueprint(mailman.bp, url_prefix='/api/mailman')
|
app.register_blueprint(mailman.bp, url_prefix='/api/mailman')
|
||||||
|
|
||||||
|
if hostname == cfg.get('ceod_database_host'):
|
||||||
|
from ceod.api import database
|
||||||
|
app.register_blueprint(database.bp, url_prefix='/api/db')
|
||||||
|
|
||||||
from ceod.api import groups
|
from ceod.api import groups
|
||||||
app.register_blueprint(groups.bp, url_prefix='/api/groups')
|
app.register_blueprint(groups.bp, url_prefix='/api/groups')
|
||||||
|
|
||||||
|
@ -109,9 +113,11 @@ def register_services(app):
|
||||||
component.provideUtility(uwldap_srv, IUWLDAPService)
|
component.provideUtility(uwldap_srv, IUWLDAPService)
|
||||||
|
|
||||||
# MySQLService
|
# MySQLService
|
||||||
mysql_srv = MySQLService()
|
if hostname == cfg.get('ceod_database_host'):
|
||||||
component.provideUtility(mysql_srv, IDatabaseService, 'mysql')
|
mysql_srv = MySQLService()
|
||||||
|
component.provideUtility(mysql_srv, IDatabaseService, 'mysql')
|
||||||
|
|
||||||
# PostgreSQLService
|
# PostgreSQLService
|
||||||
psql_srv = PostgreSQLService()
|
if hostname == cfg.get('ceod_database_host'):
|
||||||
component.provideUtility(psql_srv, IDatabaseService, 'postgresql')
|
psql_srv = PostgreSQLService()
|
||||||
|
component.provideUtility(psql_srv, IDatabaseService, 'postgresql')
|
||||||
|
|
|
@ -55,13 +55,6 @@ def create_mysql_db(auth_user: str, username: str):
|
||||||
return create_db_from_type('mysql', username)
|
return create_db_from_type('mysql', username)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/mysql/<username>', methods=['DELETE'])
|
|
||||||
@authz_restrict_to_syscom
|
|
||||||
@development_only
|
|
||||||
def delete_mysql_db(username: str):
|
|
||||||
delete_db_from_type('mysql', username)
|
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/postgresql/<username>', methods=['POST'])
|
@bp.route('/postgresql/<username>', methods=['POST'])
|
||||||
@requires_authentication_no_realm
|
@requires_authentication_no_realm
|
||||||
def create_postgresql_db(auth_user: str, username: str):
|
def create_postgresql_db(auth_user: str, username: str):
|
||||||
|
@ -70,6 +63,13 @@ def create_postgresql_db(auth_user: str, username: str):
|
||||||
return create_db_from_type('postgresql', username)
|
return create_db_from_type('postgresql', username)
|
||||||
|
|
||||||
|
|
||||||
|
@bp.route('/mysql/<username>', methods=['DELETE'])
|
||||||
|
@authz_restrict_to_syscom
|
||||||
|
@development_only
|
||||||
|
def delete_mysql_db(username: str):
|
||||||
|
delete_db_from_type('mysql', username)
|
||||||
|
|
||||||
|
|
||||||
@bp.route('/postgresql/<username>', methods=['DELETE'])
|
@bp.route('/postgresql/<username>', methods=['DELETE'])
|
||||||
@authz_restrict_to_syscom
|
@authz_restrict_to_syscom
|
||||||
@development_only
|
@development_only
|
||||||
|
|
|
@ -1,5 +1,40 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
# ask for mysql and postgres with proper postgres configs and no public schema
|
# ask for mysql and postgres with proper postgres configs and no public schema
|
||||||
|
|
||||||
# tests are stateless
|
# tests are stateless
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
import pytest
|
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ admin_host = phosphoric-acid
|
||||||
# this is the host with NFS no_root_squash
|
# this is the host with NFS no_root_squash
|
||||||
fs_root_host = phosphoric-acid
|
fs_root_host = phosphoric-acid
|
||||||
mailman_host = mail
|
mailman_host = mail
|
||||||
|
database_host = coffee
|
||||||
krb5_cache_dir = /run/ceod/krb5_cache
|
krb5_cache_dir = /run/ceod/krb5_cache
|
||||||
use_https = false
|
use_https = false
|
||||||
port = 9987
|
port = 9987
|
||||||
|
|
|
@ -7,6 +7,7 @@ uw_domain = uwaterloo.internal
|
||||||
admin_host = phosphoric-acid
|
admin_host = phosphoric-acid
|
||||||
fs_root_host = phosphoric-acid
|
fs_root_host = phosphoric-acid
|
||||||
mailman_host = phosphoric-acid
|
mailman_host = phosphoric-acid
|
||||||
|
database_host = phosphoric-acid
|
||||||
krb5_cache_dir = /tmp/ceod_test_krb5_cache
|
krb5_cache_dir = /tmp/ceod_test_krb5_cache
|
||||||
use_https = false
|
use_https = false
|
||||||
port = 9987
|
port = 9987
|
||||||
|
|
Loading…
Reference in New Issue