Permalink
Browse files

added tests!

  • Loading branch information...
1 parent 1e37d41 commit da095ce07141104994c715608f5c6fc46fb9df64 ojii committed Mar 19, 2010
View
@@ -4,3 +4,10 @@
dist
django_multilingual_ng.egg-info
_build
+tests/bin
+tests/develop-eggs
+tests/eggs
+tests/parts
+tests/.installed.cfg
+tests/testproject.db
+tests/downloads
View
@@ -8,7 +8,6 @@
VERSION = ('0', '1', '19')
__version__ = '.'.join(VERSION)
-
try:
"""
WARNING: All these names imported here WILL BE DEPRECATED!
View
@@ -3,6 +3,8 @@
fields.
This file contains the implementation for QSRF Django.
+
+Huge thanks to hubscher.remy for writing this!
"""
from django.db.models.sql.compiler import SQLCompiler
View
@@ -1,4 +1,5 @@
from django.conf import settings
+from django.core.exceptions import ImproperlyConfigured
LANGUAGES = settings.LANGUAGES
@@ -18,4 +19,12 @@ def get_fallback_languages():
IMPLICIT_FALLBACK = getattr(settings, 'MULTILINGUAL_IMPLICIT_FALLBACK', True)
-DEFAULT_LANGUAGE = LANGUAGES[0][0]
+DEFAULT_LANGUAGE = LANGUAGES[0][0]
+
+mcp = "multilingual.context_processors.multilingual"
+if mcp not in settings.TEMPLATE_CONTEXT_PROCESSORS:
+ found = ','.join(settings.TEMPLATE_CONTEXT_PROCESSORS)
+ raise ImproperlyConfigured(
+ "django-multilingual-ng requires the '%s' context processor. "
+ "Only found: %s" % (mcp, found)
+ )
View
@@ -0,0 +1,25 @@
+import subprocess
+import os
+import sys
+import unittest
+
+thisdir = os.path.abspath(os.path.dirname(__file__))
+os.chdir(thisdir + '/tests/')
+sys.path.insert(0, thisdir)
+os.environ['DJANGO_SETTINGS_MODULE'] = 'testproject.settings'
+
+def call(command):
+ pop = subprocess.Popen(command, shell=True, bufsize=1024, stdout=subprocess.PIPE)
+ pipe = pop.stdout
+ while True:
+ data = pipe.read()
+ if not data:
+ break
+ print data
+ pop.poll()
+ return pop.returncode
+
+if __name__ == '__main__':
+ call("python %s/tests/bootstrap.py -c %s/tests/buildout.cfg" % (thisdir, thisdir))
+ call("%s/tests/bin/buildout" % thisdir)
+ call("%s/tests/bin/test" % thisdir)
View
@@ -8,7 +8,7 @@
description = 'Multilingual extension for Django - NG',
author = 'Jonas Obrist',
url = 'http://github.com/ojii/django-multilingual-ng',
- packages = find_packages(exclude=["testproject",]),
+ packages = find_packages(exclude=['parts','downloads','eggs', '.installed.cfg', 'bin', 'develop-eggs']),
zip_safe=False,
package_data={
'multilingual': [
View
No changes.
View
@@ -0,0 +1,121 @@
+##############################################################################
+#
+# Copyright (c) 2006 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id$
+"""
+
+import os, shutil, sys, tempfile, urllib2
+from optparse import OptionParser
+
+tmpeggs = tempfile.mkdtemp()
+
+is_jython = sys.platform.startswith('java')
+
+# parsing arguments
+parser = OptionParser()
+parser.add_option("-v", "--version", dest="version",
+ help="use a specific zc.buildout version")
+parser.add_option("-d", "--distribute",
+ action="store_true", dest="distribute", default=False,
+ help="Use Distribute rather than Setuptools.")
+
+parser.add_option("-c", None, action="store", dest="config_file",
+ help=("Specify the path to the buildout configuration "
+ "file to be used."))
+
+options, args = parser.parse_args()
+
+# if -c was provided, we push it back into args for buildout' main function
+if options.config_file is not None:
+ args += ['-c', options.config_file]
+
+if options.version is not None:
+ VERSION = '==%s' % options.version
+else:
+ VERSION = ''
+
+USE_DISTRIBUTE = options.distribute
+args = args + ['bootstrap']
+
+to_reload = False
+try:
+ import pkg_resources
+ if not hasattr(pkg_resources, '_distribute'):
+ to_reload = True
+ raise ImportError
+except ImportError:
+ ez = {}
+ if USE_DISTRIBUTE:
+ exec urllib2.urlopen('http://python-distribute.org/distribute_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0, no_fake=True)
+ else:
+ exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+ ).read() in ez
+ ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+ if to_reload:
+ reload(pkg_resources)
+ else:
+ import pkg_resources
+
+if sys.platform == 'win32':
+ def quote(c):
+ if ' ' in c:
+ return '"%s"' % c # work around spawn lamosity on windows
+ else:
+ return c
+else:
+ def quote (c):
+ return c
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+ws = pkg_resources.working_set
+
+if USE_DISTRIBUTE:
+ requirement = 'distribute'
+else:
+ requirement = 'setuptools'
+
+if is_jython:
+ import subprocess
+
+ assert subprocess.Popen([sys.executable] + ['-c', quote(cmd), '-mqNxd',
+ quote(tmpeggs), 'zc.buildout' + VERSION],
+ env=dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse(requirement)).location
+ ),
+ ).wait() == 0
+
+else:
+ assert os.spawnle(
+ os.P_WAIT, sys.executable, quote (sys.executable),
+ '-c', quote (cmd), '-mqNxd', quote (tmpeggs), 'zc.buildout' + VERSION,
+ dict(os.environ,
+ PYTHONPATH=
+ ws.find(pkg_resources.Requirement.parse(requirement)).location
+ ),
+ ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout' + VERSION)
+import zc.buildout.buildout
+zc.buildout.buildout.main(args)
+shutil.rmtree(tmpeggs)
View
@@ -0,0 +1,22 @@
+[buildout]
+develop =
+ ../../django-multilingual-ng
+parts =
+ python
+ django
+eggs =
+ django-multilingual-ng
+
+[django]
+recipe = djangorecipe
+version = 1.2-beta-1
+project = testproject
+settings = settings
+eggs = ${buildout:eggs}
+test =
+ testproject
+
+[python]
+recipe = zc.recipe.egg
+interpreter = python
+eggs = ${buildout:eggs}
No changes.
@@ -0,0 +1 @@
+[{"pk": 5, "model": "contenttypes.contenttype", "fields": {"model": "contenttype", "name": "content type", "app_label": "contenttypes"}}, {"pk": 2, "model": "contenttypes.contenttype", "fields": {"model": "group", "name": "group", "app_label": "auth"}}, {"pk": 7, "model": "contenttypes.contenttype", "fields": {"model": "logentry", "name": "log entry", "app_label": "admin"}}, {"pk": 4, "model": "contenttypes.contenttype", "fields": {"model": "message", "name": "message", "app_label": "auth"}}, {"pk": 10, "model": "contenttypes.contenttype", "fields": {"model": "multilingualflatpage", "name": "multilingual flat page", "app_label": "flatpages"}}, {"pk": 9, "model": "contenttypes.contenttype", "fields": {"model": "multilingualflatpagetranslation", "name": "multilingual flat page translation", "app_label": "flatpages"}}, {"pk": 1, "model": "contenttypes.contenttype", "fields": {"model": "permission", "name": "permission", "app_label": "auth"}}, {"pk": 6, "model": "contenttypes.contenttype", "fields": {"model": "session", "name": "session", "app_label": "sessions"}}, {"pk": 8, "model": "contenttypes.contenttype", "fields": {"model": "site", "name": "site", "app_label": "sites"}}, {"pk": 3, "model": "contenttypes.contenttype", "fields": {"model": "user", "name": "user", "app_label": "auth"}}, {"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}, {"pk": 1, "model": "flatpages.multilingualflatpagetranslation", "fields": {"content": "MLFP-Content1-en", "language_code": "en", "master": 1, "title": "MLFP-Title1-en"}}, {"pk": 2, "model": "flatpages.multilingualflatpagetranslation", "fields": {"content": "MLFP-Content2-en", "language_code": "en", "master": 2, "title": "MLFP-Title2-en"}}, {"pk": 3, "model": "flatpages.multilingualflatpagetranslation", "fields": {"content": "MLFP-Content1-ja", "language_code": "ja", "master": 1, "title": "MLFP-Title1-ja"}}, {"pk": 4, "model": "flatpages.multilingualflatpagetranslation", "fields": {"content": "MLFP-Content2-ja", "language_code": "ja", "master": 2, "title": "MLFP-Title2-ja"}}, {"pk": 1, "model": "flatpages.multilingualflatpage", "fields": {"url": "/test1/", "enable_comments": false, "registration_required": false, "sites": [1], "template_name": ""}}, {"pk": 2, "model": "flatpages.multilingualflatpage", "fields": {"url": "/test2/", "enable_comments": false, "registration_required": false, "sites": [1], "template_name": ""}}, {"pk": 19, "model": "auth.permission", "fields": {"codename": "add_logentry", "name": "Can add log entry", "content_type": 7}}, {"pk": 20, "model": "auth.permission", "fields": {"codename": "change_logentry", "name": "Can change log entry", "content_type": 7}}, {"pk": 21, "model": "auth.permission", "fields": {"codename": "delete_logentry", "name": "Can delete log entry", "content_type": 7}}, {"pk": 4, "model": "auth.permission", "fields": {"codename": "add_group", "name": "Can add group", "content_type": 2}}, {"pk": 5, "model": "auth.permission", "fields": {"codename": "change_group", "name": "Can change group", "content_type": 2}}, {"pk": 6, "model": "auth.permission", "fields": {"codename": "delete_group", "name": "Can delete group", "content_type": 2}}, {"pk": 10, "model": "auth.permission", "fields": {"codename": "add_message", "name": "Can add message", "content_type": 4}}, {"pk": 11, "model": "auth.permission", "fields": {"codename": "change_message", "name": "Can change message", "content_type": 4}}, {"pk": 12, "model": "auth.permission", "fields": {"codename": "delete_message", "name": "Can delete message", "content_type": 4}}, {"pk": 1, "model": "auth.permission", "fields": {"codename": "add_permission", "name": "Can add permission", "content_type": 1}}, {"pk": 2, "model": "auth.permission", "fields": {"codename": "change_permission", "name": "Can change permission", "content_type": 1}}, {"pk": 3, "model": "auth.permission", "fields": {"codename": "delete_permission", "name": "Can delete permission", "content_type": 1}}, {"pk": 7, "model": "auth.permission", "fields": {"codename": "add_user", "name": "Can add user", "content_type": 3}}, {"pk": 8, "model": "auth.permission", "fields": {"codename": "change_user", "name": "Can change user", "content_type": 3}}, {"pk": 9, "model": "auth.permission", "fields": {"codename": "delete_user", "name": "Can delete user", "content_type": 3}}, {"pk": 13, "model": "auth.permission", "fields": {"codename": "add_contenttype", "name": "Can add content type", "content_type": 5}}, {"pk": 14, "model": "auth.permission", "fields": {"codename": "change_contenttype", "name": "Can change content type", "content_type": 5}}, {"pk": 15, "model": "auth.permission", "fields": {"codename": "delete_contenttype", "name": "Can delete content type", "content_type": 5}}, {"pk": 28, "model": "auth.permission", "fields": {"codename": "add_multilingualflatpage", "name": "Can add multilingual flat page", "content_type": 10}}, {"pk": 29, "model": "auth.permission", "fields": {"codename": "change_multilingualflatpage", "name": "Can change multilingual flat page", "content_type": 10}}, {"pk": 30, "model": "auth.permission", "fields": {"codename": "delete_multilingualflatpage", "name": "Can delete multilingual flat page", "content_type": 10}}, {"pk": 25, "model": "auth.permission", "fields": {"codename": "add_multilingualflatpagetranslation", "name": "Can add multilingual flat page translation", "content_type": 9}}, {"pk": 26, "model": "auth.permission", "fields": {"codename": "change_multilingualflatpagetranslation", "name": "Can change multilingual flat page translation", "content_type": 9}}, {"pk": 27, "model": "auth.permission", "fields": {"codename": "delete_multilingualflatpagetranslation", "name": "Can delete multilingual flat page translation", "content_type": 9}}, {"pk": 16, "model": "auth.permission", "fields": {"codename": "add_session", "name": "Can add session", "content_type": 6}}, {"pk": 17, "model": "auth.permission", "fields": {"codename": "change_session", "name": "Can change session", "content_type": 6}}, {"pk": 18, "model": "auth.permission", "fields": {"codename": "delete_session", "name": "Can delete session", "content_type": 6}}, {"pk": 22, "model": "auth.permission", "fields": {"codename": "add_site", "name": "Can add site", "content_type": 8}}, {"pk": 23, "model": "auth.permission", "fields": {"codename": "change_site", "name": "Can change site", "content_type": 8}}, {"pk": 24, "model": "auth.permission", "fields": {"codename": "delete_site", "name": "Can delete site", "content_type": 8}}]
No changes.
@@ -0,0 +1,66 @@
+# -*- coding: utf-8 -*-
+import os
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+DATABASE_ENGINE = 'sqlite3'
+DATABASE_NAME = 'testproject.db'
+
+TIME_ZONE = 'America/Chicago'
+
+LANGUAGE_CODE = 'en'
+
+LANGUAGES = (
+ ('en', 'English'),
+ ('ja', '日本語'),
+)
+
+MEDIA_ROOT = os.path.join(os.path.dirname(__file__), 'media')
+
+MEDIA_URL = '/media/'
+
+ADMIN_MEDIA_PREFIX = '/admin_media/'
+
+SECRET_KEY = '23aq#z2r&z(_1j^3b(s=wi+wn!ss3o9)a82hrvtyx5_p9*zvpb'
+
+SITE_ID = 1
+
+MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.contrib.sessions.middleware.SessionMiddleware',
+ 'django.contrib.auth.middleware.AuthenticationMiddleware',
+ 'django.middleware.doc.XViewMiddleware',
+ 'multilingual.flatpages.middleware.FlatpageFallbackMiddleware',
+)
+
+ROOT_URLCONF = 'testproject.urls'
+
+
+INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.admin',
+ 'django.contrib.sites',
+ 'multilingual',
+ 'multilingual.flatpages',
+ 'testproject',
+)
+
+TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.load_template_source',
+ 'django.template.loaders.app_directories.load_template_source',
+)
+
+TEMPLATE_CONTEXT_PROCESSORS = (
+ "django.core.context_processors.auth",
+ "django.core.context_processors.debug",
+ "django.core.context_processors.i18n",
+ "django.core.context_processors.media",
+ "multilingual.context_processors.multilingual",
+)
+
+TEMPLATE_DIRS = (
+ os.path.join(os.path.dirname(__file__), "templates"),
+)
No changes.
No changes.
@@ -0,0 +1,11 @@
+import unittest
+from testproject.tests.core import CoreTestCase
+from testproject.tests.flatpages import FlatpagesTestCase
+
+
+def suite():
+ # this must be changed!! and tests must happen for multiple configurations!
+ s = unittest.TestSuite()
+ s.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(CoreTestCase))
+ s.addTest(unittest.defaultTestLoader.loadTestsFromTestCase(FlatpagesTestCase))
+ return s
@@ -0,0 +1,24 @@
+from django.test import TestCase
+from multilingual.flatpages.models import MultilingualFlatPage
+from multilingual.utils import GLL
+
+class CoreTestCase(TestCase):
+ fixtures = ['testdata.json']
+
+ def test_read(self):
+ mfp = MultilingualFlatPage.objects.get(url='/test1/')
+ self.assertEqual(mfp.title_en, 'MLFP-Title1-en')
+ self.assertEqual(mfp.title_ja, 'MLFP-Title1-ja')
+ self.assertEqual(mfp.content_en, 'MLFP-Content1-en')
+ self.assertEqual(mfp.content_ja, 'MLFP-Content1-ja')
+
+ def test_gll(self):
+ mfp = MultilingualFlatPage.objects.get(url='/test2/')
+ GLL.lock('en')
+ self.assertEqual(mfp.title, 'MLFP-Title2-en')
+ self.assertEqual(mfp.content, 'MLFP-Content2-en')
+ GLL.release()
+ GLL.lock('ja')
+ self.assertEqual(mfp.title, 'MLFP-Title2-ja')
+ self.assertEqual(mfp.content, 'MLFP-Content2-ja')
+ GLL.release()
@@ -0,0 +1,12 @@
+from django.test import TestCase
+from django.contrib.sites.models import Site
+from multilingual.flatpages.models import MultilingualFlatPage
+
+class FlatpagesTestCase(TestCase):
+ fixtures = ['testdata.json']
+
+ def test_page(self):
+ response = self.client.get('/test1/')
+ self.assertEqual(response.status_code, 200)
+ response = self.client.get('/test2/')
+ self.assertEqual(response.status_code, 200)
View
@@ -0,0 +1,20 @@
+
+from django.conf.urls.defaults import patterns, include, handler500
+from django.conf import settings
+from django.contrib import admin
+admin.autodiscover()
+
+handler500 = 'django.views.defaults.server_error'
+handler404 = 'django.views.defaults.page_not_found'
+
+urlpatterns = patterns(
+ '',
+ (r'^admin/(.*)', admin.site.root),
+ (r'^accounts/login/$', 'django.contrib.auth.views.login'),
+)
+
+if settings.DEBUG:
+ urlpatterns += patterns('',
+ (r'^media/(?P<path>.*)$', 'django.views.static.serve',
+ {'document_root': settings.MEDIA_ROOT}),
+ )

0 comments on commit da095ce

Please sign in to comment.