Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Replace 'urls = ...' in test classes with override_settings('ROOT_URL…
…CONF=...')
  • Loading branch information
lovelydinosaur committed Jun 1, 2016
commit f11e24ecff8a966da5b4a092fe1f500c18592173
10 changes: 3 additions & 7 deletions tests/browsable_api/test_browsable_api.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
from __future__ import unicode_literals

from django.contrib.auth.models import User
from django.test import TestCase
from django.test import override_settings, TestCase

from rest_framework.test import APIClient


@override_settings(ROOT_URLCONF='tests.browsable_api.auth_urls')
class DropdownWithAuthTests(TestCase):
"""Tests correct dropdown behaviour with Auth views enabled."""

urls = 'tests.browsable_api.auth_urls'

def setUp(self):
self.client = APIClient(enforce_csrf_checks=True)
self.username = 'john'
Expand Down Expand Up @@ -40,11 +38,9 @@ def test_login_shown_when_logged_out(self):
self.assertContains(response, '>Log in<')


@override_settings(ROOT_URLCONF='tests.browsable_api.no_auth_urls')
class NoDropdownWithoutAuthTests(TestCase):
"""Tests correct dropdown behaviour with Auth views NOT enabled."""

urls = 'tests.browsable_api.no_auth_urls'

def setUp(self):
self.client = APIClient(enforce_csrf_checks=True)
self.username = 'john'
Expand Down
10 changes: 4 additions & 6 deletions tests/test_authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.contrib.auth.models import User
from django.db import models
from django.http import HttpResponse
from django.test import TestCase
from django.test import override_settings, TestCase
from django.utils import six

from rest_framework import (
Expand Down Expand Up @@ -81,10 +81,9 @@ def put(self, request):
]


@override_settings(ROOT_URLCONF='tests.test_authentication')
class BasicAuthTests(TestCase):
"""Basic authentication"""
urls = 'tests.test_authentication'

def setUp(self):
self.csrf_client = APIClient(enforce_csrf_checks=True)
self.username = 'john'
Expand Down Expand Up @@ -152,10 +151,9 @@ def test_post_json_failing_basic_auth(self):
self.assertEqual(response['WWW-Authenticate'], 'Basic realm="api"')


@override_settings(ROOT_URLCONF='tests.test_authentication')
class SessionAuthTests(TestCase):
"""User session authentication"""
urls = 'tests.test_authentication'

def setUp(self):
self.csrf_client = APIClient(enforce_csrf_checks=True)
self.non_csrf_client = APIClient(enforce_csrf_checks=False)
Expand Down Expand Up @@ -222,9 +220,9 @@ def test_post_form_session_auth_failing(self):
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)


@override_settings(ROOT_URLCONF='tests.test_authentication')
class BaseTokenAuthTests(object):
"""Token authentication"""
urls = 'tests.test_authentication'
model = None
path = None
header_prefix = 'Token '
Expand Down
3 changes: 1 addition & 2 deletions tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,11 @@ def test_unknown_filter(self):
self.assertEqual(response.status_code, status.HTTP_200_OK)


@override_settings(ROOT_URLCONF='tests.test_filters')
class IntegrationTestDetailFiltering(CommonFilteringTestCase):
"""
Integration tests for filtered detail views.
"""
urls = 'tests.test_filters'

def _get_url(self, item):
return reverse('detail-view', kwargs=dict(pk=item.pk))

Expand Down
8 changes: 3 additions & 5 deletions tests/test_htmlrenderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.exceptions import PermissionDenied
from django.http import Http404
from django.template import Template, TemplateDoesNotExist
from django.test import TestCase
from django.test import override_settings, TestCase
from django.utils import six

from rest_framework import status
Expand Down Expand Up @@ -43,9 +43,8 @@ def not_found(request):
]


@override_settings(ROOT_URLCONF='tests.test_htmlrenderer')
class TemplateHTMLRendererTests(TestCase):
urls = 'tests.test_htmlrenderer'

