Skip to content
Browse files

usage of db urls and cleanup

  • Loading branch information...
1 parent 08de803 commit 42ae4bf63b79f3195aeffea4053aa127d09316d1 @digi604 committed
Showing with 21 additions and 57 deletions.
  1. +4 −3 .travis.yml
  2. +8 −8 cms/models/pagemodel.py
  3. +2 −39 cms/test_utils/cli.py
  4. +7 −7 runtests.py
View
7 .travis.yml
@@ -4,17 +4,18 @@ python:
- "2.6"
- "2.7"
env:
- - DJANGO=test_requirements/django-1.3.txt DB="sqlite://:memory:"
+ - DJANGO=test_requirements/django-1.3.txt DB="sqlite://localhost/: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://:memory:"
+ - DJANGO=test_requirements/django-1.4.txt DB="sqlite://localhost/: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://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"
+ - sh -c "if [ '$DB' = 'mysql://root@127.0.0.1/djangocms_test' ]; then mysql -e 'create database IF NOT EXISTS djangocms_test CHARACTER SET utf8
+ COLLATE utf8_general_ci;' fi"
install:
- pip install -q -r $DJANGO --use-mirrors
View
16 cms/models/pagemodel.py
@@ -72,7 +72,7 @@ class Page(MPTTModel):
# Publisher fields
moderator_state = models.SmallIntegerField(_('moderator state'), default=0, blank=True, editable=False)
publisher_is_draft = models.BooleanField(default=1, editable=False, db_index=True)
- #This is misnamed - the one-to-one relation is populated on both ends
+ # This is misnamed - the one-to-one relation is populated on both ends
publisher_public = models.OneToOneField('self', related_name='publisher_draft', null=True, editable=False)
publisher_state = models.SmallIntegerField(default=0, editable=False, db_index=True)
@@ -303,7 +303,7 @@ def copy_page(self, target, site, position='first-child',
# invalidate the menu for this site
menu_pool.clear(site_id=site.pk)
- return page_copy # return the page_copy or None
+ return page_copy # return the page_copy or None
def save(self, no_signals=False, commit=True, **kwargs):
"""
@@ -465,7 +465,7 @@ def unpublish(self):
if not self.publisher_is_draft:
raise PublicIsUnmodifiable('The public instance cannot be unpublished. Use draft.')
- #First, make sure we are in the correct state
+ # First, make sure we are in the correct state
self.published = False
self.save()
public_page = self.get_public_object()
@@ -536,7 +536,7 @@ def delete_with_public(self):
"""
descendants = list(self.get_descendants().order_by('level'))
descendants.reverse()
- #TODO: Use a better exception class - PermissionDenied is not quite right
+ # TODO: Use a better exception class - PermissionDenied is not quite right
for page in descendants:
if not page.delete_requested():
raise PermissionDenied('There are descendant pages not marked for deletion')
@@ -596,7 +596,7 @@ def get_cached_ancestors(self, ascending=True):
self.ancestors_descending = list(self.get_ancestors(ascending))
return self.ancestors_descending
- ### Title object access
+ # ## Title object access
def get_title_obj(self, language=None, fallback=True, version_id=None, force_reload=False):
"""Helper function for accessing wanted / current title.
@@ -779,7 +779,7 @@ def has_view_permission(self, request):
return (user_perm or generic_perm)
else:
- #anonymous user
+ # anonymous user
if is_restricted or not settings.CMS_PUBLIC_FOR == 'all':
# anyonymous user, page has restriction and global access is permitted
return False
@@ -863,7 +863,7 @@ def is_home(self):
def get_home_pk_cache(self):
attr = "%s_home_pk_cache_%s" % (self.publisher_is_draft and "draft" or "public", self.site_id)
- if not hasattr(self, attr) or getattr(self, attr) is None:
+ if getattr(self, attr, None) is None:
setattr(self, attr, self.get_object_queryset().get_home(self.site).pk)
return getattr(self, attr)
@@ -1029,7 +1029,7 @@ def _publisher_save_public(self, obj):
prev_sibling = self.get_previous_filtered_sibling(**filters)
public_prev_sib = prev_sibling.publisher_public if prev_sibling else None
- if not self.publisher_public_id: # first time published
+ if not self.publisher_public_id: # first time published
# is there anybody on left side?
if public_prev_sib:
obj.insert_at(public_prev_sib, position='right', save=False)
View
41 cms/test_utils/cli.py
@@ -2,7 +2,7 @@
from distutils.version import LooseVersion
import django
import os
-from urlparse import urlparse
+import dj_database_url
gettext = lambda s: s
@@ -10,49 +10,12 @@
DJANGO_1_3 = LooseVersion(django.get_version()) < LooseVersion('1.4')
def configure(db_url, **extra):
- splits = db_url.split("://")
- scheme = splits[0]
- splits[0] = "http"
- db_url = "://".join(splits)
- 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 = scheme
- if db_type == 'sqlite':
- DB = {
- 'ENGINE': 'django.db.backends.sqlite3',
- 'NAME': db_splits.netloc,
- }
- elif db_type == 'postgres':
- DB = {
- 'ENGINE': 'django.db.backends.postgresql_psycopg2',
- 'NAME': db_splits.path[1:],
- }
- elif db_type == 'mysql':
- DB = {
- 'ENGINE': 'django.db.backends.mysql',
- 'NAME': db_splits.path[1:],
- 'TEST_CHARSET':'utf8',
- 'TEST_COLLATION':'utf8_general_ci',
- 'OPTIONS': {
- "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
+ DB = dj_database_url.parse(db_url)
else:
DB = {}
- print DB
defaults = dict(
CACHE_BACKEND='locmem:///',
DEBUG=True,
View
14 runtests.py
@@ -7,10 +7,11 @@
import sys
import warnings
from urlparse import urlparse
+import os
-def main(test_runner='cms.test_utils.runners.NormalTestRunner', junit_output_dir='.',
- time_tests=False, verbosity=1, failfast=False, test_labels=None, db_url="sqlite://:memory:"):
+def main(db_url, test_runner='cms.test_utils.runners.NormalTestRunner', junit_output_dir='.',
+ time_tests=False, verbosity=1, failfast=False, test_labels=None):
if not test_labels:
test_labels = ['cms']
with temp_dir() as STATIC_ROOT:
@@ -43,7 +44,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://:memory:', dest='db')
+ parser.add_argument('--db', default='sqlite://localhost/:memory:', dest='db')
parser.add_argument('test_labels', nargs='*')
args = parser.parse_args()
if getattr(args, 'jenkins', False):
@@ -53,8 +54,7 @@ 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_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_url=db_url)
+ db_url = os.environ.get('DATABASE_URL', args.db)
+ main(db_url, test_runner=test_runner, junit_output_dir=junit_output_dir, time_tests=time_tests,
+ verbosity=args.verbosity, failfast=args.failfast, test_labels=test_labels)

0 comments on commit 42ae4bf

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