<s> from os import path <EOL> from django . conf import settings <EOL> from django . test import TestCase <EOL> from django . contrib . contenttypes . models import ContentType <EOL> from regressiontests . views . models import Author , Article , UrlArticle <EOL> class DefaultsTests ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> non_existing_urls = [ '<STR_LIT>' , <EOL> '<STR_LIT>' ] <EOL> def test_shortcut_with_absolute_url ( self ) : <EOL> "<STR_LIT>" <EOL> for obj in Author . objects . all ( ) : <EOL> short_url = '<STR_LIT>' % ( ContentType . objects . get_for_model ( Author ) . id , obj . pk ) <EOL> response = self . client . get ( short_url ) <EOL> self . assertRedirects ( response , '<STR_LIT>' % obj . get_absolute_url ( ) , <EOL> status_code = <NUM_LIT> , target_status_code = <NUM_LIT> ) <EOL> def test_shortcut_no_absolute_url ( self ) : <EOL> "<STR_LIT>" <EOL> for obj in Article . objects . all ( ) : <EOL> short_url = '<STR_LIT>' % ( ContentType . objects . get_for_model ( Article ) . id , obj . pk ) <EOL> response = self . client . get ( short_url ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> def test_wrong_type_pk ( self ) : <EOL> short_url = '<STR_LIT>' % ( ContentType . objects . get_for_model ( Author ) . id , '<STR_LIT>' ) <EOL> response = self . client . get ( short_url ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> def test_shortcut_bad_pk ( self ) : <EOL> short_url = '<STR_LIT>' % ( ContentType . objects . get_for_model ( Author ) . id , '<STR_LIT>' ) <EOL> response = self . client . get ( short_url ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> def test_nonint_content_type ( self ) : <EOL> an_author = Author . objects . all ( ) [ <NUM_LIT:0> ] <EOL> short_url = '<STR_LIT>' % ( '<STR_LIT>' , an_author . pk ) <EOL> response = self . client . get ( short_url ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> def test_bad_content_type ( self ) : <EOL> an_author = Author . objects . all ( ) [ <NUM_LIT:0> ] <EOL> short_url = '<STR_LIT>' % ( <NUM_LIT> , an_author . pk ) <EOL> response = self . client . get ( short_url ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> def test_page_not_found ( self ) : <EOL> "<STR_LIT>" <EOL> for url in self . non_existing_urls : <EOL> response = self . client . get ( url ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> def test_csrf_token_in_404 ( self ) : <EOL> """<STR_LIT>""" <EOL> old_DEBUG = settings . DEBUG <EOL> try : <EOL> settings . DEBUG = False <EOL> for url in self . non_existing_urls : <EOL> response = self . client . get ( url ) <EOL> csrf_token = response . context [ '<STR_LIT>' ] <EOL> self . assertNotEqual ( str ( csrf_token ) , '<STR_LIT>' ) <EOL> self . assertNotEqual ( str ( csrf_token ) , '<STR_LIT>' ) <EOL> finally : <EOL> settings . DEBUG = old_DEBUG <EOL> def test_server_error ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( '<STR_LIT>' ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> def test_get_absolute_url_attributes ( self ) : <EOL> "<STR_LIT>" <EOL> self . assertTrue ( getattr ( UrlArticle . get_absolute_url , '<STR_LIT>' , False ) , <EOL> '<STR_LIT>' ) <EOL> article = UrlArticle . objects . get ( pk = <NUM_LIT:1> ) <EOL> self . assertTrue ( getattr ( article . get_absolute_url , '<STR_LIT>' , False ) , <EOL> '<STR_LIT>' ) </s>
