mirror of
https://github.com/QingdaoU/Spirit.git
synced 2025-01-01 09:31:48 +00:00
refactor test suite (for easy TDD)
This commit is contained in:
parent
b69caaceeb
commit
e88e3b5b67
@ -15,6 +15,7 @@ from .base import *
|
||||
DEBUG = True
|
||||
|
||||
TEMPLATES[0]['OPTIONS']['debug'] = True
|
||||
# TEMPLATES[0]['OPTIONS']['string_if_invalid'] = '{{ %s }}' # Some Django templates relies on this being the default
|
||||
|
||||
ADMINS = (('John', 'john@example.com'), ) # Log email to console when DEBUG = False
|
||||
|
||||
|
23
runtests.py
23
runtests.py
@ -18,7 +18,7 @@ if EXAMPLE:
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'example.project.settings.test' # pragma: no cover
|
||||
else:
|
||||
# Run tests with tests settings
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'tests.settings'
|
||||
os.environ['DJANGO_SETTINGS_MODULE'] = 'spirit.settings_tests'
|
||||
|
||||
|
||||
def log_warnings():
|
||||
@ -31,7 +31,26 @@ def run_tests():
|
||||
sys.stdout.write("\nRunning spirit test suite, using settings %(settings)r\n\n"
|
||||
% {"settings": os.environ['DJANGO_SETTINGS_MODULE'], })
|
||||
test_runner = DiscoverRunner()
|
||||
failures = test_runner.run_tests(["tests", ])
|
||||
# todo: remove in spirit 0.4
|
||||
failures = test_runner.run_tests([
|
||||
"spirit.apps.admin",
|
||||
"spirit.apps.category",
|
||||
"spirit.apps.comment",
|
||||
"spirit.apps.comment.bookmark",
|
||||
"spirit.apps.comment.flag",
|
||||
"spirit.apps.comment.history",
|
||||
"spirit.apps.comment.like",
|
||||
"spirit.apps.core",
|
||||
"spirit.apps.search",
|
||||
"spirit.apps.topic",
|
||||
"spirit.apps.topic.favorite",
|
||||
"spirit.apps.topic.moderate",
|
||||
"spirit.apps.topic.notification",
|
||||
"spirit.apps.topic.poll",
|
||||
"spirit.apps.topic.private",
|
||||
"spirit.apps.topic.unread",
|
||||
"spirit.apps.user",
|
||||
])
|
||||
sys.exit(failures)
|
||||
|
||||
|
||||
|
@ -9,7 +9,7 @@ from django.core.exceptions import PermissionDenied
|
||||
from django.contrib.auth import get_user_model
|
||||
from djconfig.utils import override_djconfig
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.admin.views import dashboard
|
||||
from spirit.apps.admin import views
|
||||
from spirit.apps.category.admin import views as category_views
|
||||
@ -23,7 +23,6 @@ from spirit.apps.comment.flag.admin.forms import CommentFlagForm
|
||||
from spirit.apps.user.admin.forms import UserForm, UserProfileForm
|
||||
from spirit.apps.category.admin.forms import CategoryForm
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
@ -10,7 +10,7 @@ from django.core.cache import cache
|
||||
from django.utils import timezone
|
||||
from djconfig.utils import override_djconfig
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.topic.models import Topic
|
||||
from spirit.apps.comment.bookmark.models import CommentBookmark
|
||||
|
@ -8,7 +8,7 @@ from django.template import Template, Context
|
||||
from django.core.cache import cache
|
||||
from djconfig import config
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.comment.bookmark.models import CommentBookmark
|
||||
from spirit.apps.topic.signals import topic_viewed
|
||||
from spirit.apps.comment.bookmark.forms import BookmarkForm
|
@ -6,7 +6,7 @@ from django.test import TestCase
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.cache import cache
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.comment.flag.models import Flag, CommentFlag
|
||||
from spirit.apps.comment.flag.forms import FlagForm
|
||||
|
@ -7,7 +7,7 @@ from django.core.urlresolvers import reverse
|
||||
from django.core.cache import cache
|
||||
from djconfig.utils import override_djconfig
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.comment.history.models import CommentHistory
|
||||
from spirit.apps.comment.signals import comment_pre_update, comment_post_update
|
||||
|
@ -7,7 +7,7 @@ from django.core.urlresolvers import reverse
|
||||
from django.template import Template, Context
|
||||
from django.core.cache import cache
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.comment.like.models import CommentLike
|
||||
from spirit.apps.comment.like.forms import LikeForm
|
||||
from spirit.apps.comment.like.tags import render_like_form
|
@ -16,7 +16,7 @@ from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.test.utils import override_settings
|
||||
from django.utils.six import BytesIO
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.comment.models import Comment
|
||||
from spirit.apps.comment.like.signals import comment_like_post_create, comment_like_post_delete
|
||||
from spirit.apps.topic.moderate.signals import topic_post_moderate
|
1
spirit/apps/core/tests/__init__.py
Normal file
1
spirit/apps/core/tests/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
__author__ = 'esteban'
|
@ -5,7 +5,7 @@ from __future__ import unicode_literals
|
||||
from django.test import TestCase
|
||||
from django.template import Template, Context
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
|
||||
|
||||
class GravatarTemplateTagTests(TestCase):
|
@ -34,7 +34,7 @@ from spirit.apps.user.utils.tokens import UserActivationTokenGenerator, UserEmai
|
||||
from spirit.apps.user.utils.email import send_activation_email, send_email_change_email, sender
|
||||
from spirit.apps.user.utils import email
|
||||
from spirit.apps.core.tags import time as ttags_utils
|
||||
from . import utils as test_utils
|
||||
from spirit.apps.core.tests import utils as test_utils
|
||||
from spirit.apps.core.tags.messages import render_messages
|
||||
from spirit.apps.core.utils.markdown import Markdown, quotify
|
||||
|
@ -4,7 +4,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from .models.auto_slug import AutoSlugPopulateFromModel, AutoSlugModel, AutoSlugDefaultModel, \
|
||||
from spirit.apps.core.tests.models import AutoSlugPopulateFromModel, AutoSlugModel, AutoSlugDefaultModel, \
|
||||
AutoSlugBadPopulateFromModel
|
||||
|
||||
|
@ -5,13 +5,11 @@ from __future__ import unicode_literals
|
||||
from django.core.cache import cache
|
||||
from django.test import TestCase, RequestFactory
|
||||
from django.template import Template, Context
|
||||
|
||||
from django.test.utils import override_settings
|
||||
from django.http import Http404
|
||||
|
||||
from django.core.paginator import Page, Paginator
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.comment.models import Comment
|
||||
import spirit.apps.core.utils.paginator
|
||||
from spirit.apps.core.utils.paginator import YTPaginator, InvalidPage, YTPage
|
@ -11,13 +11,12 @@ from django.core.management import call_command
|
||||
from haystack.query import SearchQuerySet
|
||||
from djconfig.utils import override_djconfig
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.topic.models import Topic
|
||||
from spirit.apps.search.forms import BasicSearchForm, AdvancedSearchForm
|
||||
from spirit.apps.search.tags import render_search_form
|
||||
from spirit.apps.search.search_indexes import TopicIndex
|
||||
|
||||
|
||||
HAYSTACK_TEST = {
|
||||
'default': {
|
||||
'ENGINE': 'haystack.backends.simple_backend.SimpleEngine',
|
@ -6,7 +6,7 @@ from django.test import TestCase
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.core.cache import cache
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.topic.favorite.models import TopicFavorite
|
||||
from spirit.apps.topic.favorite.forms import FavoriteForm
|
||||
|
@ -6,7 +6,7 @@ from django.test import TestCase
|
||||
from django.core.cache import cache
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.comment.models import CLOSED, UNCLOSED, PINNED, UNPINNED
|
||||
from spirit.apps.topic.models import Topic
|
||||
from spirit.apps.topic.moderate.signals import topic_post_moderate
|
@ -13,7 +13,7 @@ from django.template import Template, Context
|
||||
from django.utils import timezone
|
||||
from djconfig.utils import override_djconfig
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.topic.private.models import TopicPrivate
|
||||
from spirit.apps.topic.notification.models import TopicNotification, COMMENT, MENTION
|
||||
from spirit.apps.comment.signals import comment_posted
|
@ -8,13 +8,12 @@ from django.core.cache import cache
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.template import Template, Context
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.topic.poll.models import TopicPoll, TopicPollChoice, TopicPollVote
|
||||
from spirit.apps.topic.poll.forms import TopicPollForm, TopicPollChoiceFormSet, TopicPollVoteManyForm
|
||||
from spirit.apps.topic.poll.signals import topic_poll_post_vote, topic_poll_pre_vote
|
||||
from spirit.apps.topic.poll.tags import render_poll_form
|
||||
|
||||
|
||||
User = get_user_model()
|
||||
|
||||
|
@ -13,7 +13,7 @@ from django.utils import six
|
||||
from django.utils import timezone
|
||||
from djconfig.utils import override_djconfig
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.category.models import Category
|
||||
from spirit.apps.topic.private.models import TopicPrivate
|
||||
from spirit.apps.topic.private.forms import TopicForPrivateForm, TopicPrivateInviteForm,\
|
@ -11,7 +11,7 @@ from django.utils import timezone
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from djconfig.utils import override_djconfig
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.comment.models import MOVED
|
||||
from spirit.apps.topic.models import Topic
|
||||
from spirit.apps.comment.signals import comment_posted, comment_moved
|
@ -6,7 +6,7 @@ from django.core.cache import cache
|
||||
from django.test import TestCase, RequestFactory
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.topic.unread.models import TopicUnread
|
||||
from spirit.apps.topic.signals import topic_viewed
|
||||
from spirit.apps.comment.signals import comment_posted
|
@ -12,9 +12,10 @@ from django.core import mail
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.utils import timezone
|
||||
from django.test.utils import override_settings
|
||||
from django.core.urlresolvers import NoReverseMatch
|
||||
from djconfig.utils import override_djconfig
|
||||
|
||||
from . import utils
|
||||
from spirit.apps.core.tests import utils
|
||||
from spirit.apps.user.forms import UserProfileForm, EmailChangeForm, UserForm, EmailCheckForm
|
||||
from spirit.apps.user.auth.forms import RegistrationForm, ResendActivationForm
|
||||
from spirit.apps.user.auth.backends import EmailAuthBackend
|
||||
@ -441,12 +442,18 @@ class UserViewTest(TestCase):
|
||||
|
||||
def test_admin_login(self):
|
||||
"""
|
||||
redirect to regular user login
|
||||
if fails, make sure you added:
|
||||
Redirect to regular user login (optional)
|
||||
make sure you added:
|
||||
admin.site.login = login_required(admin.site.login)
|
||||
to urls.py (the one in your project's root)
|
||||
"""
|
||||
response = self.client.get(reverse('admin:login'))
|
||||
# TODO: document that devs should be doing this.
|
||||
try:
|
||||
url = reverse('admin:login')
|
||||
except NoReverseMatch:
|
||||
return
|
||||
|
||||
response = self.client.get(url)
|
||||
expected_url = reverse("spirit:user-login") + "?next=" + reverse('admin:login')
|
||||
self.assertRedirects(response, expected_url, status_code=302)
|
||||
|
@ -13,10 +13,10 @@ from spirit.settings import *
|
||||
SECRET_KEY = 'TEST'
|
||||
|
||||
INSTALLED_APPS += (
|
||||
'tests',
|
||||
'spirit.apps.core.tests',
|
||||
)
|
||||
|
||||
ROOT_URLCONF = 'tests.urls'
|
||||
ROOT_URLCONF = 'spirit.urls'
|
||||
|
||||
USE_TZ = True
|
||||
|
@ -1,57 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import models, migrations
|
||||
|
||||
import spirit.apps.core.utils.models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='AutoSlugBadPopulateFromModel',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('slug', spirit.apps.core.utils.models.AutoSlugField(populate_from=b'bad')),
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='AutoSlugDefaultModel',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('slug', spirit.apps.core.utils.models.AutoSlugField(default=b'foo')),
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='AutoSlugModel',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('slug', spirit.apps.core.utils.models.AutoSlugField()),
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
migrations.CreateModel(
|
||||
name='AutoSlugPopulateFromModel',
|
||||
fields=[
|
||||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
|
||||
('title', models.CharField(max_length=255, blank=True)),
|
||||
('slug', spirit.apps.core.utils.models.AutoSlugField(populate_from=b'title')),
|
||||
],
|
||||
options={
|
||||
},
|
||||
bases=(models.Model,),
|
||||
),
|
||||
]
|
@ -1,13 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from .auto_slug import (
|
||||
AutoSlugPopulateFromModel, AutoSlugModel,
|
||||
AutoSlugDefaultModel, AutoSlugBadPopulateFromModel
|
||||
)
|
||||
|
||||
__all__ = [
|
||||
'AutoSlugPopulateFromModel', 'AutoSlugModel',
|
||||
'AutoSlugDefaultModel', 'AutoSlugBadPopulateFromModel'
|
||||
]
|
@ -1,26 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from django.db import models
|
||||
|
||||
from spirit.apps.core.utils.models import AutoSlugField
|
||||
|
||||
|
||||
class AutoSlugModel(models.Model):
|
||||
|
||||
slug = AutoSlugField(max_length=50)
|
||||
|
||||
|
||||
class AutoSlugDefaultModel(models.Model):
|
||||
|
||||
slug = AutoSlugField(max_length=50, default="foo")
|
||||
|
||||
|
||||
class AutoSlugPopulateFromModel(models.Model):
|
||||
|
||||
title = models.CharField(max_length=255, blank=True)
|
||||
slug = AutoSlugField(populate_from='title', max_length=50)
|
||||
|
||||
|
||||
class AutoSlugBadPopulateFromModel(models.Model):
|
||||
|
||||
slug = AutoSlugField(populate_from='bad', max_length=50)
|
@ -1,18 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.conf.urls import include, url
|
||||
from django.contrib import admin
|
||||
|
||||
import spirit.urls
|
||||
|
||||
# Override admin login for security purposes
|
||||
from django.contrib.auth.decorators import login_required
|
||||
admin.site.login = login_required(admin.site.login)
|
||||
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^', include(spirit.urls)),
|
||||
url(r'^admin/', include(admin.site.urls)),
|
||||
]
|
Loading…
Reference in New Issue
Block a user