def setUp(self):
"""
Monkeypatch get_template
Expand Down Expand Up @@ -89,9 +88,8 @@ def test_permission_denied_html_view(self):
self.assertEqual(response['Content-Type'], 'text/html; charset=utf-8')


@override_settings(ROOT_URLCONF='tests.test_htmlrenderer')
class TemplateHTMLRendererExceptionTests(TestCase):
urls = 'tests.test_htmlrenderer'

def setUp(self):
"""
Monkeypatch get_template
Expand Down
6 changes: 2 additions & 4 deletions tests/test_middleware.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

from django.conf.urls import url
from django.contrib.auth.models import User
from django.test import override_settings

from rest_framework.authentication import TokenAuthentication
from rest_framework.authtoken.models import Token
Expand All @@ -20,10 +20,8 @@ def process_response(self, request, response):
return response


@override_settings(ROOT_URLCONF='tests.test_middleware')
class TestMiddleware(APITestCase):

urls = 'tests.test_middleware'

def test_middleware_can_access_user_when_processing_response(self):
user = User.objects.create_user('john', '[email protected]', 'password')
key = 'abcd1234'
Expand Down
15 changes: 5 additions & 10 deletions tests/test_relations_hyperlink.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals

from django.conf.urls import url
from django.test import TestCase
from django.test import override_settings, TestCase

from rest_framework import serializers
from rest_framework.test import APIRequestFactory
Expand Down Expand Up @@ -71,10 +71,8 @@ class Meta:


# TODO: Add test that .data cannot be accessed prior to .is_valid

@override_settings(ROOT_URLCONF='tests.test_relations_hyperlink')
class HyperlinkedManyToManyTests(TestCase):
urls = 'tests.test_relations_hyperlink'

def setUp(self):
for idx in range(1, 4):
target = ManyToManyTarget(name='target-%d' % idx)
Expand Down Expand Up @@ -188,9 +186,8 @@ def test_reverse_many_to_many_create(self):
self.assertEqual(serializer.data, expected)


@override_settings(ROOT_URLCONF='tests.test_relations_hyperlink')
class HyperlinkedForeignKeyTests(TestCase):
urls = 'tests.test_relations_hyperlink'

def setUp(self):
target = ForeignKeyTarget(name='target-1')
target.save()
Expand Down Expand Up @@ -318,9 +315,8 @@ def test_foreign_key_update_with_invalid_null(self):
self.assertEqual(serializer.errors, {'target': ['This field may not be null.']})


@override_settings(ROOT_URLCONF='tests.test_relations_hyperlink')
class HyperlinkedNullableForeignKeyTests(TestCase):
urls = 'tests.test_relations_hyperlink'

def setUp(self):
target = ForeignKeyTarget(name='target-1')
target.save()
Expand Down Expand Up @@ -425,9 +421,8 @@ def test_foreign_key_update_with_valid_emptystring(self):
self.assertEqual(serializer.data, expected)


@override_settings(ROOT_URLCONF='tests.test_relations_hyperlink')
class HyperlinkedNullableOneToOneTests(TestCase):
urls = 'tests.test_relations_hyperlink'

def setUp(self):
target = OneToOneTarget(name='target-1')
target.save()
Expand Down
10 changes: 3 additions & 7 deletions tests/test_renderers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from django.conf.urls import include, url
from django.core.cache import cache
from django.db import models
from django.test import TestCase
from django.test import override_settings, TestCase
from django.utils import six
from django.utils.safestring import SafeText
from django.utils.translation import ugettext_lazy as _
Expand Down Expand Up @@ -148,13 +148,11 @@ def test_only_permitted_forms_are_displayed(self):
self.assertContains(response, '>PATCH<')


@override_settings(ROOT_URLCONF='tests.test_renderers')
class RendererEndToEndTests(TestCase):
"""
End-to-end testing of renderers using an RendererMixin on a generic view.
"""

urls = 'tests.test_renderers'

def test_default_renderer_serializes_content(self):
"""If the Accept header is not set the default renderer should serialize the response."""
resp = self.client.get('/')
Expand Down Expand Up @@ -397,13 +395,11 @@ class AsciiJSONRenderer(JSONRenderer):


# Tests for caching issue, #346
@override_settings(ROOT_URLCONF='tests.test_renderers')
class CacheRenderTest(TestCase):
"""
Tests specific to caching responses
"""

