Skip to content

Commit

Permalink
Use djangocms-helper for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yakky committed Jun 29, 2015
1 parent c705fc9 commit 6dd67e9
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 266 deletions.
57 changes: 39 additions & 18 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

language: python

sudo: false

python:
- 3.4
- 3.3
Expand All @@ -10,33 +12,52 @@ python:

env:
matrix:
- DJANGO='django>=1.4,<1.5'
- DJANGO='django>=1.5,<1.6'
- DJANGO='django>=1.6,<1.7'
- DJANGO='django16' CMS='cms30'
- DJANGO='django16' CMS='cms31'
- DJANGO='django16' CMS='cms32'
- DJANGO='django17' CMS='cms30'
- DJANGO='django17' CMS='cms31'
- DJANGO='django17' CMS='cms32'


# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors
install:
- pip install $DJANGO
- pip install -r requirements-test.txt
- pip install -U tox>=1.8 coveralls
- "if [[ $TRAVIS_PYTHON_VERSION == '2.6' ]]; then export PYVER=py26; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '2.7' ]]; then export PYVER=py27; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.3' ]]; then export PYVER=py33; fi"
- "if [[ $TRAVIS_PYTHON_VERSION == '3.4' ]]; then export PYVER=py34; fi"

# command to run tests, e.g. python setup.py test
script: coverage run runtests.py
script: COMMAND='coverage run' tox -e"$PYVER-$DJANGO-$CMS"

after_success: coveralls

matrix:
exclude:
- python: 3.3
env: DJANGO='django>=1.4,<1.5'
- python: 3.4
env: DJANGO='django>=1.4,<1.5'
- python: 2.6
env: DJANGO='django17' CMS='cms30'
- python: 2.6
env: DJANGO='django17' CMS='cms31'
- python: 2.6
env: DJANGO='django17' CMS='cms32'
- python: 2.6
env: DJANGO='django18' CMS='cms31'
- python: 2.6
env: DJANGO='django18' CMS='cms32'

allow_failures:
- python: 3.3
env: DJANGO='django>=1.5,<1.6'
- python: 3.3
env: DJANGO='django>=1.6,<1.7'
- python: 3.4
env: DJANGO='django>=1.5,<1.6'
- python: 3.4
env: DJANGO='django>=1.6,<1.7'
- python: 2.6
env: DJANGO='django16' CMS='cms32'
- python: 2.7
env: DJANGO='django16' CMS='cms32'
- python: 2.7
env: DJANGO='django17' CMS='cms32'
- python: 3.3
env: DJANGO='django16' CMS='cms32'
- python: 3.3
env: DJANGO='django17' CMS='cms32'
- python: 3.4
env: DJANGO='django16' CMS='cms32'
- python: 3.4
env: DJANGO='django17' CMS='cms32'
59 changes: 59 additions & 0 deletions cms_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys
from tempfile import mkdtemp
gettext = lambda s: s

HELPER_SETTINGS = {
'NOSE_ARGS': [
'-s',
],
'ROOT_URLCONF': 'tests.test_utils.urls',
'INSTALLED_APPS': [
'taggit',
'taggit_autosuggest',
'djangocms_page_tags',
'tests.test_utils',
],
'LANGUAGE_CODE': 'en',
'LANGUAGES': (
('en', gettext('English')),
('fr_FR', gettext('French')),
('it', gettext('Italiano')),
),
'CMS_LANGUAGES': {
1: [
{
'code': 'en',
'name': gettext('English'),
'public': True,
},
{
'code': 'it',
'name': gettext('Italiano'),
'public': True,
},
{
'code': 'fr',
'name': gettext('French'),
'public': True,
},
],
'default': {
'hide_untranslated': False,
},
},
'CMS_TEMPLATES': (
('page_tags.html', 'page'),
),
'FILE_UPLOAD_TEMP_DIR': mkdtemp()

}

def run():
from djangocms_helper import runner
runner.cms('djangocms_page_tags')

