Skip to content
Browse files

new database url scheme

  • Loading branch information...
1 parent 2cb2e29 commit 7d57ccb1ce4b72b47545dc9ea509bacab90cdf34 @digi604 committed Dec 17, 2012
Showing with 41 additions and 52 deletions.
  1. +10 −10 .travis.yml
  2. +23 −16 cms/test_utils/cli.py
  3. +6 −19 runtests.py
  4. +2 −7 runtestserver.py
View
20 .travis.yml
@@ -4,22 +4,22 @@ python:
- "2.6"
- "2.7"
env:
- - DJANGO=test_requirements/django-1.3.txt DB=sqlite
- - DJANGO=test_requirements/django-1.3.txt DB=mysql
- - DJANGO=test_requirements/django-1.3.txt DB=postgres
- - DJANGO=test_requirements/django-1.4.txt DB=sqlite
- - DJANGO=test_requirements/django-1.4.txt DB=mysql
- - DJANGO=test_requirements/django-1.4.txt DB=postgres
+ - DJANGO=test_requirements/django-1.3.txt DB="sqlite://test.db/:memory:"
+ - DJANGO=test_requirements/django-1.3.txt DB="mysql://root@127.0.0.1/djangocms_test"
+ - DJANGO=test_requirements/django-1.3.txt DB="postgres://postgres@127.0.0.1/djangocms_test"
+ - DJANGO=test_requirements/django-1.4.txt DB="sqlite://test.db/:memory:"
+ - DJANGO=test_requirements/django-1.4.txt DB="mysql://root@127.0.0.1/djangocms_test"
+ - DJANGO=test_requirements/django-1.4.txt DB="postgres://postgres@127.0.0.1/djangocms_test"
before_script:
- - sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'DROP DATABASE IF EXISTS djangocms_test;' -U postgres; fi"
- - sh -c "if [ '$DB' = 'postgres' ]; then psql -c 'create database djangocms_test;' -U postgres; fi"
- - sh -c "if [ '$DB' = 'mysql' ]; then mysql -e 'create database IF NOT EXISTS djangocms_test'; fi"
+ - sh -c "if [ '$DB' = 'postgres://postgres@127.0.0.1/djangocms_test' ]; then psql -c 'DROP DATABASE IF EXISTS djangocms_test;' -U postgres; fi"
+ - sh -c "if [ '$DB' = 'postgres://postgres@127.0.0.1/djangocms_test' ]; then psql -c 'create database djangocms_test;' -U postgres; fi"
+ - sh -c "if [ '$DB' = 'mysql://root@127.0.0.1/djangocms_test' ]; then mysql -e 'create database IF NOT EXISTS djangocms_test'; fi"
install:
- pip install -q -r $DJANGO --use-mirrors
script:
- python runtests.py --db $DB --db_name djangocms_test
+ python runtests.py --db $DB
notifications:
email:
recipients:
View
39 cms/test_utils/cli.py
@@ -2,46 +2,53 @@
from distutils.version import LooseVersion
import django
import os
+from urlparse import urlparse
gettext = lambda s: s
urlpatterns = []
DJANGO_1_3 = LooseVersion(django.get_version()) < LooseVersion('1.4')
-def configure(db_data, **extra):
+def configure(db_url, **extra):
+ db_splits = urlparse(db_url)
from django.conf import settings
os.environ['DJANGO_SETTINGS_MODULE'] = 'cms.test_utils.cli'
if not 'DATABASES' in extra:
- db_type = db_data.get('DB', 'sqlite')
+ db_type = db_splits.scheme
if db_type == 'sqlite':
DB = {
'ENGINE': 'django.db.backends.sqlite3',
- 'NAME': ':memory:',
+ 'NAME': db_splits.netloc,
}
elif db_type == 'postgres':
DB = {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
- 'NAME': db_data.get('NAME', 'djangocms_test'),
- 'USER': db_data.get('USER', 'postgres'),
- 'HOST':'127.0.0.1',
- }
- if db_data.get('PASSWORD', None):
- DB['PASSWORD'] = db_data['PASSWORD']
+ 'NAME': db_splits.path[1:],
+ }
elif db_type == 'mysql':
DB = {
'ENGINE': 'django.db.backends.mysql',
- 'NAME': db_data.get('NAME', 'djangocms_test'),
- 'USER': db_data.get('USER', 'root'),
+ 'NAME': db_splits.path[1:],
'TEST_CHARSET':'utf8',
'TEST_COLLATION':'utf8_general_ci',
'OPTIONS': {
- "init_command": "SET storage_engine=INNODB",
- },
- }
- if db_data.get('PASSWORD', None):
- DB['PASSWORD'] = db_data['PASSWORD']
+ "init_command": "SET storage_engine=INNODB",
+ },
+ }
+ if db_splits.username:
+ DB['USER'] = db_splits.username
+ if db_splits.password:
+ DB['PASSWORD'] = db_splits.password
+ if db_splits.hostname:
+ DB['HOST'] = db_splits.hostname
+ try:
+ if db_splits.port:
+ DB['PORT'] = db_splits.port
+ except ValueError:
+ pass
else:
DB = {}
+ print DB
defaults = dict(
CACHE_BACKEND='locmem:///',
DEBUG=True,
View
25 runtests.py
@@ -6,10 +6,11 @@
import argparse
import sys
import warnings
+from urlparse import urlparse
def main(test_runner='cms.test_utils.runners.NormalTestRunner', junit_output_dir='.',
- time_tests=False, verbosity=1, failfast=False, test_labels=None, db_data={}):
+ time_tests=False, verbosity=1, failfast=False, test_labels=None, db_url="sqlite://:memory:"):
if not test_labels:
test_labels = ['cms']
with temp_dir() as STATIC_ROOT:
@@ -18,7 +19,7 @@ def main(test_runner='cms.test_utils.runners.NormalTestRunner', junit_output_dir
warnings.filterwarnings(
'error', r"DateTimeField received a naive datetime",
RuntimeWarning, r'django\.db\.models\.fields')
- configure(db_data=db_data, TEST_RUNNER=test_runner, JUNIT_OUTPUT_DIR=junit_output_dir,
+ configure(db_url=db_url, TEST_RUNNER=test_runner, JUNIT_OUTPUT_DIR=junit_output_dir,
TIME_TESTS=time_tests, ROOT_URLCONF='cms.test_utils.project.urls',
STATIC_ROOT=STATIC_ROOT, MEDIA_ROOT=MEDIA_ROOT, USE_TZ=use_tz)
from django.conf import settings
@@ -42,10 +43,7 @@ def main(test_runner='cms.test_utils.runners.NormalTestRunner', junit_output_dir
parser.add_argument('--verbosity', default=1)
parser.add_argument('--time-tests', action='store_true', default=False,
dest='time_tests')
- parser.add_argument('--db', default='sqlite', dest='db')
- parser.add_argument('--db_user', default=None, dest='db_user')
- parser.add_argument('--db_name', default=None, dest='db_name')
- parser.add_argument('--db_password', default="", dest='db_password')
+ parser.add_argument('--db', default='sqlite://:memory:', dest='db')
parser.add_argument('test_labels', nargs='*')
args = parser.parse_args()
if getattr(args, 'jenkins', False):
@@ -55,19 +53,8 @@ def main(test_runner='cms.test_utils.runners.NormalTestRunner', junit_output_dir
junit_output_dir = getattr(args, 'jenkins_data_dir', '.')
time_tests = getattr(args, 'time_tests', False)
test_labels = ['cms.%s' % label for label in args.test_labels]
- db_data = {'DB':args.db}
- if args.db_user:
- db_data['USER'] = args.db_user
- else:
- if args.db == "mysql":
- db_data['USER'] = "root"
- elif args.db == 'postgres':
- db_data['USER'] = 'postgres'
- if args.db_name:
- db_data['NAME'] = args.db_name
- if args.db_password:
- db_data['PASSWORD'] = args.db_password
+ db_url = args.db
main(test_runner=test_runner, junit_output_dir=junit_output_dir, time_tests=time_tests,
verbosity=args.verbosity, failfast=args.failfast, test_labels=test_labels,
- db_data=db_data)
+ db_url=db_url)
View
9 runtestserver.py
@@ -5,6 +5,7 @@
from django.utils import autoreload
import os
import sys
+import urlparse
def main():
@@ -15,16 +16,10 @@ def main():
new_db = not os.path.exists('cmstestdb.sqlite')
with temp_dir() as STATIC_ROOT:
with temp_dir() as MEDIA_ROOT:
- configure({},
+ configure("sqlite://cmstestdb.sqlite",
ROOT_URLCONF='cms.test_utils.project.urls',
STATIC_ROOT=STATIC_ROOT,
MEDIA_ROOT=MEDIA_ROOT,
- DATABASES={
- 'default': {
- 'ENGINE': 'django.db.backends.sqlite3',
- 'NAME': 'cmstestdb.sqlite',
- }
- }
)
if os.environ.get("RUN_MAIN") != "true":
from django.core.management import call_command

0 comments on commit 7d57ccb

Please sign in to comment.
Something went wrong with that request. Please try again.