urls = 'tests.test_renderers'

def test_head_caching(self):
"""
Test caching of HEAD requests
Expand Down
5 changes: 2 additions & 3 deletions tests/test_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.contrib.auth import authenticate, login, logout
from django.contrib.auth.models import User
from django.contrib.sessions.middleware import SessionMiddleware
from django.test import TestCase
from django.test import override_settings, TestCase
from django.utils import six

from rest_framework import status
Expand Down Expand Up @@ -113,9 +113,8 @@ def post(self, request):
]


@override_settings(ROOT_URLCONF='tests.test_request')
class TestContentParsingWithAuthentication(TestCase):
urls = 'tests.test_request'

def setUp(self):
self.csrf_client = APIClient(enforce_csrf_checks=True)
self.username = 'john'
Expand Down
20 changes: 6 additions & 14 deletions tests/test_response.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import unicode_literals

from django.conf.urls import include, url
from django.test import TestCase
from django.test import override_settings, TestCase
from django.utils import six

from rest_framework import generics, routers, serializers, status, viewsets
Expand Down Expand Up @@ -131,13 +131,11 @@ class HTMLNewModelView(generics.ListCreateAPIView):


# TODO: Clean tests bellow - remove duplicates with above, better unit testing, ...
@override_settings(ROOT_URLCONF='tests.test_response')
class RendererIntegrationTests(TestCase):
"""
End-to-end testing of renderers using an ResponseMixin on a generic view.
"""

urls = 'tests.test_response'

def test_default_renderer_serializes_content(self):
"""If the Accept header is not set the default renderer should serialize the response."""
resp = self.client.get('/')
Expand Down Expand Up @@ -201,9 +199,8 @@ def test_specified_renderer_is_used_on_format_query_with_matching_accept(self):
self.assertEqual(resp.status_code, DUMMYSTATUS)


@override_settings(ROOT_URLCONF='tests.test_response')
class UnsupportedMediaTypeTests(TestCase):
urls = 'tests.test_response'

def test_should_allow_posting_json(self):
response = self.client.post('/json', data='{"test": 123}', content_type='application/json')

Expand All @@ -220,12 +217,11 @@ def test_should_not_allow_posting_a_form(self):
self.assertEqual(response.status_code, 415)


@override_settings(ROOT_URLCONF='tests.test_response')
class Issue122Tests(TestCase):
"""
Tests that covers #122.
"""
urls = 'tests.test_response'

def test_only_html_renderer(self):
"""
Test if no infinite recursion occurs.
Expand All @@ -239,27 +235,23 @@ def test_html_renderer_is_first(self):
self.client.get('/html1')


@override_settings(ROOT_URLCONF='tests.test_response')
class Issue467Tests(TestCase):
"""
Tests for #467
"""

urls = 'tests.test_response'

def test_form_has_label_and_help_text(self):
resp = self.client.get('/html_new_model')
self.assertEqual(resp['Content-Type'], 'text/html; charset=utf-8')
# self.assertContains(resp, 'Text comes here')
# self.assertContains(resp, 'Text description.')


@override_settings(ROOT_URLCONF='tests.test_response')
class Issue807Tests(TestCase):
"""
Covers #807
"""

urls = 'tests.test_response'

def test_does_not_append_charset_by_default(self):
"""
Renderers don't include a charset unless set explicitly.
Expand Down
5 changes: 2 additions & 3 deletions tests/test_reverse.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from django.conf.urls import url
from django.core.urlresolvers import NoReverseMatch
from django.test import TestCase
from django.test import override_settings, TestCase

from rest_framework.reverse import reverse
from rest_framework.test import APIRequestFactory
Expand Down Expand Up @@ -30,12 +30,11 @@ def reverse(self, *args, **kwargs):
return 'http://scheme-reversed/view'


@override_settings(ROOT_URLCONF='tests.test_reverse')
class ReverseTests(TestCase):
"""
Tests for fully qualified URLs when using `reverse`.
"""
urls = 'tests.test_reverse'

def test_reversed_urls_are_fully_qualified(self):
request = factory.get('/view')
url = reverse('view', request=request)
Expand Down
Loading