2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-28 11:36:44 +00:00

Add CI tests for MySQL database

This commit is contained in:
Oliver Walters 2020-09-01 21:01:38 +10:00
parent c3c5a86ea5
commit 55c1ea750c
3 changed files with 47 additions and 4 deletions

View File

@ -1,5 +1,9 @@
dist: xenial dist: xenial
services:
- mysql
- postgresql
language: python language: python
python: python:
- 3.6 - 3.6
@ -16,11 +20,14 @@ before_install:
- invoke install - invoke install
- invoke migrate - invoke migrate
- cd InvenTree && python3 manage.py createsuperuser --username InvenTreeAdmin --email admin@inventree.com --noinput && cd .. - 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: script:
- cd InvenTree && python3 manage.py makemigrations && cd .. - cd InvenTree && python3 manage.py makemigrations && cd ..
- python3 ci/check_migration_files.py - python3 ci/check_migration_files.py
- invoke coverage - invoke coverage
- invoke test --database=mysql
- invoke translate - invoke translate
- invoke style - invoke style

View File

@ -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'
}

View File

@ -174,18 +174,36 @@ def style(c):
print("Running PEP style checks...") print("Running PEP style checks...")
c.run('flake8 InvenTree') c.run('flake8 InvenTree')
@task @task(help={'database': "Database framework to use (default=sqlite)"})
def test(c): def test(c, database=None):
""" """
Run unit-tests for InvenTree codebase. 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 # Run sanity check on the django install
manage(c, 'check') manage(c, 'check')
# Run coverage tests # Run coverage tests
manage(c, 'test {apps}'.format( manage(c, 'test {apps} --settings={sett}'.format(
apps=' '.join(apps()) apps=' '.join(apps()),
sett=allowed[database]
)) ))
@task @task