From 6b6e16d07374cb43481da783e5ffc70d7ed45331 Mon Sep 17 00:00:00 2001 From: Gael Pasgrimaud Date: Mon, 7 Mar 2016 14:54:52 +0100 Subject: [PATCH 1/2] run tests with mysql --- .travis.yml | 19 +++++++++++--- test_project/test_project/settings.py | 38 +++++++++++++++++++-------- tests.py | 10 ++++--- 3 files changed, 48 insertions(+), 19 deletions(-) diff --git a/.travis.yml b/.travis.yml index c2636b754..d10fde17e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,22 +3,33 @@ language: python python: - "2.7" +env: + - DB="POSTGRESQL" + - DB="MYSQL" + +services: + - mysql + - postgres + before_install: - pip install codecov - + install: - python setup.py -q develop - - pip install -q psycopg2 + - pip install -q psycopg2 mysqlclient - pip install -q -r test-requirements.txt before_script: - psql -c 'create database modoboa_test;' -U postgres + - mysql -e "create database IF NOT EXISTS modoboa_test;" -uroot + - mysql -e "CREATE USER 'modoboa'@'localhost' IDENTIFIED BY 'modoboa'" -uroot; + - mysql -e "GRANT ALL PRIVILEGES ON * . * TO 'modoboa'@'localhost';" -uroot; -script: +script: - python ./tests.py - cd test_project - coverage run --source ../modoboa manage.py test modoboa.core modoboa.lib modoboa.admin.tests modoboa.limits modoboa.relaydomains after_success: - codecov - + diff --git a/test_project/test_project/settings.py b/test_project/test_project/settings.py index 9e938d703..8df3f5dd7 100644 --- a/test_project/test_project/settings.py +++ b/test_project/test_project/settings.py @@ -94,20 +94,36 @@ WSGI_APPLICATION = 'test_project.wsgi.application' # Database # https://docs.djangoproject.com/en/1.6/ref/settings/#databases -DATABASES = { +if os.environ.get('DB') == 'MYSQL': + DATABASES = { - 'default': { - 'ENGINE': 'django.db.backends.postgresql_psycopg2', - 'NAME': 'modoboa_test', - 'USER': 'postgres', - 'PASSWORD': '', - 'HOST': 'localhost', - 'PORT': '', - 'ATOMIC_REQUESTS': True, + 'default': { + 'ENGINE': 'django.db.backends.mysql', + 'NAME': 'modoboa_test', + 'USER': 'modoboa', + 'PASSWORD': 'modoboa', + 'HOST': 'localhost', + 'PORT': '', + 'ATOMIC_REQUESTS': True, - }, + }, -} + } +else: + DATABASES = { + + 'default': { + 'ENGINE': 'django.db.backends.postgresql_psycopg2', + 'NAME': 'modoboa_test', + 'USER': 'postgres', + 'PASSWORD': '', + 'HOST': 'localhost', + 'PORT': '', + 'ATOMIC_REQUESTS': True, + + }, + + } # Internationalization # https://docs.djangoproject.com/en/1.6/topics/i18n/ diff --git a/tests.py b/tests.py index 7cc4ad086..21fc99b58 100644 --- a/tests.py +++ b/tests.py @@ -1,17 +1,19 @@ # coding: utf-8 - +import os import tempfile import unittest from modoboa.lib.sysutils import exec_cmd +DB = os.environ.get("DB", "postgres") + class DeployTest(unittest.TestCase): - dbtype = "postgres" + dbtype = DB.lower() dbhost = "localhost" projname = "modoboa_test" - dbuser = "postgres" - dbpassword = "" + dbuser = DB == "MYSQL" and "modoboa" or "postgres" + dbpassword = DB == "MYSQL" and "modoboa" or "" def setUp(self): self.workdir = tempfile.mkdtemp() From 833363cba6572cc651a140280c86f1bc76a37e1f Mon Sep 17 00:00:00 2001 From: Gael Pasgrimaud Date: Mon, 7 Mar 2016 15:09:50 +0100 Subject: [PATCH 2/2] do not use an hardcoded name --- modoboa/admin/tests/api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/modoboa/admin/tests/api.py b/modoboa/admin/tests/api.py index d6aa4c9b4..5d7303d31 100644 --- a/modoboa/admin/tests/api.py +++ b/modoboa/admin/tests/api.py @@ -29,11 +29,12 @@ class APITestCase(ModoAPITestCase): response = self.client.get(url) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 2) + domain = response.data[0] url = reverse( - "external_api:domain-detail", args=[response.data[0]["pk"]]) + "external_api:domain-detail", args=[domain["pk"]]) response = self.client.get(url) self.assertEqual(response.status_code, 200) - self.assertEqual(response.data["name"], "test2.com") + self.assertEqual(response.data["name"], domain["name"]) def test_create_domain(self): """Check domain creation."""