Skip to content

Commit 09bf76d

Browse files
committed
Merge pull request django-cms#2214 from ojii/tests-cleanup
Tests cleanup
2 parents c12a894 + 098f1f1 commit 09bf76d

File tree

31 files changed

+616
-350
lines changed

31 files changed

+616
-350
lines changed

.travis.yml

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ python:
44
- 2.7
55
- 3.3
66
env:
7-
- DJANGO=1.4 DB='sqlite://localhost/:memory:'
8-
- DJANGO=1.4 DB='mysql://[email protected]/djangocms_test'
9-
- DJANGO=1.4 DB='postgres://[email protected]/djangocms_test'
10-
- DJANGO=1.5 DB='sqlite://localhost/:memory:'
11-
- DJANGO=1.5 DB='mysql://[email protected]/djangocms_test'
12-
- DJANGO=1.5 DB='postgres://[email protected]/djangocms_test'
7+
- DJANGO=1.4 DATABASE_URL='sqlite://localhost/:memory:'
8+
- DJANGO=1.4 DATABASE_URL='mysql://[email protected]/djangocms_test'
9+
- DJANGO=1.4 DATABASE_URL='postgres://[email protected]/djangocms_test'
10+
- DJANGO=1.5 DATABASE_URL='sqlite://localhost/:memory:'
11+
- DJANGO=1.5 DATABASE_URL='mysql://[email protected]/djangocms_test'
12+
- DJANGO=1.5 DATABASE_URL='postgres://[email protected]/djangocms_test'
1313

1414
before_script:
15-
- sh -c "if [ '$DB' = 'postgres://[email protected]/djangocms_test' ]; then psql -c 'DROP DATABASE IF EXISTS djangocms_test;' -U postgres; fi"
16-
- sh -c "if [ '$DB' = 'postgres://[email protected]/djangocms_test' ]; then psql -c 'create database djangocms_test;' -U postgres; fi"
17-
- sh -c "if [ '$DB' = 'mysql://[email protected]/djangocms_test' ]; then mysql -e 'create database IF NOT EXISTS djangocms_test CHARACTER SET utf8 COLLATE utf8_general_ci;'; fi"
15+
- sh -c "if [ '$DATABASE_URL' = 'postgres://[email protected]/djangocms_test' ]; then psql -c 'DROP DATABASE IF EXISTS djangocms_test;' -U postgres; fi"
16+
- sh -c "if [ '$DATABASE_URL' = 'postgres://[email protected]/djangocms_test' ]; then psql -c 'create database djangocms_test;' -U postgres; fi"
17+
- sh -c "if [ '$DATABASE_URL' = 'mysql://[email protected]/djangocms_test' ]; then mysql -e 'create database IF NOT EXISTS djangocms_test CHARACTER SET utf8 COLLATE utf8_general_ci;'; fi"
1818

1919
install:
2020
- export DISPLAY=:99.0
2121
- sh -e /etc/init.d/xvfb start
2222
- pip install -q -r "test_requirements/django-$DJANGO.txt" --use-mirrors
23-
- if [ $DB == 'mysql://[email protected]/djangocms_test' ]; then pip install -q mysql-python --use-mirrors; fi
23+
- if [ $DATABASE_URL == 'mysql://[email protected]/djangocms_test' ]; then pip install -q mysql-python --use-mirrors; fi
2424
script:
25-
python runtests.py --db $DB
25+
python develop.py test --migrate
2626
notifications:
2727
email:
2828
recipients:
@@ -37,11 +37,10 @@ notifications:
3737
matrix:
3838
exclude:
3939
- python: 3.3
40-
env: DJANGO=1.4 DB='sqlite://localhost/:memory:'
40+
env: DJANGO=1.4 DATABASE_URL='sqlite://localhost/:memory:'
4141
- python: 3.3
42-
env: DJANGO=1.4 DB='mysql://[email protected]/djangocms_test'
42+
env: DJANGO=1.4 DATABASE_URL='mysql://[email protected]/djangocms_test'
4343
- python: 3.3
44-
env: DJANGO=1.4 DB='postgres://[email protected]/djangocms_test'
44+
env: DJANGO=1.4 DATABASE_URL='postgres://[email protected]/djangocms_test'
4545
- python: 3.3
46-
env: DJANGO=1.5 DB='mysql://[email protected]/djangocms_test'
47-
46+
env: DJANGO=1.5 DATABASE_URL='mysql://[email protected]/djangocms_test'

cms/middleware/page.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# -*- coding: utf-8 -*-
22
from cms.appresolver import applications_page_check
3+
from django.utils.functional import SimpleLazyObject
34

45

