<s> from django import db <EOL> from django . conf import settings <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from django . contrib . sites . models import Site <EOL> from django . contrib . contenttypes . views import shortcut <EOL> from django . core . exceptions import ObjectDoesNotExist <EOL> from django . http import HttpRequest <EOL> from django . test import TestCase <EOL> class ContentTypesTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . old_DEBUG = settings . DEBUG <EOL> self . old_Site_meta_installed = Site . _meta . installed <EOL> settings . DEBUG = True <EOL> ContentType . objects . clear_cache ( ) <EOL> db . reset_queries ( ) <EOL> def tearDown ( self ) : <EOL> settings . DEBUG = self . old_DEBUG <EOL> Site . _meta . installed = self . old_Site_meta_installed <EOL> ContentType . objects . clear_cache ( ) <EOL> def test_lookup_cache ( self ) : <EOL> """<STR_LIT>""" <EOL> ContentType . objects . get_for_model ( ContentType ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( db . connection . queries ) ) <EOL> ct = ContentType . objects . get_for_model ( ContentType ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( db . connection . queries ) ) <EOL> ContentType . objects . get_for_id ( ct . id ) <EOL> self . assertEqual ( <NUM_LIT:1> , len ( db . connection . queries ) ) <EOL> ContentType . objects . clear_cache ( ) <EOL> ContentType . objects . get_for_model ( ContentType ) <EOL> len ( db . connection . queries ) <EOL> self . assertEqual ( <NUM_LIT:2> , len ( db . connection . queries ) ) <EOL> def test_shortcut_view ( self ) : <EOL> """<STR_LIT>""" <EOL> request = HttpRequest ( ) <EOL> request . META = { <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> } <EOL> from django . contrib . auth . models import User <EOL> user_ct = ContentType . objects . get_for_model ( User ) <EOL> obj = User . objects . create ( username = "<STR_LIT>" ) <EOL> if Site . _meta . installed : <EOL> current_site = Site . objects . get_current ( ) <EOL> response = shortcut ( request , user_ct . id , obj . id ) <EOL> self . assertEqual ( "<STR_LIT>" % current_site . domain , <EOL> response . _headers . get ( "<STR_LIT:location>" ) [ <NUM_LIT:1> ] ) <EOL> Site . _meta . installed = False <EOL> response = shortcut ( request , user_ct . id , obj . id ) <EOL> self . assertEqual ( "<STR_LIT>" , <EOL> response . _headers . get ( "<STR_LIT:location>" ) [ <NUM_LIT:1> ] ) </s>
