mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 17:47:04 +03:00
0dec36eb41
* Start test case * Added 'requests' test client * Address typos * Graceful fallback if requests is not installed. * Add cookie support * Tests for auth and CSRF * Py3 compat * py3 compat * py3 compat * Add get_requests_client * Added SchemaGenerator.should_include_link * add settings for html cutoff on related fields * Router doesn't work if prefix is blank, though project urls.py handles prefix * Fix Django 1.10 to-many deprecation * Add django.core.urlresolvers compatibility * Update django-filter & django-guardian * Check for empty router prefix; adjust URL accordingly It's easiest to fix this issue after we have made the regex. To try to fix it before would require doing something different for List vs Detail, which means we'd have to know which type of url we're constructing before acting accordingly. * Fix misc django deprecations * Use TOC extension instead of header * Fix deprecations for py3k * Add py3k compatibility to is_simple_callable * Add is_simple_callable tests * Drop python 3.2 support (EOL, Dropped by Django) * schema_renderers= should *set* the renderers, not append to them. * API client (#4424) * Fix release notes * Add note about 'User account is disabled.' vs 'Unable to log in' * Clean up schema generation (#4527) * Handle multiple methods on custom action (#4529) * RequestsClient, CoreAPIClient * exclude_from_schema * Added 'get_schema_view()' shortcut * Added schema descriptions * Better descriptions for schemas * Add type annotation to schema generation * Coerce schema 'pk' in path to actual field name * Deprecations move into assertion errors * Use get_schema_view in tests * Updte CoreJSON media type * Handle schema structure correctly when path prefixs exist. Closes #4401 * Add PendingDeprecation to Router schema generation. * Added SCHEMA_COERCE_PATH_PK and SCHEMA_COERCE_METHOD_NAMES * Renamed and documented 'get_schema_fields' interface.
56 lines
1.5 KiB
Python
56 lines
1.5 KiB
Python
from __future__ import unicode_literals
|
|
|
|
from django.conf.urls import url
|
|
from django.test import TestCase, override_settings
|
|
|
|
from rest_framework.compat import NoReverseMatch
|
|
from rest_framework.reverse import reverse
|
|
from rest_framework.test import APIRequestFactory
|
|
|
|
factory = APIRequestFactory()
|
|
|
|
|
|
def null_view(request):
|
|
pass
|
|
|
|
urlpatterns = [
|
|
url(r'^view$', null_view, name='view'),
|
|
]
|
|
|
|
|
|
class MockVersioningScheme(object):
|
|
|
|
def __init__(self, raise_error=False):
|
|
self.raise_error = raise_error
|
|
|
|
def reverse(self, *args, **kwargs):
|
|
if self.raise_error:
|
|
raise NoReverseMatch()
|
|
|
|
return 'http://scheme-reversed/view'
|
|
|
|
|
|
@override_settings(ROOT_URLCONF='tests.test_reverse')
|
|
class ReverseTests(TestCase):
|
|
"""
|
|
Tests for fully qualified URLs when using `reverse`.
|
|
"""
|
|
def test_reversed_urls_are_fully_qualified(self):
|
|
request = factory.get('/view')
|
|
url = reverse('view', request=request)
|
|
self.assertEqual(url, 'http://testserver/view')
|
|
|
|
def test_reverse_with_versioning_scheme(self):
|
|
request = factory.get('/view')
|
|
request.versioning_scheme = MockVersioningScheme()
|
|
|
|
url = reverse('view', request=request)
|
|
self.assertEqual(url, 'http://scheme-reversed/view')
|
|
|
|
def test_reverse_with_versioning_scheme_fallback_to_default_on_error(self):
|
|
request = factory.get('/view')
|
|
request.versioning_scheme = MockVersioningScheme(raise_error=True)
|
|
|
|
url = reverse('view', request=request)
|
|
self.assertEqual(url, 'http://testserver/view')
|