<s> from __future__ import unicode_literals <EOL> from collections import namedtuple <EOL> from django . conf . urls import include , url <EOL> from django . core import urlresolvers <EOL> from django . test import TestCase <EOL> from rest_framework . test import APIRequestFactory <EOL> from rest_framework . urlpatterns import format_suffix_patterns <EOL> URLTestPath = namedtuple ( '<STR_LIT>' , [ '<STR_LIT:path>' , '<STR_LIT:args>' , '<STR_LIT>' ] ) <EOL> def dummy_view ( request , * args , ** kwargs ) : <EOL> pass <EOL> class FormatSuffixTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> def _resolve_urlpatterns ( self , urlpatterns , test_paths ) : <EOL> factory = APIRequestFactory ( ) <EOL> try : <EOL> urlpatterns = format_suffix_patterns ( urlpatterns ) <EOL> except Exception : <EOL> self . fail ( "<STR_LIT>" ) <EOL> resolver = urlresolvers . RegexURLResolver ( r'<STR_LIT>' , urlpatterns ) <EOL> for test_path in test_paths : <EOL> request = factory . get ( test_path . path ) <EOL> try : <EOL> callback , callback_args , callback_kwargs = resolver . resolve ( request . path_info ) <EOL> except Exception : <EOL> self . fail ( "<STR_LIT>" % request . path_info ) <EOL> self . assertEqual ( callback_args , test_path . args ) <EOL> self . assertEqual ( callback_kwargs , test_path . kwargs ) <EOL> def test_trailing_slash ( self ) : <EOL> factory = APIRequestFactory ( ) <EOL> urlpatterns = format_suffix_patterns ( [ <EOL> url ( r'<STR_LIT>' , dummy_view ) , <EOL> ] ) <EOL> resolver = urlresolvers . RegexURLResolver ( r'<STR_LIT>' , urlpatterns ) <EOL> test_paths = [ <EOL> ( URLTestPath ( '<STR_LIT>' , ( ) , { '<STR_LIT>' : '<STR_LIT>' } ) , True ) , <EOL> ( URLTestPath ( '<STR_LIT>' , ( ) , { '<STR_LIT>' : '<STR_LIT>' } ) , False ) , <EOL> ( URLTestPath ( '<STR_LIT>' , ( ) , { '<STR_LIT>' : '<STR_LIT>' } ) , True ) , <EOL> ] <EOL> for test_path , expected_resolved in test_paths : <EOL> request = factory . get ( test_path . path ) <EOL> try : <EOL> callback , callback_args , callback_kwargs = resolver . resolve ( request . path_info ) <EOL> except urlresolvers . Resolver404 : <EOL> callback , callback_args , callback_kwargs = ( None , None , None ) <EOL> if not expected_resolved : <EOL> assert callback is None <EOL> continue <EOL> assert callback_args == test_path . args <EOL> assert callback_kwargs == test_path . kwargs <EOL> def test_format_suffix ( self ) : <EOL> urlpatterns = [ <EOL> url ( r'<STR_LIT>' , dummy_view ) , <EOL> ] <EOL> test_paths = [ <EOL> URLTestPath ( '<STR_LIT>' , ( ) , { } ) , <EOL> URLTestPath ( '<STR_LIT>' , ( ) , { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> URLTestPath ( '<STR_LIT>' , ( ) , { '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> ] <EOL> self . _resolve_urlpatterns ( urlpatterns , test_paths ) <EOL> def test_default_args ( self ) : <EOL> urlpatterns = [ <EOL> url ( r'<STR_LIT>' , dummy_view , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) , <EOL> ] <EOL> test_paths = [ <EOL> URLTestPath ( '<STR_LIT>' , ( ) , { '<STR_LIT:foo>' : '<STR_LIT:bar>' , } ) , <EOL> URLTestPath ( '<STR_LIT>' , ( ) , { '<STR_LIT:foo>' : '<STR_LIT:bar>' , '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> URLTestPath ( '<STR_LIT>' , ( ) , { '<STR_LIT:foo>' : '<STR_LIT:bar>' , '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> ] <EOL> self . _resolve_urlpatterns ( urlpatterns , test_paths ) <EOL> def test_included_urls ( self ) : <EOL> nested_patterns = [ <EOL> url ( r'<STR_LIT>' , dummy_view ) <EOL> ] <EOL> urlpatterns = [ <EOL> url ( r'<STR_LIT>' , include ( nested_patterns ) , { '<STR_LIT:foo>' : '<STR_LIT:bar>' } ) , <EOL> ] <EOL> test_paths = [ <EOL> URLTestPath ( '<STR_LIT>' , ( ) , { '<STR_LIT:foo>' : '<STR_LIT:bar>' , } ) , <EOL> URLTestPath ( '<STR_LIT>' , ( ) , { '<STR_LIT:foo>' : '<STR_LIT:bar>' , '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> URLTestPath ( '<STR_LIT>' , ( ) , { '<STR_LIT:foo>' : '<STR_LIT:bar>' , '<STR_LIT>' : '<STR_LIT>' } ) , <EOL> ] <EOL> self . _resolve_urlpatterns ( urlpatterns , test_paths ) </s>