5-
class LazyPage(object):
6-
def __get__(self, request, obj_type=None):
7-
from cms.utils.page_resolver import get_page_from_request
6+
def get_page(request):
7+
from cms.utils.page_resolver import get_page_from_request
88

9-
if not hasattr(request, '_current_page_cache'):
10-
request._current_page_cache = get_page_from_request(request)
11-
if not request._current_page_cache:
12-
# if this is in a apphook
13-
# find the page the apphook is attached to
14-
request._current_page_cache = applications_page_check(request)
15-
return request._current_page_cache
9+
if not hasattr(request, '_current_page_cache'):
10+
request._current_page_cache = get_page_from_request(request)
11+
if not request._current_page_cache:
12+
# if this is in a apphook
13+
# find the page the apphook is attached to
14+
request._current_page_cache = applications_page_check(request)
15+
return request._current_page_cache
1616

1717

1818
class CurrentPageMiddleware(object):
1919
def process_request(self, request):
20-
request.__class__.current_page = LazyPage()
20+
request.current_page = SimpleLazyObject(lambda: get_page(request))
2121
return None

cms/models/managers.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -327,20 +327,27 @@ def for_page(self, page):
327327
"""
328328
# permissions should be managed on the draft page only
329329
page = page.get_draft_object()
330-
from cms.models import ACCESS_DESCENDANTS, ACCESS_CHILDREN, \
331-
ACCESS_PAGE_AND_CHILDREN, ACCESS_PAGE_AND_DESCENDANTS, ACCESS_PAGE
330+
from cms.models import (ACCESS_DESCENDANTS, ACCESS_CHILDREN,
331+
ACCESS_PAGE_AND_CHILDREN, ACCESS_PAGE_AND_DESCENDANTS, ACCESS_PAGE)
332332

333-
parents = Q(page__tree_id=page.tree_id, page__lft__lte=page.lft, page__rght__gte=page.rght) & (
333+
if page.level is None or page.lft is None or page.rght is None:
334+
raise ValueError("Cannot use unsaved page for permission lookup, missing MPTT attributes.")
335+
336+
parents = Q(page__tree_id=page.tree_id) & (
334337
Q(grant_on=ACCESS_DESCENDANTS) | Q(grant_on=ACCESS_PAGE_AND_DESCENDANTS))
335338
direct_parents = Q(
336339
page__tree_id=page.tree_id,
337-
page__lft__lte=page.lft,
338-
page__rght__gte=page.rght,
339-
page__level=page.level - 1) & \
340-
(Q(grant_on=ACCESS_CHILDREN) | Q(grant_on=ACCESS_PAGE_AND_CHILDREN))
340+
page__level=page.level - 1) & (
341+
Q(grant_on=ACCESS_CHILDREN) | Q(grant_on=ACCESS_PAGE_AND_CHILDREN)
342+
)
341343
page_qs = Q(page=page) & (
342344
Q(grant_on=ACCESS_PAGE_AND_DESCENDANTS) | Q(grant_on=ACCESS_PAGE_AND_CHILDREN) | Q(grant_on=ACCESS_PAGE))
343345

346+
parents = parents & Q(page__lft__lte=page.lft)
347+
direct_parents = direct_parents & Q(page__lft__lte=page.lft)
348+
parents = parents & Q(page__rght__gte=page.rght)
349+
direct_parents = direct_parents & Q(page__rght__gte=page.rght)
350+
344351
query = (parents | direct_parents | page_qs)
345352
return self.filter(query).order_by('page__level')
346353

cms/plugins/file/migrations/0001_initial.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
class Migration(SchemaMigration):
99

10+
depends_on = (
11+
("cms", "0048_auto__add_field_page_application_namespace__add_unique_page_publisher_"),
12+
)
13+
1014
def forwards(self, orm):
1115
# Adding model 'File'
1216
db.create_table('cmsplugin_file', (

cms/plugins/flash/migrations/0001_initial.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
class Migration(SchemaMigration):
99

10+
depends_on = (
11+
("cms", "0048_auto__add_field_page_application_namespace__add_unique_page_publisher_"),
12+
)
13+
1014
def forwards(self, orm):
1115
# Adding model 'Flash'
1216
db.create_table('cmsplugin_flash', (

cms/plugins/googlemap/migrations/0001_initial.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
class Migration(SchemaMigration):
99

10+
depends_on = (
11+
("cms", "0048_auto__add_field_page_application_namespace__add_unique_page_publisher_"),
12+
)
13+
1014
def forwards(self, orm):
1115
# Adding model 'GoogleMap'
1216
db.create_table('cmsplugin_googlemap', (

0 commit comments

Comments
 (0)