From 55c1ea750c915409c23b3d39a2ff6cc1c802b1c3 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Tue, 1 Sep 2020 21:01:38 +1000 Subject: [PATCH] Add CI tests for MySQL database --- .travis.yml | 7 +++++++ InvenTree/InvenTree/ci_mysql.py | 18 ++++++++++++++++++ tasks.py | 26 ++++++++++++++++++++++---- 3 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 InvenTree/InvenTree/ci_mysql.py diff --git a/.travis.yml b/.travis.yml index d3ac736a7c..06e73958c0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,5 +1,9 @@ dist: xenial +services: + - mysql + - postgresql + language: python python: - 3.6 @@ -16,11 +20,14 @@ before_install: - invoke install - invoke migrate - cd InvenTree && python3 manage.py createsuperuser --username InvenTreeAdmin --email admin@inventree.com --noinput && cd .. + - psql -c 'create database inventree_test_db;' -U postgres + - mysql -e `CREATE DATABSE inventree_test_db;' script: - cd InvenTree && python3 manage.py makemigrations && cd .. - python3 ci/check_migration_files.py - invoke coverage + - invoke test --database=mysql - invoke translate - invoke style diff --git a/InvenTree/InvenTree/ci_mysql.py b/InvenTree/InvenTree/ci_mysql.py new file mode 100644 index 0000000000..aaaae2ddb0 --- /dev/null +++ b/InvenTree/InvenTree/ci_mysql.py @@ -0,0 +1,18 @@ +""" +Configuration file for running tests against a MySQL database. +""" + +from InvenTree.settings import * + +# Override the 'test' database +if 'test' in sys.argv: + eprint('InvenTree: Running tests - Using MySQL test database') + + DATABASES['default'] = { + # Ensure mysql backend is being used + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'inventree_test_db', + 'USER': 'travis', + 'PASSWORD': '', + 'HOST': '127.0.0.1' + } diff --git a/tasks.py b/tasks.py index b7bda95033..a5e7f61430 100644 --- a/tasks.py +++ b/tasks.py @@ -174,18 +174,36 @@ def style(c): print("Running PEP style checks...") c.run('flake8 InvenTree') -@task -def test(c): +@task(help={'database': "Database framework to use (default=sqlite)"}) +def test(c, database=None): """ Run unit-tests for InvenTree codebase. """ + if database is None: + database = 'sqlite' + + database = database.lower() + + allowed = { + 'sqlite': 'InvenTree.settings', + 'postgresql': 'InvenTree.ci_postgresql', + 'mysql': 'InvenTree.ci_mysql', + } + + if database not in allowed.keys(): + print("Database framework not supported for testing:") + print("Choose from: '{a}'".format(a=allowed)) + + return False + # Run sanity check on the django install manage(c, 'check') # Run coverage tests - manage(c, 'test {apps}'.format( - apps=' '.join(apps()) + manage(c, 'test {apps} --settings={sett}'.format( + apps=' '.join(apps()), + sett=allowed[database] )) @task