This commit is contained in:
Ricky Rosario 2015-03-19 14:30:37 -04:00
Родитель 349f970536
Коммит d07f5537a3
32 изменённых файлов: 61 добавлений и 65 удалений

Просмотреть файл

@ -98,9 +98,6 @@ cover the new functionality. All apps have a ``tests`` module where
tests should go. They will be discovered automatically by the test
runner as long as the look like a test.
* Avoid naming test files ``test_utils.py``, since we use a library
with the same name. Use ``test__utils.py`` instead.
* If you're expecting ``reverse`` to return locales in the URL, use
``LocalizingClient`` instead of the default client for the
``TestCase`` class.

Просмотреть файл

@ -1,6 +1,6 @@
from django.contrib.contenttypes.models import ContentType
from django.test.client import RequestFactory
import test_utils
from authority.models import Permission
from nose.tools import eq_
@ -21,7 +21,7 @@ class AccessTests(TestCase):
"""Test stuff in access/__init__.py"""
def setUp(self):
url = reverse('forums.threads', args=[u'test-forum'])
self.context = {'request': test_utils.RequestFactory().get(url)}
self.context = {'request': RequestFactory().get(url)}
def test_admin_perm_thread(self):
"""Super user can do anything on any forum."""

Просмотреть файл

@ -1,7 +1,7 @@
from django.contrib.auth.models import AnonymousUser
from django.http import HttpResponse
from django.test.client import RequestFactory
import test_utils
from nose.tools import eq_
from kitsune.access.decorators import (
@ -16,21 +16,21 @@ def simple_view(request):
class LogoutRequiredTestCase(TestCase):
def test_logged_out_default(self):
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.user = AnonymousUser()
view = logout_required(simple_view)
response = view(request)
eq_(200, response.status_code)
def test_logged_in_default(self):
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.user = user(save=True)
view = logout_required(simple_view)
response = view(request)
eq_(302, response.status_code)
def test_logged_in_argument(self):
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.user = user(save=True)
view = logout_required('/bar')(simple_view)
response = view(request)
@ -39,7 +39,7 @@ class LogoutRequiredTestCase(TestCase):
def test_no_redirect_ajax(self):
"""Ajax requests should not redirect."""
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
request.user = user(save=True)
view = logout_required(simple_view)
@ -49,7 +49,7 @@ class LogoutRequiredTestCase(TestCase):
class LoginRequiredTestCase(TestCase):
def test_logged_out_default(self):
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.user = AnonymousUser()
view = login_required(simple_view)
response = view(request)
@ -57,7 +57,7 @@ class LoginRequiredTestCase(TestCase):
def test_logged_in_default(self):
"""Active user login."""
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.user = user(save=True)
view = login_required(simple_view)
response = view(request)
@ -65,7 +65,7 @@ class LoginRequiredTestCase(TestCase):
def test_logged_in_inactive(self):
"""Inactive user login not allowed by default."""
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.user = user(is_active=False, save=True)
view = login_required(simple_view)
response = view(request)
@ -73,7 +73,7 @@ class LoginRequiredTestCase(TestCase):
def test_logged_in_inactive_allow(self):
"""Inactive user login explicitly allowed."""
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.user = user(is_active=False, save=True)
view = login_required(simple_view, only_active=False)
response = view(request)
@ -81,7 +81,7 @@ class LoginRequiredTestCase(TestCase):
def test_no_redirect_ajax(self):
"""Ajax requests should not redirect."""
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
request.user = AnonymousUser()
view = login_required(simple_view)
@ -91,14 +91,14 @@ class LoginRequiredTestCase(TestCase):
class PermissionRequiredTestCase(TestCase):
def test_logged_out_default(self):
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.user = AnonymousUser()
view = permission_required('perm')(simple_view)
response = view(request)
eq_(302, response.status_code)
def test_logged_in_default(self):
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.user = user(save=True)
view = permission_required('perm')(simple_view)
response = view(request)
@ -106,14 +106,14 @@ class PermissionRequiredTestCase(TestCase):
def test_logged_in_inactive(self):
"""Inactive user is denied access."""
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.user = user(is_active=False, save=True)
view = permission_required('perm')(simple_view)
response = view(request)
eq_(403, response.status_code)
def test_logged_in_admin(self):
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.user = user(is_staff=True, is_superuser=True, save=True)
view = permission_required('perm')(simple_view)
response = view(request)
@ -121,7 +121,7 @@ class PermissionRequiredTestCase(TestCase):
def test_no_redirect_ajax(self):
"""Ajax requests should not redirect."""
request = test_utils.RequestFactory().get('/foo')
request = RequestFactory().get('/foo')
request.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest'
request.user = AnonymousUser()
view = permission_required('perm')(simple_view)

Просмотреть файл

@ -2,10 +2,10 @@ from datetime import datetime, timedelta
import json
from django.conf import settings
from django.test.client import RequestFactory
from mock import patch, Mock
from nose.tools import eq_
from test_utils import RequestFactory
from kitsune.customercare.models import Tweet, Reply
from kitsune.customercare.tests import tweet, twitter_account, reply

Просмотреть файл

@ -3,10 +3,10 @@ from django.contrib.admin.options import ModelAdmin
from django.contrib.auth.models import User
from django.contrib.sites.models import Site
from django.core import mail
from django.test.client import RequestFactory
import mock
from nose.tools import eq_
import test_utils
from kitsune.forums.events import NewPostEvent, NewThreadEvent
from kitsune.forums.models import Thread, Post
@ -340,7 +340,7 @@ class NotificationsTests(ForumTestCase):
self.client.login(username=admin_user.username, password='testpass')
self._toggle_watch_thread_as(t, watcher, turn_on=True)
url = reverse('admin:auth_user_delete', args=[u.id])
request = test_utils.RequestFactory().get(url)
request = RequestFactory().get(url)
request.user = admin_user
request.session = self.client.session
# The following blows up without our monkeypatch.

Просмотреть файл

@ -1,6 +1,5 @@
from django.contrib.contenttypes.models import ContentType
import test_utils
from django.test.client import RequestFactory
from kitsune.access.helpers import has_perm, has_perm_or_owns
from kitsune.access.tests import permission
@ -14,7 +13,7 @@ class ForumTestPermissions(ForumTestCase):
def setUp(self):
url = reverse('forums.threads', args=[u'test-forum'])
self.context = {'request': test_utils.RequestFactory().get(url)}
self.context = {'request': RequestFactory().get(url)}
self.group = group(save=True)

Просмотреть файл

@ -1,8 +1,8 @@
from django.contrib.auth.models import AnonymousUser
from django.test.client import RequestFactory
import mock
from nose.tools import eq_
from test_utils import RequestFactory
from kitsune import messages
from kitsune.messages.context_processors import unread_message_count

Просмотреть файл

@ -4,15 +4,13 @@ from django.test.utils import override_settings
from elasticutils.contrib.django import get_es
from nose import SkipTest
from test_utils import TestCase
from kitsune.search import es_utils
from kitsune.search.models import generate_tasks, Synonym
from kitsune.sumo.tests import with_save
from kitsune.sumo.tests import with_save, TestCase
# Dummy request for passing to question_searcher() and brethren.
# There's no reason to use test_utils' RequestFactory.
dummy_request = RequestFactory().get('/')

Просмотреть файл

Просмотреть файл

@ -564,7 +564,6 @@ INSTALLED_APPS = (
# Extra apps for testing.
'django_nose',
'test_utils',
# Extra app for python migrations.
'django_extensions',

Просмотреть файл

@ -9,7 +9,7 @@ from django.utils import translation
import jingo
from premailer import transform
from test_utils import RequestFactory
from django.test.client import RequestFactory
from kitsune.sumo.utils import uselocale

Просмотреть файл

@ -5,10 +5,12 @@ from os.path import join, dirname
from smtplib import SMTPRecipientsRefused
from django.conf import settings
from django.core.cache import cache
from django.core.management import call_command
from django.test import LiveServerTestCase
from django.test import LiveServerTestCase, TestCase as OriginalTestCase
from django.test.client import Client
from django.test.utils import override_settings
from django.utils.translation import trans_real
import django_nose
from nose import SkipTest
@ -16,7 +18,6 @@ from nose.tools import eq_
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.firefox import firefox_binary
from test_utils import TestCase as OriginalTestCase
from kitsune import sumo
from kitsune.sumo.urlresolvers import reverse, split_path
@ -51,8 +52,13 @@ class TestSuiteRunner(django_nose.NoseTestSuiteRunner):
@override_settings(ES_LIVE_INDEX=False)
class TestCase(OriginalTestCase):
"""A modification of ``test_utils.TestCase`` that skips live indexing."""
pass
"""TestCase that skips live indexing."""
def _pre_setup(self):
cache.clear()
trans_real.deactivate()
trans_real._translations = {} # Django fails to clear this cache.
trans_real.activate(settings.LANGUAGE_CODE)
super(TestCase, self)._pre_setup()
def attrs_eq(received, **expected):

Просмотреть файл

@ -1,9 +1,8 @@
from nose.tools import eq_
from django.http import HttpResponse
from django.conf import settings
import test_utils
from django.http import HttpResponse
from django.test.client import RequestFactory
from kitsune.sumo.anonymous import AnonymousIdentityMiddleware
from kitsune.sumo.tests import TestCase
@ -19,7 +18,7 @@ class TestAnonymousMiddleware(TestCase):
def test_cookie_set(self):
"""The anonymous cookie is set when the anonymous id is created."""
# Create and process a request
request = test_utils.RequestFactory().request()
request = RequestFactory().request()
self.middleware.process_request(request)
# Make sure anonymous id isn't set then access it to generate it
@ -38,7 +37,7 @@ class TestAnonymousMiddleware(TestCase):
def test_cookie_not_set(self):
"""The anonymous cookie isn't set if it isn't created."""
# Create and process a request
request = test_utils.RequestFactory().request()
request = RequestFactory().request()
self.middleware.process_request(request)
# Check if anonymous id is set (without creating one)
@ -55,7 +54,7 @@ class TestAnonymousMiddleware(TestCase):
"""Anonymous cookie is already set.
Make sure the value is read correctly and a new one isn't set."""
# Create, add the anonymous cookie and process a request
request = test_utils.RequestFactory().request()
request = RequestFactory().request()
anon_id = '63de20c227be94560e3c679330c678ee'
request.COOKIES[settings.ANONYMOUS_COOKIE_NAME] = anon_id
self.middleware.process_request(request)

Просмотреть файл

@ -1,5 +1,6 @@
from django.test.client import RequestFactory
from nose.tools import eq_
from test_utils import RequestFactory
from kitsune.sumo.tests import TestCase
from kitsune.sumo.context_processors import geoip_cache_detector

Просмотреть файл

@ -3,9 +3,9 @@ from collections import namedtuple
from datetime import datetime
from django.forms.fields import CharField
from django.test.client import RequestFactory
import jingo
import test_utils
from babel.dates import format_date, format_time, format_datetime
from mock import Mock
from nose.tools import eq_, assert_raises
@ -100,7 +100,7 @@ class TestDateTimeFormat(TestCase):
self.timezone = timezone('US/Pacific')
self.locale = 'en_US'
url_ = reverse('forums.threads', args=['testslug'])
self.context = {'request': test_utils.RequestFactory().get(url_)}
self.context = {'request': RequestFactory().get(url_)}
self.context['request'].LANGUAGE_CODE = self.locale
user_profile = profile(timezone=self.timezone, locale=self.locale)
self.context['request'].user = user_profile

Просмотреть файл

@ -1,8 +1,8 @@
from django.http import HttpResponsePermanentRedirect
from django.test.client import RequestFactory
import mobility
from nose.tools import eq_
from test_utils import RequestFactory
from kitsune.sumo.middleware import (
PlusToSpaceMiddleware, DetectMobileMiddleware)

Просмотреть файл

@ -1,4 +1,5 @@
import test_utils
from django.test.client import RequestFactory
import pyquery
from nose.tools import eq_, raises
@ -12,7 +13,7 @@ from kitsune.sumo.utils import paginate, simple_paginate
def test_paginated_url():
"""Avoid duplicating page param in pagination."""
url = '%s?%s' % (reverse('search'), 'q=bookmarks&page=2')
request = test_utils.RequestFactory().get(url)
request = RequestFactory().get(url)
queryset = [{}, {}]
paginated = paginate(request, queryset)
eq_(paginated.url,
@ -21,7 +22,7 @@ def test_paginated_url():
def test_invalid_page_param():
url = '%s?%s' % (reverse('search'), 'page=a')
request = test_utils.RequestFactory().get(url)
request = RequestFactory().get(url)
queryset = range(100)
paginated = paginate(request, queryset)
eq_(paginated.url,
@ -32,7 +33,7 @@ def test_paginator_filter():
# Correct number of <li>s on page 1.
url = reverse('search')
request = test_utils.RequestFactory().get(url)
request = RequestFactory().get(url)
pager = paginate(request, range(100), per_page=9)
html = paginator(pager)
doc = pyquery.PyQuery(html)
@ -40,7 +41,7 @@ def test_paginator_filter():
# Correct number of <li>s in the middle.
url = '%s?%s' % (reverse('search'), 'page=10')
request = test_utils.RequestFactory().get(url)
request = RequestFactory().get(url)
pager = paginate(request, range(200), per_page=10)
html = paginator(pager)
doc = pyquery.PyQuery(html)
@ -49,7 +50,7 @@ def test_paginator_filter():
class SimplePaginatorTestCase(TestCase):
rf = test_utils.RequestFactory()
rf = RequestFactory()
def test_no_explicit_page(self):
"""No 'page' query param implies page 1."""

Просмотреть файл

@ -3,9 +3,9 @@ import copy
from django.conf import settings
from django.db import models
from django.db.utils import DatabaseError
from django.test import TestCase
from django.utils import importlib
import test_utils
from nose.tools import assert_raises, eq_
from pyquery import PyQuery as pq
@ -14,7 +14,7 @@ from kitsune.sumo.urlresolvers import reverse
from kitsune.users.tests import user
class ReadOnlyModeTest(test_utils.TestCase):
class ReadOnlyModeTest(TestCase):
extra = ('kitsune.sumo.middleware.ReadOnlyMiddleware',)
def setUp(self):

Просмотреть файл

@ -1,11 +1,11 @@
from django.conf import settings
from django.test.client import RequestFactory
from django.utils import translation
import jingo
import mock
from nose.tools import eq_
from pyquery import PyQuery as pq
from test_utils import RequestFactory
from kitsune.sumo.tests import LocalizingClient, TestCase
from kitsune.sumo.urlresolvers import reverse

Просмотреть файл

@ -2,10 +2,10 @@
import json
from django.contrib.auth.models import Permission
from django.test.client import RequestFactory
from mock import patch, Mock
from nose.tools import eq_
from test_utils import RequestFactory
from kitsune.journal.models import Record
from kitsune.sumo.utils import (

Просмотреть файл

@ -4,11 +4,11 @@ import django
from django.conf import settings
from django.contrib.sites.models import Site
from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect
from django.test.client import RequestFactory
import mock
from nose.tools import eq_
from pyquery import PyQuery as pq
from test_utils import RequestFactory
from kitsune.sumo.helpers import urlparams
from kitsune.sumo.middleware import LocaleURLMiddleware

Просмотреть файл

@ -639,6 +639,6 @@ class EditWatchListTests(TestCaseBase):
eq_(w.is_active, False)
self.client.post(reverse('users.edit_watch_list'), {
'watch_%s' % self.question.id: '1'})
'watch_%s' % w.id: '1'})
w = Watch.objects.get(object_id=self.question.id, user=self.user)
eq_(w.is_active, True)

Просмотреть файл

Просмотреть файл

@ -21,7 +21,7 @@ class LocaleListTests(TestCase):
r = self.client.get(reverse('wiki.locales'))
eq_(r.status_code, 200)
doc = pq(r.content)
eq_(3, len(doc('#locale-listing li')))
eq_(Locale.objects.count(), len(doc('#locale-listing li')))
class LocaleDetailsTests(TestCase):

Просмотреть файл

@ -6,12 +6,12 @@ from django.conf import settings
from django.contrib.sites.models import Site
from django.core import mail
from django.core.cache import cache
from django.test.client import RequestFactory
import bleach
import mock
import waffle
from nose.tools import eq_
from test_utils import RequestFactory
from kitsune.sumo.tests import TestCase
from kitsune.users.tests import add_permission, user

Просмотреть файл

Просмотреть файл

@ -2,10 +2,10 @@ import collections
from django import forms
from django.conf import settings
from django.test.client import RequestFactory
from django.utils.safestring import mark_safe
import jingo
from test_utils import RequestFactory
from kitsune.products.models import Topic
from kitsune.wiki.config import SIGNIFICANCES_HELP

Просмотреть файл

@ -312,10 +312,6 @@ sqlparse==0.1.1
# sha256: iwwUgZEicThAdjbIlWf8v2ruD33Bdms1HZcZzyF4CQ8
statsd==2.0.1
# test-utils: master
# sha256: TfVu9q0eiiDx7hMROF0rrBpPv60m3A5ceuuN_sMdgHI
https://github.com/jbalogh/test-utils/archive/9fa5b26730e36ee390653f7364a74bb7180e9b4c.tar.gz#egg=test-utils
# tower: tags/v0.4.0~10
# sha256: SUBIuWRLwj-FjRiYUuI3vgSTuyjtMQZaipayJ4SVcUI
https://github.com/clouserw/tower/archive/af393cd07b1ee02107cb003ab47c6b0b4553b0b7.tar.gz#egg=tower