Permalink
Browse files

easier to run tests

  • Loading branch information...
1 parent 2a7f559 commit b493b0a2ee3f720e4cfe8cb1a711aac97e1c4e9b @fivethreeo committed Sep 5, 2011
Showing with 121 additions and 15 deletions.
  1. +1 −0 requirements-12.txt
  2. +1 −0 requirements-13.txt
  3. +1 −0 requirements-trunk.txt
  4. +3 −0 requirements.txt
  5. +99 −0 runtests.sh
  6. +6 −5 simple_translation/test/run_tests.py
  7. +10 −10 simple_translation/tests.py
View
@@ -0,0 +1 @@
+Django==1.2.5
View
@@ -0,0 +1 @@
+Django==1.3
View
@@ -0,0 +1 @@
+-e git+http://github.com/django/django.git#egg=Django
View
@@ -0,0 +1,3 @@
+django-staticfiles
+coverage
+unittest-xml-reporting==1.2
View
@@ -0,0 +1,99 @@
+#!/bin/bash
+
+find . -name '*.pyc' -delete
+
+args=("$@")
+num_args=${#args[@]}
+index=0
+
+django=12
+reuse_env=true
+disable_coverage=true
+update_requirements=false
+
+python="python" # to ensure this script works if no python option is specified
+while [ "$index" -lt "$num_args" ]
+do
+case "${args[$index]}" in
+ "-f"|"--failfast")
+ failfast="--failfast"
+ ;;
+
+ "-r"|"--rebuild-env")
+ reuse_env=false
+ ;;
+
+ "-u"|"--update-requirements")
+ update_requirements=true
+ ;;
+
+ "-d"|"--django")
+ let "index = $index + 1"
+ django="${args[$index]}"
+ ;;
+
+ "-p"|"--python")
+ let "index = $index + 1"
+ python="${args[$index]}"
+ ;;
+
+ "-c"|"--with-coverage")
+ disable_coverage=false
+ ;;
+
+ "-h"|"--help")
+ echo ""
+ echo "usage:"
+ echo " runtests.sh"
+ echo ""
+ echo "flags:"
+ echo " -r, --rebuild-env - delete virtualenv and rebuild virtualenv before the tests"
+ echo " -u, --update-requirements - update requirements before the tests"
+ echo " -d, --django <version> - run tests against a django version, options: 12, 13 or trunk"
+ echo " -c, --with-coverage - enables coverage"
+ echo " -p, --python /path/to/python - python version to use to run the tests"
+ echo " -h, --help - display this help"
+ exit 1
+ ;;
+ esac
+let "index = $index + 1"
+done
+
+python_executeable=`which $python`
+
+echo "using python at: $python_executeable"
+
+venv="venv-$python-$django"
+
+if [ $reuse_env == false ]; then
+ rm -rf $venv
+ echo "deleted virtualenv: $venv"
+fi
+
+if [ ! -d $venv ]; then
+ echo "building virtualenv"
+ virtualenv $venv --distribute -p $python_executeable
+ update_requirements=true
+else
+ echo "reusing current virualenv: $venv"
+fi
+
+if [ $update_requirements == true ]; then
+ echo "updating requirements"
+ $venv/bin/pip install -r requirements-$django.txt
+ $venv/bin/pip install -r requirements.txt
+fi
+
+if [ $disable_coverage == false ]; then
+ $venv/bin/coverage run --rcfile=coveragerc setup.py test
+ retcode=$?
+ echo "build coverage reports"
+
+ $venv/bin/coverage xml --rcfile=coveragerc
+ $venv/bin/coverage html --rcfile=coveragerc
+ $venv/bin/coverage report -m --rcfile=coveragerc
+else
+ $venv/bin/python setup.py test
+ retcode=$?
+fi
+exit $retcode
@@ -38,7 +38,7 @@ def run_tests():
'django.contrib.sessions',
'django.contrib.admin',
'django.contrib.sites',
- 'django.contrib.staticfiles',
+ 'staticfiles',
'simple_translation',
'simple_translation.test.testapp'
),
@@ -50,9 +50,10 @@ def run_tests():
("de", "German"),
),
- SITE_ID = 1
-
-
+ SITE_ID = 1,
+ STATIC_URL='/some/url/',
+ TEST_RUNNER = 'xmlrunner.extra.djangotestrunner.XMLTestRunner',
+ TEST_OUTPUT_VERBOSE = True
)
from django.test.utils import get_runner
@@ -61,4 +62,4 @@ def run_tests():
sys.exit(failures)
if __name__ == '__main__':
- run_tests()
+ run_tests()
@@ -3,14 +3,10 @@
from django.conf import settings
from django.contrib.auth.models import User
from django.template import Template, Context
-from django.test.client import RequestFactory
from simple_translation.test.testcases import SimpleTranslationBaseTestCase
class SimpleTranslationTestCase(SimpleTranslationBaseTestCase):
-
- def setUp(self):
- self.request_factory = RequestFactory()
-
+
def test_01_test_translated_urls(self):
old_urlconf = settings.ROOT_URLCONF
@@ -154,18 +150,19 @@ def test_06_admin_edit_translated_entry(self):
# edit english(default)
response = self.client.get(edit_url)
+
self.assertEquals(response.status_code, 200)
- self.assertContains(response, 'class="simple-translation-current" name="en"' )
+ self.assertContains(response, 'simple-translation-current" name="en"' )
# edit english
response = self.client.get(edit_url, {'language': 'en'})
self.assertEquals(response.status_code, 200)
- self.assertContains(response, 'class="simple-translation-current" name="en"' )
+ self.assertContains(response, 'simple-translation-current" name="en"' )
# edit german
response = self.client.get(edit_url, {'language': 'de'})
self.assertEquals(response.status_code, 200)
- self.assertContains(response, 'class="simple-translation-current" name="de"' )
+ self.assertContains(response, 'simple-translation-current" name="de"' )
def test_07_test_changelist_description(self):
@@ -193,8 +190,11 @@ def test_08_test_filters(self):
de_title = self.create_entry_title(entry, title='german', language='de', published_at=published_at)
- request = self.request_factory.get('')
- request.LANGUAGE_CODE = 'en'
+ class MockRequest(object):
+ LANGUAGE_CODE = 'en'
+ REQUEST = {}
+
+ request = MockRequest()
ctxt = Context({'entry': entry, 'request': request})

0 comments on commit b493b0a

Please sign in to comment.