<s> """<STR_LIT>""" <EOL> from collections import namedtuple <EOL> from django . db import models <EOL> from django . test import TestCase <EOL> from rest_framework . viewsets import ModelViewSet <EOL> from rest_framework_nested . routers import SimpleRouter , NestedSimpleRouter <EOL> QS = namedtuple ( '<STR_LIT>' , [ '<STR_LIT>' ] ) <EOL> class A ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> class B ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> parent = models . ForeignKey ( A ) <EOL> class C ( models . Model ) : <EOL> name = models . CharField ( max_length = <NUM_LIT:255> ) <EOL> parent = models . ForeignKey ( B ) <EOL> class AViewSet ( ModelViewSet ) : <EOL> lookup_value_regex = '<STR_LIT>' <EOL> model = A <EOL> queryset = QS ( A ) <EOL> class BViewSet ( ModelViewSet ) : <EOL> model = B <EOL> queryset = QS ( B ) <EOL> class CViewSet ( ModelViewSet ) : <EOL> model = C <EOL> queryset = QS ( C ) <EOL> class TestNestedSimpleRouter ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . router = SimpleRouter ( ) <EOL> self . router . register ( r'<STR_LIT:a>' , AViewSet ) <EOL> self . a_router = NestedSimpleRouter ( self . router , r'<STR_LIT:a>' , lookup = '<STR_LIT:a>' ) <EOL> self . a_router . register ( r'<STR_LIT:b>' , BViewSet ) <EOL> self . b_router = NestedSimpleRouter ( self . a_router , r'<STR_LIT:b>' , lookup = '<STR_LIT:b>' ) <EOL> self . b_router . register ( r'<STR_LIT:c>' , CViewSet ) <EOL> def test_recursive_nested_simple_routers ( self ) : <EOL> self . assertFalse ( hasattr ( self . router , '<STR_LIT>' ) ) <EOL> urls = self . router . urls <EOL> self . assertEquals ( len ( urls ) , <NUM_LIT:2> ) <EOL> self . assertEquals ( urls [ <NUM_LIT:0> ] . regex . pattern , u'<STR_LIT>' ) <EOL> self . assertEquals ( urls [ <NUM_LIT:1> ] . regex . pattern , u'<STR_LIT>' ) <EOL> self . assertEqual ( self . a_router . parent_regex , u'<STR_LIT>' ) <EOL> urls = self . a_router . urls <EOL> self . assertEquals ( len ( urls ) , <NUM_LIT:2> ) <EOL> self . assertEquals ( urls [ <NUM_LIT:0> ] . regex . pattern , u'<STR_LIT>' ) <EOL> self . assertEquals ( urls [ <NUM_LIT:1> ] . regex . pattern , u'<STR_LIT>' ) <EOL> self . assertEqual ( self . b_router . parent_regex , u'<STR_LIT>' ) <EOL> urls = self . b_router . urls <EOL> self . assertEquals ( len ( urls ) , <NUM_LIT:2> ) <EOL> self . assertEquals ( urls [ <NUM_LIT:0> ] . regex . pattern , u'<STR_LIT>' ) <EOL> self . assertEquals ( urls [ <NUM_LIT:1> ] . regex . pattern , u'<STR_LIT>' ) </s>
