<s> from django . core . exceptions import ValidationError <EOL> from django . test import TestCase <EOL> from . . models import Message , MessageQuerySet <EOL> from . . models import GLOBAL_OR_LOCAL , WHERE_REQUIRED <EOL> class MessageTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_global_instance ( self ) : <EOL> """<STR_LIT>""" <EOL> message = Message . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertTrue ( <EOL> message . match ( '<STR_LIT:/>' ) <EOL> ) <EOL> self . assertTrue ( <EOL> message . match ( '<STR_LIT>' ) <EOL> ) <EOL> self . assertTrue ( <EOL> message . match ( '<STR_LIT>' ) <EOL> ) <EOL> def test_non_global_instance ( self ) : <EOL> """<STR_LIT>""" <EOL> message = Message . objects . get ( pk = <NUM_LIT:2> ) <EOL> self . assertFalse ( <EOL> message . match ( '<STR_LIT:/>' ) <EOL> ) <EOL> self . assertTrue ( <EOL> message . match ( '<STR_LIT>' ) <EOL> ) <EOL> def test_prefix_matching ( self ) : <EOL> """<STR_LIT>""" <EOL> message = Message . objects . get ( pk = <NUM_LIT:2> ) <EOL> self . assertTrue ( <EOL> message . match ( '<STR_LIT>' ) <EOL> ) <EOL> def test_active_queryset ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( <NUM_LIT:5> , MessageQuerySet ( Message ) . active ( ) . count ( ) ) <EOL> def test_active_manager ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( Message . objects . active ( ) . count ( ) , <NUM_LIT:5> ) <EOL> def test_match_global ( self ) : <EOL> """<STR_LIT>""" <EOL> results = Message . objects . match ( '<STR_LIT:/>' ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:1> ) <EOL> result_ids = [ m . id for m in results ] <EOL> self . assertEqual ( [ <NUM_LIT:1> ] , result_ids ) <EOL> def test_match_simple ( self ) : <EOL> """<STR_LIT>""" <EOL> results = Message . objects . match ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( <EOL> { <NUM_LIT:1> , <NUM_LIT:4> } , { m . id for m in results } <EOL> ) <EOL> def test_match_partial ( self ) : <EOL> """<STR_LIT>""" <EOL> results = Message . objects . match ( '<STR_LIT>' ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( <EOL> { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:7> } , { m . id for m in results } <EOL> ) <EOL> def test_global_or_local ( self ) : <EOL> """<STR_LIT>""" <EOL> m = Message ( <EOL> message = "<STR_LIT>" , <EOL> is_global = True , <EOL> is_active = True , <EOL> url = "<STR_LIT>" <EOL> ) <EOL> with self . assertRaises ( ValidationError , msg = GLOBAL_OR_LOCAL ) : <EOL> m . clean ( ) <EOL> m = Message ( <EOL> message = "<STR_LIT>" , <EOL> is_global = True , <EOL> is_active = True , <EOL> url = "<STR_LIT>" <EOL> ) <EOL> m . clean ( ) <EOL> def test_where_required ( self ) : <EOL> """<STR_LIT>""" <EOL> m = Message ( <EOL> message = "<STR_LIT>" , <EOL> is_global = False , <EOL> is_active = True <EOL> ) <EOL> with self . assertRaises ( ValidationError , msg = WHERE_REQUIRED ) : <EOL> m . clean ( ) <EOL> class ContextProcessorTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_context_processor ( self ) : <EOL> """<STR_LIT>""" <EOL> with self . modify_settings ( <EOL> TEMPLATE_CONTEXT_PROCESSORS = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) : <EOL> r = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEqual ( r . status_code , <NUM_LIT:200> ) <EOL> self . assertTrue ( '<STR_LIT>' in r . context ) <EOL> self . assertEqual ( <EOL> len ( r . context [ '<STR_LIT>' ] ) , <NUM_LIT:4> ) <EOL> self . assertEqual ( <EOL> { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:7> } , <EOL> { m . id for m in r . context [ '<STR_LIT>' ] } <EOL> ) </s>
