diff --git a/.travis.yml b/.travis.yml index 3c1735cb..5dcf2e61 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,16 @@ # https://github.com/travis-ci/travis-ci/wiki/.travis.yml-options -install: "sudo pip install -r test/example_thirdparty/requirements.txt -r test/example_thirdparty/requirements_test.txt" - -script: "python test/example_thirdparty/manage.py test pybb" - +language: python python: + - "2.6" - "2.7" +env: + - DJANGO=1.3.7 + - DJANGO=1.4.5 + - DJANGO=1.5 +install: + - pip install Django==$DJANGO --use-mirrors + - pip install -r test/test_project/requirements_test.txt +script: + - python setup.py test + diff --git a/pybb/models.py b/pybb/models.py index c31898fa..d03e9406 100644 --- a/pybb/models.py +++ b/pybb/models.py @@ -111,7 +111,7 @@ def __unicode__(self): return self.name def update_counters(self): - posts = Post.objects.filter(topic__forum_id=self.id) + posts = Post.objects.filter(topic__forum__id=self.id) self.post_count = posts.count() self.topic_count = Topic.objects.filter(forum=self).count() try: @@ -225,7 +225,7 @@ def delete(self, using=None): def update_counters(self): self.post_count = self.posts.count() - last_post = Post.objects.filter(topic_id=self.id).order_by('-created')[0] + last_post = Post.objects.filter(topic__id=self.id).order_by('-created')[0] self.updated = last_post.updated or last_post.created self.save() diff --git a/pybb/tests.py b/pybb/tests.py index 75802faf..93ccf95d 100644 --- a/pybb/tests.py +++ b/pybb/tests.py @@ -966,7 +966,7 @@ def setUp(self): self.create_user() self.create_initial() - def test_attachment(self): + def test_attachment_one(self): add_post_url = reverse('pybb:add_post', kwargs={'topic_id': self.topic.id}) self.login_client() response = self.client.get(add_post_url) @@ -977,7 +977,7 @@ def test_attachment(self): self.assertEqual(response.status_code, 200) self.assertTrue(Post.objects.filter(body='test attachment').exists()) - def test_attachment(self): + def test_attachment_two(self): add_post_url = reverse('pybb:add_post', kwargs={'topic_id': self.topic.id}) self.login_client() response = self.client.get(add_post_url) diff --git a/pybb/urls.py b/pybb/urls.py index 3cb433db..a4401388 100644 --- a/pybb/urls.py +++ b/pybb/urls.py @@ -1,6 +1,8 @@ # -*- coding: utf-8 -*- - -from django.conf.urls import * +try: + from django.conf.urls import patterns, include, url +except ImportError: + from django.conf.urls.defaults import patterns, include, url from pybb.feeds import LastPosts, LastTopics from pybb.views import IndexView, CategoryView, ForumView, TopicView,\ diff --git a/runtests.py b/runtests.py new file mode 100644 index 00000000..ffd260a2 --- /dev/null +++ b/runtests.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +import sys +import os +from os.path import dirname, abspath +from optparse import OptionParser + +from django.conf import settings +import django + +TEMPLATE_CONTEXT_PROCESSORS = ( + 'django.contrib.auth.context_processors.auth', + 'django.core.context_processors.debug', + 'django.core.context_processors.i18n', + 'django.core.context_processors.media', + 'django.core.context_processors.static', + 'django.core.context_processors.request', + 'pybb.context_processors.processor', +) + +if django.get_version() >= (1, 4): + TEMPLATE_CONTEXT_PROCESSORS += ['django.core.context_processors.tz',] + +# For convenience configure settings if they are not pre-configured or if we +# haven't been provided settings to use by environment variable. +if not settings.configured and not os.environ.get('DJANGO_SETTINGS_MODULE'): + settings.configure( + DATABASES={ + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', + } + }, + INSTALLED_APPS=[ + 'django.contrib.auth', + 'django.contrib.admin', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.sites', + 'pytils', + 'sorl.thumbnail', + 'pure_pagination', + 'pybb', + ], + ROOT_URLCONF='test.test_project.test_urls', + DEBUG=False, + SITE_ID=1, + STATIC_URL='/static/', + AUTH_PROFILE_MODULE='pybb.Profile', + TEMPLATE_DIRS=(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'test/test_project/templates'), ), + PYBB_ATTACHMENT_ENABLE=True, + TEMPLATE_CONTEXT_PROCESSORS=TEMPLATE_CONTEXT_PROCESSORS, + ) + +from django.test.simple import DjangoTestSuiteRunner + + +def runtests(*test_args, **kwargs): + if 'south' in settings.INSTALLED_APPS: + from south.management.commands import patch_for_test_db_setup + patch_for_test_db_setup() + + if not test_args: + test_args = ['pybb'] + parent = dirname(abspath(__file__)) + sys.path.insert(0, parent) + test_runner = DjangoTestSuiteRunner(verbosity=kwargs.get('verbosity', 1), interactive=kwargs.get('interactive', False), failfast=kwargs.get('failfast')) + failures = test_runner.run_tests(test_args) + sys.exit(failures) + +if __name__ == '__main__': + parser = OptionParser() + parser.add_option('--failfast', action='store_true', default=False, dest='failfast') + + (options, args) = parser.parse_args() + + runtests(failfast=options.failfast, *args) \ No newline at end of file diff --git a/setup.py b/setup.py index e40a9a7c..7f9c78b8 100644 --- a/setup.py +++ b/setup.py @@ -1,29 +1,29 @@ from setuptools import setup, find_packages setup( - version = '0.12.4', - description = 'PyBB Modified. Django forum application', - long_description = open('README.rst').read(), - author = 'Pavel Zhukov', - author_email = 'gelios@gmail.com', - name = 'pybbm', - url = 'http://www.pybbm.org/', - packages = find_packages(), - include_package_data = True, - package_data = {'': ['pybb/templates', 'pybb/static']}, - install_requires = [ - 'markdown', - 'postmarkup', - 'south', - 'pytils', - 'django-annoying', - 'sorl-thumbnail', - 'django-pure-pagination', - 'django-mailer', - ], - - license = "BSD", - keywords = "django application forum board", + version='0.12.4', + description='PyBB Modified. Django forum application', + long_description=open('README.rst').read(), + author='Pavel Zhukov', + author_email='gelios@gmail.com', + name='pybbm', + url='http://www.pybbm.org/', + packages=find_packages(), + include_package_data=True, + package_data={'': ['pybb/templates', 'pybb/static']}, + install_requires=[ + 'markdown', + 'postmarkup', + 'south', + 'pytils', + 'django-annoying', + 'sorl-thumbnail', + 'django-pure-pagination', + 'django-mailer', + ], + test_suite='runtests.runtests', + license="BSD", + keywords="django application forum board", classifiers=[ 'Development Status :: 4 - Beta', 'Environment :: Web Environment', diff --git a/test/__init__.py b/test/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/example_bootstrap/urls.py b/test/example_bootstrap/urls.py index 47e7db99..60b83f6b 100644 --- a/test/example_bootstrap/urls.py +++ b/test/example_bootstrap/urls.py @@ -1,4 +1,7 @@ -from django.conf.urls.defaults import patterns, include, url +try: + from django.conf.urls import patterns, include, url +except ImportError: + from django.conf.urls.defaults import patterns, include, url from django.contrib import admin admin.autodiscover() diff --git a/test/example_thirdparty/requirements.txt b/test/example_thirdparty/requirements.txt index 375cf0ad..0c148921 100644 --- a/test/example_thirdparty/requirements.txt +++ b/test/example_thirdparty/requirements.txt @@ -1,4 +1,3 @@ -Django>=1.4 South>=0.7.5 Markdown>=2.1 postmarkup>=1.2.0 diff --git a/test/example_thirdparty/settings.py b/test/example_thirdparty/settings.py index fdd8ee6d..d23eec02 100644 --- a/test/example_thirdparty/settings.py +++ b/test/example_thirdparty/settings.py @@ -98,30 +98,6 @@ ] AUTH_PROFILE_MODULE = 'pybb.Profile' -LOGGING = { - 'version': 1, - 'disable_existing_loggers': False, - 'filters': { - 'require_debug_false': { - '()': 'django.utils.log.RequireDebugFalse' - } - }, - 'handlers': { - 'mail_admins': { - 'level': 'ERROR', - 'filters': ['require_debug_false'], - 'class': 'django.utils.log.AdminEmailHandler' - } - }, - 'loggers': { - 'django.request': { - 'handlers': ['mail_admins'], - 'level': 'ERROR', - 'propagate': True, - }, - } -} - EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Pybb diff --git a/test/example_thirdparty/urls.py b/test/example_thirdparty/urls.py index 1c41f97d..61417483 100644 --- a/test/example_thirdparty/urls.py +++ b/test/example_thirdparty/urls.py @@ -1,5 +1,8 @@ # -*- coding: utf-8 -*- -from django.conf.urls import patterns, include, url +try: + from django.conf.urls import patterns, include, url +except ImportError: + from django.conf.urls.defaults import patterns, include, url from django.contrib import admin admin.autodiscover() diff --git a/test/test_project/__init__.py b/test/test_project/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/test/example_thirdparty/requirements_test.txt b/test/test_project/requirements_test.txt similarity index 100% rename from test/example_thirdparty/requirements_test.txt rename to test/test_project/requirements_test.txt diff --git a/test/test_project/templates/base.html b/test/test_project/templates/base.html new file mode 100644 index 00000000..137fab4d --- /dev/null +++ b/test/test_project/templates/base.html @@ -0,0 +1,17 @@ +{% load url from future %} +{% load pytils_numeral %} + + +
+ {% block extra_style %}{% endblock %} +