Skip to content

Commit

Permalink
Test config to run on multiple databases, WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
maciej-jaworski committed Apr 27, 2015
1 parent 9358a49 commit ff04f21
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 23 deletions.
5 changes: 4 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ python:
env:
- DJANGO=1.7.7
- DJANGO=1.8
addons:
- postgresql: "9.3"
install:
- pip install -q Django==$DJANGO --use-mirrors
- pip install coveralls
Expand All @@ -14,4 +16,5 @@ script:
after_success:
- coveralls
before_script:
- mysql -e 'create database djangocron;'
- mysql -e 'create database travis_test;'
- psql -c 'create database travis_test;' -U postgres
2 changes: 1 addition & 1 deletion django_cron/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class TestCase(unittest.TestCase):
error_cron = 'test_crons.TestErrorCronJob'
five_mins_cron = 'test_crons.Test5minsCronJob'
run_at_times_cron = 'test_crons.TestRunAtTimesCronJob'
wait_3sec_cron = 'test_crons.Wiat3secCronJob'
wait_3sec_cron = 'test_crons.Wait3secCronJob'
test_failed_runs_notification_cron = 'django_cron.cron.FailedRunsNotificationCronJob'

def setUp(self):
Expand Down
29 changes: 20 additions & 9 deletions runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,30 @@
import os
import sys

os.environ['DJANGO_SETTINGS_MODULE'] = 'test_settings'

test_dir = os.path.dirname(__file__)
sys.path.insert(0, test_dir)

import django
from django.test.utils import get_runner
from django.conf import settings

SETTING_MODULES = (
'settings_sqllite',
'settings_postgres',
'settings_mysql',
)


def runtests():
TestRunner = get_runner(settings)
test_runner = TestRunner(verbosity=1, interactive=True)
if hasattr(django, 'setup'):
django.setup()
failures = test_runner.run_tests(['django_cron'])
failures = 0
for module in SETTING_MODULES:
os.environ['DJANGO_SETTINGS_MODULE'] = module
import django
from django.test.utils import get_runner
from django.conf import settings

TestRunner = get_runner(settings)
test_runner = TestRunner(verbosity=1, interactive=True)
if hasattr(django, 'setup'):
django.setup()
failures += test_runner.run_tests(['django_cron'])

sys.exit(bool(failures))
12 changes: 1 addition & 11 deletions test_settings.py → settings_base.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'USER': 'travis',
'NAME': 'djangocron',
'TEST_NAME': 'djangocron_test',
}
}

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
Expand All @@ -29,7 +19,7 @@
'test_crons.TestErrorCronJob',
'test_crons.Test5minsCronJob',
'test_crons.TestRunAtTimesCronJob',
'test_crons.Wiat3secCronJob',
'test_crons.Wait3secCronJob',
'django_cron.cron.FailedRunsNotificationCronJob'
]

Expand Down
11 changes: 11 additions & 0 deletions settings_mysql.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from settings_base import *

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'USER': 'travis',
'PASSWORD': '',
'NAME': 'travis',
'TEST_NAME': 'travis_test',
}
}
11 changes: 11 additions & 0 deletions settings_postgres.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from settings_base import *

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'USER': 'postgres',
'PASSWORD': '',
'NAME': 'travis',
'TEST_NAME': 'travis_test',
}
}
10 changes: 10 additions & 0 deletions settings_sqllite.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from settings_base import *

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'USER': 'travis',
'NAME': 'djangocron',
'TEST_NAME': 'djangocron_test',
}
}
2 changes: 1 addition & 1 deletion test_crons.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def do(self):
pass


class Wiat3secCronJob(CronJobBase):
class Wait3secCronJob(CronJobBase):
code = 'test_wait_3_seconds'
schedule = Schedule(run_every_mins=5)

Expand Down

0 comments on commit ff04f21

Please sign in to comment.