Skip to content

Commit

Permalink
Merge 2335844 into 0766dc6
Browse files Browse the repository at this point in the history
  • Loading branch information
dsanders11 committed May 2, 2016
2 parents 0766dc6 + 2335844 commit 1c53bf7
Show file tree
Hide file tree
Showing 29 changed files with 54 additions and 53 deletions.
15 changes: 0 additions & 15 deletions newsletter/tests/__init__.py

This file was deleted.

57 changes: 29 additions & 28 deletions runtests.py
@@ -1,38 +1,39 @@
#!/usr/bin/env python # Run tests for application
# Source: https://stackoverflow.com/questions/3841725/how-to-launch-tests-for-django-reusable-app
#!/usr/bin/env python

import os
import sys
from argparse import ArgumentParser

import django
from django.core.management.commands.test import Command as TestCommand

from django.test.runner import DiscoverRunner

def setup_django():
""" Setup Django for testing using the test_project directory """

# Any parameter should be optional as automated tests do not set parameters
def runtests(options=None):
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
test_project_dir = os.path.join(os.path.dirname(__file__), 'test_project')
sys.path.insert(0, test_project_dir)

os.environ['DJANGO_SETTINGS_MODULE'] = 'test_project.settings'
django.setup()

verbosity = options.verbosity if options else 1
failfast = options.failfast if options else False
test_runner = DiscoverRunner(verbosity=verbosity, failfast=failfast)

labels = options.labels if options else []
failures = test_runner.run_tests(labels or ['newsletter'])
sys.exit(failures)


if __name__ == '__main__':
parser = ArgumentParser(description="Run the django-newsletter test suite.")
parser.add_argument('labels', nargs='*', metavar='label',
help='Optional path(s) to test modules; e.g. "newsletter.tests.test_mailing".')
parser.add_argument(
'-v', '--verbosity', default=1, type=int, choices=[0, 1, 2, 3],
help='Verbosity level; 0=minimal output, 1=normal output, 2=all output')
parser.add_argument(
'--failfast', action='store_true', dest='failfast', default=False,
help='Tells Django to stop running the test suite after first failed test.')
options = parser.parse_args()
runtests(options)

def run_tests():
""" Run tests via setuptools, all tests with no special options """

setup_django()

# Bypass argument parsing and run the test command manually with no args
TestCommand().handle()

sys.exit(0) # TestCommand exits itself on failure, we only exit on success


if __name__ == "__main__":
setup_django()

# Command expects to be called via 'manage.py test' so
# add the extra argument so that it can parse correctly
sys.argv.insert(1, 'test')

# Run the test command with argv to get all the argument goodies
TestCommand().run_from_argv(sys.argv)
4 changes: 2 additions & 2 deletions setup.py
Expand Up @@ -58,7 +58,7 @@
author='Mathijs de Bruin',
author_email='mathijs@mathijsfietst.nl',
url='http://github.com/dokterbob/django-newsletter/',
packages=find_packages(),
packages=find_packages(exclude=("tests", "test_project")),
include_package_data=True,
classifiers=(
'Development Status :: 6 - Mature',
Expand All @@ -73,6 +73,6 @@
'Programming Language :: Python :: 3.5',
'Topic :: Utilities'
),
test_suite='runtests.runtests',
test_suite='runtests.run_tests',
tests_require=TEST_REQUIREMENTS
)
Empty file.
Expand Up @@ -32,7 +32,7 @@
'django.contrib.messages.middleware.MessageMiddleware',
]

ROOT_URLCONF = 'tests.urls'
ROOT_URLCONF = 'test_project.urls'

SITE_ID = 1

Expand Down
File renamed without changes.
File renamed without changes.
15 changes: 15 additions & 0 deletions tests/__init__.py
@@ -0,0 +1,15 @@
from .test_web import (
AnonymousNewsletterListTestCase, UserNewsletterListTestCase,
SubscribeTestCase, UserSubscribeTestCase,
InvisibleAnonymousSubscribeTestCase, InvisibleUserSubscribeTestCase,
AnonymousSubscribeTestCase, ArchiveTestcase,
ActivationEmailSentUrlTestCase, ActionActivatedUrlTestCase
)

from .test_mailing import (
MailingTestCase, ArticleTestCase, CreateSubmissionTestCase,
SubmitSubmissionTestCase, SubscriptionTestCase, HtmlEmailsTestCase,
TextOnlyEmailsTestCase, TemplateOverridesTestCase
)

from .test_settings import SettingsTestCase
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions newsletter/tests/test_mailing.py → tests/test_mailing.py
Expand Up @@ -10,10 +10,10 @@
from django.utils.six.moves import range
from django.utils.timezone import now

from ..models import (
from newsletter.models import (
Newsletter, Subscription, Submission, Message, Article, get_default_sites
)
from ..utils import ACTIONS
from newsletter.utils import ACTIONS

from .utils import MailTestCase, UserTestCase, template_exists

Expand Down
File renamed without changes.
10 changes: 5 additions & 5 deletions newsletter/tests/test_web.py → tests/test_web.py
Expand Up @@ -24,11 +24,11 @@

from django.test.utils import override_settings, patch_logger

from ..models import (
from newsletter.models import (
Newsletter, Subscription, Submission, Message, get_default_sites
)

from ..forms import UpdateForm
from newsletter.forms import UpdateForm

from .utils import MailTestCase, UserTestCase, WebTestCase, ComparingTestCase

Expand Down Expand Up @@ -610,7 +610,7 @@ def test_subscribe_request_post_error(self):
"""

with override_settings(
EMAIL_BACKEND='newsletter.tests.utils.FailingEmailBackend'
EMAIL_BACKEND='tests.utils.FailingEmailBackend'
):
with patch_logger('newsletter.views', 'error') as messages:
response = self.client.post(
Expand Down Expand Up @@ -885,7 +885,7 @@ def test_unsubscribe_request_post_error(self):
subscription.save()

with override_settings(
EMAIL_BACKEND='newsletter.tests.utils.FailingEmailBackend'
EMAIL_BACKEND='tests.utils.FailingEmailBackend'
):
with patch_logger('newsletter.views', 'error') as messages:
response = self.client.post(
Expand Down Expand Up @@ -1016,7 +1016,7 @@ def test_update_request_post_error(self):
subscription.save()

with override_settings(
EMAIL_BACKEND='newsletter.tests.utils.FailingEmailBackend'
EMAIL_BACKEND='tests.utils.FailingEmailBackend'
):


Expand Down
File renamed without changes.

0 comments on commit 1c53bf7

Please sign in to comment.