<s> from __future__ import unicode_literals <EOL> import unittest <EOL> from django . conf import settings <EOL> from django . conf . urls import url <EOL> from django . core . urlresolvers import RegexURLResolver , Resolver404 , NoReverseMatch <EOL> from django . http import HttpResponse <EOL> from multiurl import multiurl , ContinueResolving <EOL> class MultiviewTests ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> self . patterns_catchall = RegexURLResolver ( '<STR_LIT>' , [ <EOL> multiurl ( <EOL> url ( r'<STR_LIT>' , person , name = '<STR_LIT>' ) , <EOL> url ( r'<STR_LIT>' , place , name = '<STR_LIT>' ) , <EOL> url ( r'<STR_LIT>' , thing , name = '<STR_LIT>' ) , <EOL> ) <EOL> ] ) <EOL> self . patterns_no_fallthrough = RegexURLResolver ( '<STR_LIT>' , [ <EOL> multiurl ( <EOL> url ( r'<STR_LIT>' , person , name = '<STR_LIT>' ) , <EOL> url ( r'<STR_LIT>' , place , name = '<STR_LIT>' ) , <EOL> ) <EOL> ] ) <EOL> def test_resolve_match_first ( self ) : <EOL> m = self . patterns_catchall . resolve ( '<STR_LIT>' ) <EOL> response = m . func ( request = None , * m . args , ** m . kwargs ) <EOL> self . assertEqual ( response . content , b"<STR_LIT>" ) <EOL> def test_resolve_match_middle ( self ) : <EOL> m = self . patterns_catchall . resolve ( '<STR_LIT>' ) <EOL> response = m . func ( request = None , * m . args , ** m . kwargs ) <EOL> self . assertEqual ( response . content , b"<STR_LIT>" ) <EOL> def test_resolve_match_last ( self ) : <EOL> m = self . patterns_catchall . resolve ( '<STR_LIT>' ) <EOL> response = m . func ( request = None , * m . args , ** m . kwargs ) <EOL> self . assertEqual ( response . content , b"<STR_LIT>" ) <EOL> def test_resolve_match_faillthrough ( self ) : <EOL> m = self . patterns_no_fallthrough . resolve ( '<STR_LIT>' ) <EOL> with self . assertRaises ( Resolver404 ) : <EOL> m . func ( request = None , * m . args , ** m . kwargs ) <EOL> def test_no_match ( self ) : <EOL> with self . assertRaises ( Resolver404 ) : <EOL> self . patterns_catchall . resolve ( '<STR_LIT>' ) <EOL> def test_reverse ( self ) : <EOL> self . assertEqual ( '<STR_LIT>' , self . patterns_catchall . reverse ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( '<STR_LIT>' , self . patterns_catchall . reverse ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( '<STR_LIT>' , self . patterns_catchall . reverse ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> with self . assertRaises ( NoReverseMatch ) : <EOL> self . patterns_catchall . reverse ( '<STR_LIT>' ) <EOL> with self . assertRaises ( NoReverseMatch ) : <EOL> self . patterns_catchall . reverse ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def person ( request , name ) : <EOL> people = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if name in people : <EOL> return HttpResponse ( "<STR_LIT>" + people [ name ] ) <EOL> raise ContinueResolving <EOL> def place ( request , name ) : <EOL> places = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> if name in places : <EOL> return HttpResponse ( "<STR_LIT>" + places [ name ] ) <EOL> raise ContinueResolving <EOL> def thing ( request , name ) : <EOL> return HttpResponse ( "<STR_LIT>" + name . title ( ) ) <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> settings . configure ( ) <EOL> unittest . main ( ) </s>
