Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
  • 3 commits
  • 12 files changed
  • 0 comments
  • 1 contributor
4 .gitignore
@@ -4,5 +4,5 @@ build
4 4 dist
5 5 *.egg-info
6 6 *.sqlite
7   -tests/htmlcov/
8   -tests/.coverage
  7 +.coverage
  8 +coverage
14 Makefile
... ... @@ -1,5 +1,6 @@
1 1 test:
2   - make -C tests test
  2 + python quicktest.py webmaster_verification
  3 + python quicktest.py webmaster_verification --multicode
3 4
4 5 install:
5 6 python setup.py install
@@ -15,7 +16,12 @@ upload:
15 16
16 17 clean:
17 18 rm -rf dist build *.egg-info django-webmaster-verification-*
18   - rm -rf tests/htmlcov tests/.coverage
  19 + rm -rf .coverage coverage
19 20
20   -coverage:
21   - make -C tests htmlcov
  21 +.PHONY: .coverage
  22 +.coverage:
  23 + coverage run --source=webmaster_verification quicktest.py webmaster_verification
  24 + coverage run --source=webmaster_verification quicktest.py webmaster_verification --multicode
  25 +
  26 +coverage: .coverage
  27 + coverage html -d coverage
4 README.rst
Source Rendered
@@ -84,6 +84,10 @@ For **Yandex** only the `.txt` file method is supported, but adding support for
84 84 Changelog
85 85 =========
86 86
  87 +0.2.1 ()
  88 +--------
  89 +- Refactor the test project to use the modern structure
  90 +
87 91 0.2 (2013-02-16)
88 92 ----------------
89 93 - Python 3.2 support
110 quicktest.py
... ... @@ -0,0 +1,110 @@
  1 +"""
  2 +Source: http://datadesk.latimes.com/posts/2012/06/test-your-django-app-with-travisci/
  3 +Slightly modified by Nicolas Kuttler.
  4 +"""
  5 +
  6 +import os
  7 +import sys
  8 +import argparse
  9 +
  10 +from django.conf import settings
  11 +
  12 +
  13 +class QuickDjangoTest(object):
  14 + """
  15 + A quick way to run the Django test suite without a fully-configured project.
  16 +
  17 + Example usage:
  18 +
  19 + >>> QuickDjangoTest('app1', 'app2')
  20 +
  21 + Based on a script published by Lukasz Dziedzia at:
  22 + http://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app
  23 + """
  24 + DIRNAME = os.path.dirname(__file__)
  25 + INSTALLED_APPS = (
  26 + 'django.contrib.auth',
  27 + 'django.contrib.contenttypes',
  28 + 'django.contrib.sessions',
  29 + 'django.contrib.admin',
  30 + )
  31 + WEBMASTER_VERIFICATION = {}
  32 +
  33 + def __init__(self, options, *args, **kwargs):
  34 + self.apps = options.apps
  35 + self.multicode = options.multicode
  36 + self._tests()
  37 +
  38 + def _tests(self):
  39 + """
  40 + Fire up the Django test suite developed for version 1.2
  41 + """
  42 + settings.configure(
  43 + DEBUG = True,
  44 + DATABASES = {
  45 + 'default': {
  46 + 'ENGINE': 'django.db.backends.sqlite3',
  47 + 'NAME': os.path.join(self.DIRNAME, 'database.db'),
  48 + 'USER': '',
  49 + 'PASSWORD': '',
  50 + 'HOST': '',
  51 + 'PORT': '',
  52 + }
  53 + },
  54 + INSTALLED_APPS = self.INSTALLED_APPS + tuple(self.apps),
  55 + WEBMASTER_VERIFICATION = self._get_wv_config(),
  56 + ROOT_URLCONF = 'test_project.urls',
  57 + TEMPLATE_DIRS = (
  58 + './test_project/templates/',
  59 + ),
  60 + )
  61 + from django.test.simple import DjangoTestSuiteRunner
  62 + failures = DjangoTestSuiteRunner().run_tests(self.apps, verbosity=1)
  63 + if failures:
  64 + sys.exit(failures)
  65 +
  66 + def _get_wv_config(self, key='default'):
  67 + if self.multicode:
  68 + conf = {
  69 + 'bing': 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
  70 + 'google': (
  71 + 'ffffffffffffffff',
  72 + 'aaaaaaaaaaaaaaaa',
  73 + ),
  74 + 'majestic': (
  75 + 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
  76 + 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
  77 + ),
  78 + 'yandex': (
  79 + 'f0f0f0f0f0f0f0f0',
  80 + '1919191919191919',
  81 + ),
  82 + }
  83 + else:
  84 + conf = {
  85 + 'bing': 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
  86 + 'google': 'ffffffffffffffff',
  87 + 'majestic': 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
  88 + 'yandex': 'f0f0f0f0f0f0f0f0',
  89 + }
  90 + return conf
  91 +
  92 +
  93 +if __name__ == '__main__':
  94 + """
  95 + What do when the user hits this file from the shell.
  96 +
  97 + Example usage:
  98 +
  99 + $ python quicktest.py app1 app2
  100 +
  101 + """
  102 + parser = argparse.ArgumentParser(
  103 + usage="[args]",
  104 + description="Run Django tests on the provided applications."
  105 + )
  106 + parser.add_argument('apps', nargs='+', type=str)
  107 + parser.add_argument('--multicode', action="store_true",
  108 + help='run the multicode tests')
  109 + options = parser.parse_args()
  110 + QuickDjangoTest(options)
