Commit 548d1547 authored by Adrià Labay's avatar Adrià Labay

run mysql as gitlab service

parent 8c034ff2
Pipeline #33322 passed with stages
in 7 minutes and 14 seconds
......@@ -54,10 +54,14 @@ lint_py:
test_py:
<<: *python_packages
stage: test
services:
- mysql:5.7
variables:
MYSQL_DATABASE: "course_dev"
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
script:
- yarn mysql-create
- yarn test:mysql-start && yarn test:py:cov
- yarn mysql-stop
- echo "SELECT 'OK';" | mysql -uroot -h mysql "course_dev"
- yarn test:py:cov
artifacts:
paths:
- cov.html/
......
......@@ -8,9 +8,6 @@
# the 'revision' command, regardless of autogenerate
# revision_environment = false
# path to migration scripts
script_location = .
# Logging configuration
[loggers]
......
......@@ -15,7 +15,7 @@
"lint:js": "standard --verbose | snazzy",
"test:js": "jest",
"lint:py": "flake8",
"test:py": "python3 -m pytest -v -W error::RuntimeWarning",
"test:py": "yarn test:mysql-start && python3 -m pytest -v -W error::RuntimeWarning; yarn mysql-stop",
"start": "ZESJE_SETTINGS=$(pwd)/zesje_dev_cfg.py python3 zesje",
"analyze": "webpack --config webpack.prod.js --profile --json > stats.json; webpack-bundle-analyzer stats.json zesje/static",
"migrate": "mysql -uroot <$(pwd)/myinit.sql; FLASK_APP=zesje.wsgi:app flask db upgrade",
......@@ -23,9 +23,9 @@
"prepare-migration": "ZESJE_SETTINGS=$(pwd)/zesje_dev_cfg.py FLASK_APP=zesje.wsgi:app flask db migrate",
"test:py:cov": "python3 -m pytest -v -W error::RuntimeWarning --cov=zesje --cov-report=xml:cov.xml --cov-report=html:cov.html --cov-report=term tests/",
"migrate-down": "FLASK_APP=zesje.wsgi:app flask db downgrade",
"mysql-create": "if [ ! -d \"$(pwd)/data-dev/mysql\" ]; then mysqld --defaults-file=my.cnf --initialize-insecure; else echo \"MySql already exists. Skipping.\"; fi",
"mysql-start": "mysqld_safe --defaults-file=my.cnf --gdb --init-file=/app/myinit.sql &",
"dev:mysql-start": "mysqld_safe --defaults-file=my.cnf --gdb --init-file=$(pwd)/myinit.sql",
"mysql-create": "if [ ! -d \"$(pwd)/data-dev/mysql\" ]; then mysqld --defaults-file=$(pwd)/my.cnf --initialize-insecure; else echo \"MySql already exists. Skipping.\"; fi",
"mysql-start": "mysqld_safe --defaults-file=$(pwd)/my.cnf --gdb --init-file=$(pwd)/myinit.sql &",
"dev:mysql-start": "mysqld_safe --defaults-file=$(pwd)/my.cnf --gdb --init-file=$(pwd)/myinit.sql",
"test:mysql-start": "mysqld_safe --defaults-file=my.cnf --gdb --init-file=$(pwd)/myinit_test.sql &",
"mysql-stop": "mysqladmin -uroot shutdown"
},
......
......@@ -5,6 +5,7 @@ import pytest
from flask import Flask
from pathlib import Path
import sys
import MySQLdb
sys.path.insert(0, str(Path.cwd()))
......@@ -18,6 +19,16 @@ def datadir():
return os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data')
@pytest.fixture(scope="module")
def db_host():
try:
MySQLdb.connect('localhost', "root", "", "course_dev")
except Exception:
return 'mysql'
return 'localhost'
# Returns a Flask app with only the config initialized
@pytest.fixture(scope="module")
def config_app():
......@@ -30,12 +41,12 @@ def config_app():
# Return a mock DB which can be used in the testing enviroment
# Module scope ensures it is ran only once
@pytest.fixture(scope="module")
def db_app(config_app):
def db_app(config_app, db_host):
app = config_app
db.init_app(app)
app.config.update(SQLALCHEMY_DATABASE_URI=f'mysql://root:@localhost/course_dev')
app.config.update(SQLALCHEMY_DATABASE_URI=f'mysql://root:@{db_host}/course_dev')
with TemporaryDirectory() as temp_dir:
app.config.update(
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment