testing

pull/10/head
Andrew Wang 1 year ago
parent 5893e561cd
commit dc4d60fba2
  1. 2
      ceo/utils.py
  2. 1
      ceo_common/interfaces/IDatabaseService.py
  3. 1
      ceo_common/interfaces/__init__.py
  4. 14
      ceod/api/app_factory.py
  5. 14
      ceod/api/database.py
  6. 2
      ceod/db/__init__.py
  7. 35
      tests/ceod/db/test_mysql.py
  8. 1
      tests/ceod/db/test_postgres.py
  9. 1
      tests/ceod_dev.ini
  10. 1
      tests/ceod_test_local.ini

@ -10,7 +10,7 @@ def http_request(method: str, path: str, **kwargs) -> requests.Response:
client = component.getUtility(IHTTPClient)
cfg = component.getUtility(IConfig)
if path.startswith('/api/db'):
host = cfg.get('ceod_db_host')
host = cfg.get('ceod_database_host')
need_cred = False
else:
host = cfg.get('ceod_admin_host')

@ -1,5 +1,4 @@
from zope.interface import Attribute, Interface
from .IUser import IUser
class IDatabaseService(Interface):

@ -8,3 +8,4 @@ from .IUWLDAPService import IUWLDAPService
from .IMailService import IMailService
from .IMailmanService import IMailmanService
from .IHTTPClient import IHTTPClient
from .IDatabaseService import IDatabaseService

@ -38,6 +38,10 @@ def create_app(flask_config={}):
from ceod.api import 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
app.register_blueprint(groups.bp, url_prefix='/api/groups')
@ -109,9 +113,11 @@ def register_services(app):
component.provideUtility(uwldap_srv, IUWLDAPService)
# MySQLService
mysql_srv = MySQLService()
component.provideUtility(mysql_srv, IDatabaseService, 'mysql')
if hostname == cfg.get('ceod_database_host'):
mysql_srv = MySQLService()
component.provideUtility(mysql_srv, IDatabaseService, 'mysql')
# PostgreSQLService
psql_srv = PostgreSQLService()
component.provideUtility(psql_srv, IDatabaseService, 'postgresql')
if hostname == cfg.get('ceod_database_host'):
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)
@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'])
@requires_authentication_no_realm
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)
@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'])
@authz_restrict_to_syscom
@development_only

@ -1,2 +1,2 @@
from .MySQLService import MySQLService
from .PostgreSQLService import PostgreSQLService
from .PostgreSQLService import PostgreSQLService

@ -1,5 +1,40 @@
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
# tests are stateless

@ -7,6 +7,7 @@ admin_host = phosphoric-acid
# this is the host with NFS no_root_squash
fs_root_host = phosphoric-acid
mailman_host = mail
database_host = coffee
krb5_cache_dir = /run/ceod/krb5_cache
use_https = false
port = 9987

@ -7,6 +7,7 @@ uw_domain = uwaterloo.internal
admin_host = phosphoric-acid
fs_root_host = phosphoric-acid
mailman_host = phosphoric-acid
database_host = phosphoric-acid
krb5_cache_dir = /tmp/ceod_test_krb5_cache
use_https = false
port = 9987

Loading…
Cancel
Save