0  tests/test_project/__init__.py → test_project/__init__.py
File renamed without changes
2  tests/test_project/settings.py → test_project/settings.py
... ... @@ -1,6 +1,6 @@
1 1 import os
2 2
3   -TESTS_DIR = os.getcwd()
  3 +TESTS_DIR = os.path.dirname(os.getcwd())
4 4
5 5 DEBUG = True
6 6 TEMPLATE_DEBUG = True
4 test_project/settings_multicode.py
... ... @@ -0,0 +1,4 @@
  1 +from settings import *
  2 +
  3 +# And override what we want
  4 +WEBMASTER_VERIFICATION = {
0  tests/test_project/templates/404.html → test_project/templates/404.html
File renamed without changes
3  tests/test_project/urls.py → test_project/urls.py
... ... @@ -1,8 +1,5 @@
1 1 from django.conf.urls.defaults import patterns, include, url
2 2
3   -from django.views.generic import TemplateView
4   -from webmaster_verification.views import BingVerificationView
5   -
6 3 urlpatterns = patterns('',
7 4 url(r'', include('webmaster_verification.urls')),
8 5 )
13 tests/Makefile
... ... @@ -1,13 +0,0 @@
1   -.PHONY: test
2   -test: db.sqlite
3   - python manage.py test --failfast --settings=test_project.settings_multicode
4   - python manage.py test --failfast
5   -
6   -db.sqlite:
7   - python manage.py syncdb --noinput
8   -
9   -.coverage:
10   - coverage run --source=webmaster_verification manage.py test
11   -
12   -htmlcov: .coverage
13   - coverage html
9 tests/manage.py
... ... @@ -1,9 +0,0 @@
1   -#!/usr/bin/env python
2   -import os
3   -import sys
4   -from django.core.management import execute_from_command_line
5   -
6   -if __name__ == "__main__":
7   - os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
8   - sys.path.insert(0, os.path.abspath('%s/..' % os.getcwd()))
9   - execute_from_command_line(sys.argv)
28 tests/test_project/settings_multicode.py
... ... @@ -1,28 +0,0 @@
1   -import sys
2   -
3   -from django.utils.importlib import import_module
4   -
5   -
6   -# Import default settings
7   -settings_default = import_module('test_project.settings')
8   -settings_multicode = sys.modules[__name__]
9   -for key in dir(settings_default):
10   - if not key.startswith('__'):
11   - setattr(settings_multicode, key, getattr(settings_default, key))
12   -
13   -# And override what we want
14   -WEBMASTER_VERIFICATION = {
15   - 'google': (
16   - 'ffffffffffffffff',
17   - 'aaaaaaaaaaaaaaaa',
18   - ),
19   - 'bing': 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
20   - 'majestic': (
21   - 'FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF',
22   - 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',
23   - ),
24   - 'yandex': (
25   - 'f0f0f0f0f0f0f0f0',
26   - '1919191919191919',
27   - ),
28   -}

No commit comments for this range

Something went wrong with that request. Please try again.