Skip to content
Browse files

Refactor testing

  • Loading branch information...
1 parent 663dcda commit 7cbe3ca7636e6c13889eb3dd9c357a923966d8a0 @nkuttler committed
View
4 .gitignore
@@ -4,5 +4,5 @@ build
dist
*.egg-info
*.sqlite
-tests/htmlcov/
-tests/.coverage
+.coverage
+coverage
View
14 Makefile
@@ -1,5 +1,6 @@
test:
- make -C tests test
+ python quicktest.py webmaster_verification
+ python quicktest.py webmaster_verification --multicode
install:
python setup.py install
@@ -15,7 +16,12 @@ upload:
clean:
rm -rf dist build *.egg-info django-webmaster-verification-*
- rm -rf tests/htmlcov tests/.coverage
+ rm -rf .coverage coverage
-coverage:
- make -C tests htmlcov
+.PHONY: .coverage
+.coverage:
+ coverage run --source=webmaster_verification quicktest.py webmaster_verification
+ coverage run --source=webmaster_verification quicktest.py webmaster_verification --multicode
+
+coverage: .coverage
+ coverage html -d coverage
View
110 quicktest.py
@@ -0,0 +1,110 @@
+"""
+Source: http://datadesk.latimes.com/posts/2012/06/test-your-django-app-with-travisci/
+Slightly modified by Nicolas Kuttler.
+"""
+
+import os
+import sys
+import argparse
+
+from django.conf import settings
+
+
+class QuickDjangoTest(object):
+ """
+ A quick way to run the Django test suite without a fully-configured project.
+
+ Example usage:
+
+ >>> QuickDjangoTest('app1', 'app2')
+
+ Based on a script published by Lukasz Dziedzia at:
+ http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app
+ """
+ DIRNAME = os.path.dirname(__file__)
+ INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sessions',
+ 'django.contrib.admin',
+ )
+ WEBMASTER_VERIFICATION = {}
+
+ def __init__(self, options, *args, **kwargs):
+ self.apps = options.apps
+ self.multicode = options.multicode
+ self._tests()
+
+ def _tests(self):
+ """
+ Fire up the Django test suite developed for version 1.2
+ """
+ settings.configure(
+ DEBUG = True,
+ DATABASES = {
+ 'default': {
+ 'ENGINE': 'django.db.backends.sqlite3',
+ 'NAME': os.path.join(self.DIRNAME, 'database.db'),
+ 'USER': '',
+ 'PASSWORD': '',
+ 'HOST': '',
+ 'PORT': '',
+ }
+ },
+ INSTALLED_APPS = self.INSTALLED_APPS + tuple(self.apps),
+ WEBMASTER_VERIFICATION = self._get_wv_config(),
+ ROOT_URLCONF = 'test_project.urls',
+ TEMPLATE_DIRS = (
+ './test_project/templates/',
+ ),
+ )
+ from django.test.simple import DjangoTestSuiteRunner
+ failures = DjangoTestSuiteRunner().run_tests(self.apps, verbosity=1)
+ if failures:
+ sys.exit(failures)
+
+ def _get_wv_config(self, key='default'):
+ if self.multicode:
+ conf = {
+ 'bing': 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
+ 'google': (
+ 'ffffffffffffffff',
+ 'aaaaaaaaaaaaaaaa',
+ ),
+ 'majestic': (
+ 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
+ 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
+ ),
+ 'yandex': (
+ 'f0f0f0f0f0f0f0f0',
+ '1919191919191919',
+ ),
+ }
+ else:
+ conf = {
+ 'bing': 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
+ 'google': 'ffffffffffffffff',
+ 'majestic': 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
+ 'yandex': 'f0f0f0f0f0f0f0f0',
+ }
+ return conf
+
+
+if __name__ == '__main__':
+ """
+ What do when the user hits this file from the shell.
+
+ Example usage:
+
+ $ python quicktest.py app1 app2
+
+ """
+ parser = argparse.ArgumentParser(
+ usage="[args]",
+ description="Run Django tests on the provided applications."
+ )
+ parser.add_argument('apps', nargs='+', type=str)
+ parser.add_argument('--multicode', action="store_true",
+ help='run the multicode tests')
+ options = parser.parse_args()
+ QuickDjangoTest(options)
View
0 tests/test_project/test_project/__init__.py → test_project/__init__.py
File renamed without changes.
View
0 tests/test_project/test_project/settings.py → test_project/settings.py
File renamed without changes.
View
4 test_project/settings_multicode.py
@@ -0,0 +1,4 @@
+from settings import *
+
+# And override what we want
+WEBMASTER_VERIFICATION = {
View
0 tests/test_project/templates/404.html → test_project/templates/404.html
File renamed without changes.
View
0 tests/test_project/test_project/urls.py → test_project/urls.py
File renamed without changes.
View
8 tests/Makefile
@@ -1,8 +0,0 @@
-test:
- make -C test_project test
-
-.coverage:
- coverage run --source=webmaster_verification manage.py test
-
-htmlcov: .coverage
- coverage html
View
4 tests/test_project/Makefile
@@ -1,4 +0,0 @@
-.PHONY: test
-test:
- python manage.py test --failfast --settings=test_project.settings_multicode
- python manage.py test --failfast
View
10 tests/test_project/manage.py
@@ -1,10 +0,0 @@
-#!/usr/bin/env python
-import os
-import sys
-
-if __name__ == "__main__":
- os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
-
- from django.core.management import execute_from_command_line
-
- execute_from_command_line(sys.argv)
View
18 tests/test_project/test_project/settings_multicode.py
@@ -1,18 +0,0 @@
-from settings import *
-
-# And override what we want
-WEBMASTER_VERIFICATION = {
- 'google': (
- 'ffffffffffffffff',
- 'aaaaaaaaaaaaaaaa',
- ),
- 'bing': 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
- 'majestic': (
- 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
- 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
- ),
- 'yandex': (
- 'f0f0f0f0f0f0f0f0',
- '1919191919191919',
- ),
-}

0 comments on commit 7cbe3ca

Please sign in to comment.
Something went wrong with that request. Please try again.