if __name__ == "__main__":
run()
4 changes: 3 additions & 1 deletion requirements-test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ coverage
coveralls
mock>=1.0.1
nose>=1.3.0
django-nose>=1.2
django-nose>=1.2
flake8
https://github.com/nephila/djangocms-helper/archive/develop.zip
112 changes: 0 additions & 112 deletions runtests.py

This file was deleted.

1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
),
license='BSD',
zip_safe=False,
test_suite='cms_helper.run',
keywords='djangocms-page-tags',
classifiers=[
'Development Status :: 4 - Beta',
Expand Down
81 changes: 15 additions & 66 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,74 +2,23 @@
"""
Tests for `djangocms_page_tags` module.
"""
from cms.utils.i18n import get_language_list
from django.core.cache import cache
from djangocms_helper.base_test import BaseTestCase

from django.contrib.auth.models import User
from django.http import SimpleCookie
from django.test import TestCase, RequestFactory
from six import StringIO
from cms.models import Page
from djangocms_page_tags.models import TitleTags, PageTags


class BaseTest(TestCase):
class BaseTest(BaseTestCase):
"""
Base class with utility function
"""
request_factory = None
user = None
languages = get_language_list()

@classmethod
def setUpClass(cls):
cls.request_factory = RequestFactory()
cls.user = User.objects.create(username='admin', is_staff=True, is_superuser=True)
cls.user_staff = User.objects.create(username='staff', is_staff=True)
cls.user_normal = User.objects.create(username='normal')

def get_pages(self):
from cms.api import create_page, create_title
page = create_page(u'page one', 'page.html', language='en')
page_2 = create_page(u'page two', 'page.html', language='en')
create_title(language='fr', title=u'page un', page=page)
create_title(language='it', title=u'pagina uno', page=page)
for lang in self.languages:
page.publish(lang)
page_2.publish('en')
return page.get_draft_object(), page_2.get_draft_object()

def get_request(self, page, lang):
request = self.request_factory.get(page.get_path(lang))
request.current_page = page
request.user = self.user
request.session = {}
request.cookies = SimpleCookie()
request.errors = StringIO()
return request

def get_page_request(self, page, user, path=None, edit=False, lang_code='en'):
from cms.middleware.toolbar import ToolbarMiddleware
path = path or page and page.get_absolute_url()
if edit:
path += '?edit'
request = RequestFactory().get(path)
request.session = {}
request.user = user
request.LANGUAGE_CODE = lang_code
if edit:
request.GET = {'edit': None}
else:
request.GET = {'edit_off': None}
request.current_page = page
mid = ToolbarMiddleware()
mid.process_request(request)
return request

def tearDown(self):
Page.objects.all().delete()
PageTags.objects.all().delete()
TitleTags.objects.all().delete()

@classmethod
def tearDownClass(cls):
User.objects.all().delete()
_pages_data = (
{'en': {'title': 'page one', 'template': 'page_tags.html', 'publish': True},
'fr': {'title': 'page un', 'publish': True},
'it': {'title': 'pagina uno', 'publish': True}},
{'en': {'title': 'page two', 'template': 'page_tags.html', 'publish': True},
'fr': {'title': 'page deux', 'publish': True},
'it': {'title': 'pagina due', 'publish': True}},
)

def setUp(self):
super(BaseTest, self).setUp()
cache.clear()
6 changes: 3 additions & 3 deletions tests/test_templatetags.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ def test_title_tags(self):
Test title-level templatetags
"""
page1, page2 = self.get_pages()
title_ext = TitleTags.objects.create(extended_object=page1.get_title_obj('en'))
title_ext = TitleTags.objects.create(extended_object=page2.get_title_obj('en'))
title_ext.tags.add("titletag.1", "titletag.2")
for lang in self.languages:
page1.publish(lang)
page2.publish(lang)
tags = Tag.objects.filter(name__in=("titletag.1", "titletag.2"))

request = self.get_page_request(page1.get_public_object(), AnonymousUser())
request = self.get_page_request(page2.get_public_object(), AnonymousUser())
response = details(request, '')
self.assertContains(response, '<li>titletag.2</li>')
self.assertContains(response, '<li>titletag.1</li>')
Expand Down
File renamed without changes.

0 comments on commit 6dd67e9

Please sign in to comment.