<s> import datetime <EOL> from django . core . management . color import no_style <EOL> from django . db import backend , connection , connections , DEFAULT_DB_ALIAS , IntegrityError <EOL> from django . db . backends . signals import connection_created <EOL> from django . db . backends . postgresql import version as pg_version <EOL> from django . test import TestCase , skipUnlessDBFeature , TransactionTestCase <EOL> from django . utils import unittest <EOL> from regressiontests . backends import models <EOL> class OracleChecks ( unittest . TestCase ) : <EOL> @ unittest . skipUnless ( connection . vendor == '<STR_LIT>' , <EOL> "<STR_LIT>" ) <EOL> def test_dbms_session ( self ) : <EOL> convert_unicode = backend . convert_unicode <EOL> cursor = connection . cursor ( ) <EOL> cursor . callproc ( convert_unicode ( '<STR_LIT>' ) , <EOL> [ convert_unicode ( '<STR_LIT>' ) , ] ) <EOL> @ unittest . skipUnless ( connection . vendor == '<STR_LIT>' , <EOL> "<STR_LIT>" ) <EOL> def test_cursor_var ( self ) : <EOL> cursor = connection . cursor ( ) <EOL> var = cursor . var ( backend . Database . STRING ) <EOL> cursor . execute ( "<STR_LIT>" , [ var ] ) <EOL> self . assertEqual ( var . getvalue ( ) , '<STR_LIT:X>' ) <EOL> @ unittest . skipUnless ( connection . vendor == '<STR_LIT>' , <EOL> "<STR_LIT>" ) <EOL> def test_long_string ( self ) : <EOL> c = connection . cursor ( ) <EOL> c . execute ( '<STR_LIT>' ) <EOL> long_str = '<STR_LIT>' . join ( [ unicode ( x ) for x in xrange ( <NUM_LIT> ) ] ) <EOL> c . execute ( '<STR_LIT>' , [ long_str ] ) <EOL> c . execute ( '<STR_LIT>' ) <EOL> row = c . fetchone ( ) <EOL> self . assertEqual ( long_str , row [ <NUM_LIT:0> ] . read ( ) ) <EOL> c . execute ( '<STR_LIT>' ) <EOL> @ unittest . skipUnless ( connection . vendor == '<STR_LIT>' , <EOL> "<STR_LIT>" ) <EOL> def test_client_encoding ( self ) : <EOL> c = connection . cursor ( ) <EOL> self . assertEqual ( connection . connection . encoding , "<STR_LIT>" ) <EOL> self . assertEqual ( connection . connection . nencoding , "<STR_LIT>" ) <EOL> class DateQuotingTest ( TestCase ) : <EOL> def test_django_date_trunc ( self ) : <EOL> """<STR_LIT>""" <EOL> updated = datetime . datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:20> ) <EOL> models . SchoolClass . objects . create ( year = <NUM_LIT> , last_updated = updated ) <EOL> years = models . SchoolClass . objects . dates ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertEqual ( list ( years ) , [ datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ] ) <EOL> def test_django_extract ( self ) : <EOL> """<STR_LIT>""" <EOL> updated = datetime . datetime ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT:20> ) <EOL> models . SchoolClass . objects . create ( year = <NUM_LIT> , last_updated = updated ) <EOL> classes = models . SchoolClass . objects . filter ( last_updated__day = <NUM_LIT:20> ) <EOL> self . assertEqual ( len ( classes ) , <NUM_LIT:1> ) <EOL> class ParameterHandlingTest ( TestCase ) : <EOL> def test_bad_parameter_count ( self ) : <EOL> "<STR_LIT>" <EOL> cursor = connection . cursor ( ) <EOL> query = ( '<STR_LIT>' % ( <EOL> connection . introspection . table_name_converter ( '<STR_LIT>' ) , <EOL> connection . ops . quote_name ( '<STR_LIT:root>' ) , <EOL> connection . ops . quote_name ( '<STR_LIT>' ) <EOL> ) ) <EOL> self . assertRaises ( Exception , cursor . executemany , query , [ ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ) , ] ) <EOL> self . assertRaises ( Exception , cursor . executemany , query , [ ( <NUM_LIT:1> , ) , ] ) <EOL> class LongNameTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> @ skipUnlessDBFeature ( '<STR_LIT>' ) <EOL> def test_sequence_name_length_limits_create ( self ) : <EOL> """<STR_LIT>""" <EOL> models . VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ . objects . create ( ) <EOL> @ skipUnlessDBFeature ( '<STR_LIT>' ) <EOL> def test_sequence_name_length_limits_m2m ( self ) : <EOL> """<STR_LIT>""" <EOL> obj = models . VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ . objects . create ( ) <EOL> rel_obj = models . Person . objects . create ( first_name = '<STR_LIT>' , last_name = '<STR_LIT>' ) <EOL> obj . m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz . add ( rel_obj ) <EOL> @ skipUnlessDBFeature ( '<STR_LIT>' ) <EOL> def test_sequence_name_length_limits_flush ( self ) : <EOL> """<STR_LIT>""" <EOL> VLM = models . VeryLongModelNameZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ <EOL> VLM_m2m = VLM . m2m_also_quite_long_zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz . through <EOL> tables = [ <EOL> VLM . _meta . db_table , <EOL> VLM_m2m . _meta . db_table , <EOL> ] <EOL> sequences = [ <EOL> { <EOL> '<STR_LIT>' : VLM . _meta . pk . column , <EOL> '<STR_LIT>' : VLM . _meta . db_table <EOL> } , <EOL> ] <EOL> cursor = connection . cursor ( ) <EOL> for statement in connection . ops . sql_flush ( no_style ( ) , tables , sequences ) : <EOL> cursor . execute ( statement ) <EOL> class SequenceResetTest ( TestCase ) : <EOL> def test_generic_relation ( self ) : <EOL> "<STR_LIT>" <EOL> models . Post . objects . create ( id = <NUM_LIT:10> , name = '<STR_LIT>' , text = '<STR_LIT>' ) <EOL> cursor = connection . cursor ( ) <EOL> commands = connections [ DEFAULT_DB_ALIAS ] . ops . sequence_reset_sql ( no_style ( ) , [ models . Post ] ) <EOL> for sql in commands : <EOL> cursor . execute ( sql ) <EOL> obj = models . Post . objects . create ( name = '<STR_LIT>' , text = '<STR_LIT>' ) <EOL> self . assertTrue ( obj . pk > <NUM_LIT:10> ) <EOL> class PostgresVersionTest ( TestCase ) : <EOL> def assert_parses ( self , version_string , version ) : <EOL> self . assertEqual ( pg_version . _parse_version ( version_string ) , version ) <EOL> def test_parsing ( self ) : <EOL> self . assert_parses ( "<STR_LIT>" , ( <NUM_LIT:8> , <NUM_LIT:3> , None ) ) <EOL> self . assert_parses ( "<STR_LIT>" , ( <NUM_LIT:8> , <NUM_LIT:3> , None ) ) <EOL> self . assert_parses ( "<STR_LIT>" , ( <NUM_LIT:8> , <NUM_LIT:3> , None ) ) <EOL> self . assert_parses ( "<STR_LIT>" , ( <NUM_LIT:8> , <NUM_LIT:3> , <NUM_LIT:6> ) ) <EOL> self . assert_parses ( "<STR_LIT>" , ( <NUM_LIT:8> , <NUM_LIT:4> , None ) ) <EOL> self . assert_parses ( "<STR_LIT>" , ( <NUM_LIT:8> , <NUM_LIT:3> , <NUM_LIT:1> ) ) <EOL> class ConnectionCreatedSignalTest ( TestCase ) : <EOL> @ skipUnlessDBFeature ( '<STR_LIT>' ) <EOL> def test_signal ( self ) : <EOL> data = { } <EOL> def receiver ( sender , connection , ** kwargs ) : <EOL> data [ "<STR_LIT>" ] = connection <EOL> connection_created . connect ( receiver ) <EOL> connection . close ( ) <EOL> cursor = connection . cursor ( ) <EOL> self . assertTrue ( data [ "<STR_LIT>" ] is connection ) <EOL> connection_created . disconnect ( receiver ) <EOL> data . clear ( ) <EOL> cursor = connection . cursor ( ) <EOL> self . assertTrue ( data == { } ) <EOL> class EscapingChecks ( TestCase ) : <EOL> @ unittest . skipUnless ( connection . vendor == '<STR_LIT>' , <EOL> "<STR_LIT>" ) <EOL> def test_parameter_escaping ( self ) : <EOL> cursor = connection . cursor ( ) <EOL> response = cursor . execute ( <EOL> "<STR_LIT>" ) . fetchall ( ) [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] <EOL> self . assertNotEqual ( response , None ) <EOL> self . assertTrue ( int ( response ) ) <EOL> class BackendTestCase ( TestCase ) : <EOL> def test_cursor_executemany ( self ) : <EOL> cursor = connection . cursor ( ) <EOL> qn = connection . ops . quote_name <EOL> opts = models . Square . _meta <EOL> f1 , f2 = opts . get_field ( '<STR_LIT:root>' ) , opts . get_field ( '<STR_LIT>' ) <EOL> query = ( '<STR_LIT>' <EOL> % ( connection . introspection . table_name_converter ( opts . db_table ) , qn ( f1 . column ) , qn ( f2 . column ) ) ) <EOL> cursor . executemany ( query , [ ( i , i ** <NUM_LIT:2> ) for i in range ( - <NUM_LIT:5> , <NUM_LIT:6> ) ] ) <EOL> self . assertEqual ( models . Square . objects . count ( ) , <NUM_LIT:11> ) <EOL> for i in range ( - <NUM_LIT:5> , <NUM_LIT:6> ) : <EOL> square = models . Square . objects . get ( root = i ) <EOL> self . assertEqual ( square . square , i ** <NUM_LIT:2> ) <EOL> cursor . executemany ( query , [ ] ) <EOL> self . assertEqual ( models . Square . objects . count ( ) , <NUM_LIT:11> ) <EOL> def test_unicode_fetches ( self ) : <EOL> qn = connection . ops . quote_name <EOL> models . Person ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" ) . save ( ) <EOL> models . Person ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" ) . save ( ) <EOL> models . Person ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" ) . save ( ) <EOL> models . Person ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" ) . save ( ) <EOL> models . Person ( first_name = "<STR_LIT>" , last_name = "<STR_LIT>" ) . save ( ) <EOL> opts2 = models . Person . _meta <EOL> f3 , f4 = opts2 . get_field ( '<STR_LIT>' ) , opts2 . get_field ( '<STR_LIT>' ) <EOL> query2 = ( '<STR_LIT>' <EOL> % ( qn ( f3 . column ) , qn ( f4 . column ) , connection . introspection . table_name_converter ( opts2 . db_table ) , <EOL> qn ( f3 . column ) ) ) <EOL> cursor = connection . cursor ( ) <EOL> cursor . execute ( query2 ) <EOL> self . assertEqual ( cursor . fetchone ( ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) ) <EOL> self . assertEqual ( list ( cursor . fetchmany ( <NUM_LIT:2> ) ) , [ ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) ] ) <EOL> self . assertEqual ( list ( cursor . fetchall ( ) ) , [ ( u'<STR_LIT>' , u'<STR_LIT>' ) , ( u'<STR_LIT>' , u'<STR_LIT>' ) ] ) <EOL> class FkConstraintsTests ( TransactionTestCase ) : <EOL> def setUp ( self ) : <EOL> self . r = models . Reporter . objects . create ( first_name = '<STR_LIT>' , last_name = '<STR_LIT>' ) <EOL> def test_integrity_checks_on_creation ( self ) : <EOL> """<STR_LIT>""" <EOL> a = models . Article ( headline = "<STR_LIT>" , pub_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> ) , reporter_id = <NUM_LIT:30> ) <EOL> try : <EOL> a . save ( ) <EOL> except IntegrityError : <EOL> pass <EOL> def test_integrity_checks_on_update ( self ) : <EOL> """<STR_LIT>""" <EOL> models . Article . objects . create ( headline = "<STR_LIT>" , pub_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:4> ) , reporter = self . r ) <EOL> a = models . Article . objects . get ( headline = "<STR_LIT>" ) <EOL> a . reporter_id = <NUM_LIT:30> <EOL> try : <EOL> a . save ( ) <EOL> except IntegrityError : <EOL> pass </s>
