<s> import os <EOL> import re <EOL> import sys <EOL> try : <EOL> from cStringIO import StringIO <EOL> except ImportError : <EOL> from StringIO import StringIO <EOL> from django . conf import settings <EOL> from django . core import management <EOL> from django . core . management . commands . dumpdata import sort_dependencies <EOL> from django . core . management . base import CommandError <EOL> from django . db . models import signals <EOL> from django . db import DEFAULT_DB_ALIAS , transaction <EOL> from django . test import TestCase , TransactionTestCase <EOL> from models import Animal , Stuff <EOL> from models import Absolute , Parent , Child <EOL> from models import Article , Widget <EOL> from models import Store , Person , Book <EOL> from models import NKChild , RefToNKChild <EOL> from models import Circle1 , Circle2 , Circle3 <EOL> from models import ExternalDependency <EOL> from models import Thingy <EOL> pre_save_checks = [ ] <EOL> def animal_pre_save_check ( signal , sender , instance , ** kwargs ) : <EOL> "<STR_LIT>" <EOL> pre_save_checks . append ( <EOL> ( <EOL> '<STR_LIT>' % ( instance . count , type ( instance . count ) ) , <EOL> '<STR_LIT>' % ( instance . weight , type ( instance . weight ) ) , <EOL> ) <EOL> ) <EOL> class TestFixtures ( TestCase ) : <EOL> def test_duplicate_pk ( self ) : <EOL> """<STR_LIT>""" <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> animal = Animal ( <EOL> name = '<STR_LIT>' , <EOL> latin_name = '<STR_LIT>' , <EOL> count = <NUM_LIT:2> , <EOL> weight = <NUM_LIT> <EOL> ) <EOL> animal . save ( ) <EOL> self . assertTrue ( animal . id > <NUM_LIT:1> ) <EOL> if settings . DATABASES [ DEFAULT_DB_ALIAS ] [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> def test_pretty_print_xml ( self ) : <EOL> """<STR_LIT>""" <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> self . assertEqual ( Stuff . objects . all ( ) [ <NUM_LIT:0> ] . name , None ) <EOL> self . assertEqual ( Stuff . objects . all ( ) [ <NUM_LIT:0> ] . owner , None ) <EOL> if settings . DATABASES [ DEFAULT_DB_ALIAS ] [ '<STR_LIT>' ] == '<STR_LIT>' : <EOL> def test_pretty_print_xml_empty_strings ( self ) : <EOL> """<STR_LIT>""" <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> self . assertEqual ( Stuff . objects . all ( ) [ <NUM_LIT:0> ] . name , u'<STR_LIT>' ) <EOL> self . assertEqual ( Stuff . objects . all ( ) [ <NUM_LIT:0> ] . owner , None ) <EOL> def test_absolute_path ( self ) : <EOL> """<STR_LIT>""" <EOL> load_absolute_path = os . path . join ( <EOL> os . path . dirname ( __file__ ) , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' <EOL> ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> load_absolute_path , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> self . assertEqual ( Absolute . load_count , <NUM_LIT:1> ) <EOL> def test_unknown_format ( self ) : <EOL> """<STR_LIT>""" <EOL> stderr = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False , <EOL> stderr = stderr , <EOL> ) <EOL> self . assertEqual ( <EOL> stderr . getvalue ( ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_invalid_data ( self ) : <EOL> """<STR_LIT>""" <EOL> stderr = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False , <EOL> stderr = stderr , <EOL> ) <EOL> self . assertEqual ( <EOL> stderr . getvalue ( ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_invalid_data_no_ext ( self ) : <EOL> """<STR_LIT>""" <EOL> stderr = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False , <EOL> stderr = stderr , <EOL> ) <EOL> self . assertEqual ( <EOL> stderr . getvalue ( ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_empty ( self ) : <EOL> """<STR_LIT>""" <EOL> stderr = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False , <EOL> stderr = stderr , <EOL> ) <EOL> self . assertEqual ( <EOL> stderr . getvalue ( ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_abort_loaddata_on_error ( self ) : <EOL> """<STR_LIT>""" <EOL> stderr = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False , <EOL> stderr = stderr , <EOL> ) <EOL> self . assertEqual ( <EOL> stderr . getvalue ( ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_error_message ( self ) : <EOL> """<STR_LIT>""" <EOL> stderr = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False , <EOL> stderr = stderr , <EOL> ) <EOL> self . assertEqual ( <EOL> stderr . getvalue ( ) , <EOL> "<STR_LIT>" <EOL> ) <EOL> def test_pg_sequence_resetting_checks ( self ) : <EOL> """<STR_LIT>""" <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> self . assertEqual ( Parent . objects . all ( ) [ <NUM_LIT:0> ] . id , <NUM_LIT:1> ) <EOL> self . assertEqual ( Child . objects . all ( ) [ <NUM_LIT:0> ] . id , <NUM_LIT:1> ) <EOL> def test_close_connection_after_loaddata ( self ) : <EOL> """<STR_LIT>""" <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> articles = Article . objects . exclude ( id = <NUM_LIT:9> ) <EOL> self . assertEqual ( <EOL> list ( articles . values_list ( '<STR_LIT:id>' , flat = True ) ) , <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] <EOL> ) <EOL> self . assertEqual ( <EOL> list ( articles . values_list ( '<STR_LIT:id>' , flat = True ) ) , <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> ] <EOL> ) <EOL> def test_field_value_coerce ( self ) : <EOL> """<STR_LIT>""" <EOL> global pre_save_checks <EOL> pre_save_checks = [ ] <EOL> signals . pre_save . connect ( animal_pre_save_check ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False , <EOL> ) <EOL> self . assertEqual ( <EOL> pre_save_checks , <EOL> [ <EOL> ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> ] <EOL> ) <EOL> signals . pre_save . disconnect ( animal_pre_save_check ) <EOL> def test_dumpdata_uses_default_manager ( self ) : <EOL> """<STR_LIT>""" <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False , <EOL> ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False , <EOL> ) <EOL> animal = Animal ( <EOL> name = '<STR_LIT>' , <EOL> latin_name = '<STR_LIT>' , <EOL> count = <NUM_LIT:2> , <EOL> weight = <NUM_LIT> <EOL> ) <EOL> animal . save ( ) <EOL> stdout = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> format = '<STR_LIT>' , <EOL> stdout = stdout <EOL> ) <EOL> data = stdout . getvalue ( ) <EOL> data = re . sub ( '<STR_LIT>' , '<STR_LIT>' , data ) <EOL> lion_json = '<STR_LIT>' <EOL> emu_json = '<STR_LIT>' <EOL> platypus_json = '<STR_LIT>' <EOL> platypus_json = platypus_json % animal . pk <EOL> self . assertEqual ( len ( data ) , len ( '<STR_LIT>' % '<STR_LIT:U+002CU+0020>' . join ( [ lion_json , emu_json , platypus_json ] ) ) ) <EOL> self . assertTrue ( lion_json in data ) <EOL> self . assertTrue ( emu_json in data ) <EOL> self . assertTrue ( platypus_json in data ) <EOL> def test_proxy_model_included ( self ) : <EOL> """<STR_LIT>""" <EOL> stdout = StringIO ( ) <EOL> Widget ( name = '<STR_LIT>' ) . save ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> format = '<STR_LIT>' , <EOL> stdout = stdout <EOL> ) <EOL> self . assertEqual ( <EOL> stdout . getvalue ( ) , <EOL> """<STR_LIT>""" <EOL> ) <EOL> class NaturalKeyFixtureTests ( TestCase ) : <EOL> def assertRaisesMessage ( self , exc , msg , func , * args , ** kwargs ) : <EOL> try : <EOL> func ( * args , ** kwargs ) <EOL> except Exception , e : <EOL> self . assertEqual ( msg , str ( e ) ) <EOL> self . assertTrue ( isinstance ( e , exc ) , "<STR_LIT>" % ( exc , type ( e ) ) ) <EOL> def test_nk_deserialize ( self ) : <EOL> """<STR_LIT>""" <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> self . assertEqual ( <EOL> NKChild . objects . get ( pk = <NUM_LIT:1> ) . data , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> RefToNKChild . objects . get ( pk = <NUM_LIT:1> ) . nk_fk . data , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_nk_deserialize_xml ( self ) : <EOL> """<STR_LIT>""" <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> self . assertEqual ( <EOL> NKChild . objects . get ( pk = <NUM_LIT:2> ) . data , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> RefToNKChild . objects . get ( pk = <NUM_LIT:2> ) . nk_fk . data , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_nk_on_serialize ( self ) : <EOL> """<STR_LIT>""" <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> stdout = StringIO ( ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> format = '<STR_LIT>' , <EOL> use_natural_keys = True , <EOL> stdout = stdout , <EOL> ) <EOL> self . assertEqual ( <EOL> stdout . getvalue ( ) , <EOL> """<STR_LIT>""" <EOL> ) <EOL> def test_dependency_sorting ( self ) : <EOL> """<STR_LIT>""" <EOL> sorted_deps = sort_dependencies ( <EOL> [ ( '<STR_LIT>' , [ Book , Person , Store ] ) ] <EOL> ) <EOL> self . assertEqual ( <EOL> sorted_deps , <EOL> [ Store , Person , Book ] <EOL> ) <EOL> def test_dependency_sorting_2 ( self ) : <EOL> sorted_deps = sort_dependencies ( <EOL> [ ( '<STR_LIT>' , [ Book , Store , Person ] ) ] <EOL> ) <EOL> self . assertEqual ( <EOL> sorted_deps , <EOL> [ Store , Person , Book ] <EOL> ) <EOL> def test_dependency_sorting_3 ( self ) : <EOL> sorted_deps = sort_dependencies ( <EOL> [ ( '<STR_LIT>' , [ Store , Book , Person ] ) ] <EOL> ) <EOL> self . assertEqual ( <EOL> sorted_deps , <EOL> [ Store , Person , Book ] <EOL> ) <EOL> def test_dependency_sorting_4 ( self ) : <EOL> sorted_deps = sort_dependencies ( <EOL> [ ( '<STR_LIT>' , [ Store , Person , Book ] ) ] <EOL> ) <EOL> self . assertEqual ( <EOL> sorted_deps , <EOL> [ Store , Person , Book ] <EOL> ) <EOL> def test_dependency_sorting_5 ( self ) : <EOL> sorted_deps = sort_dependencies ( <EOL> [ ( '<STR_LIT>' , [ Person , Book , Store ] ) ] <EOL> ) <EOL> self . assertEqual ( <EOL> sorted_deps , <EOL> [ Store , Person , Book ] <EOL> ) <EOL> def test_dependency_sorting_6 ( self ) : <EOL> sorted_deps = sort_dependencies ( <EOL> [ ( '<STR_LIT>' , [ Person , Store , Book ] ) ] <EOL> ) <EOL> self . assertEqual ( <EOL> sorted_deps , <EOL> [ Store , Person , Book ] <EOL> ) <EOL> def test_dependency_sorting_dangling ( self ) : <EOL> sorted_deps = sort_dependencies ( <EOL> [ ( '<STR_LIT>' , [ Person , Circle1 , Store , Book ] ) ] <EOL> ) <EOL> self . assertEqual ( <EOL> sorted_deps , <EOL> [ Circle1 , Store , Person , Book ] <EOL> ) <EOL> def test_dependency_sorting_tight_circular ( self ) : <EOL> self . assertRaisesMessage ( <EOL> CommandError , <EOL> """<STR_LIT>""" , <EOL> sort_dependencies , <EOL> [ ( '<STR_LIT>' , [ Person , Circle2 , Circle1 , Store , Book ] ) ] , <EOL> ) <EOL> def test_dependency_sorting_tight_circular_2 ( self ) : <EOL> self . assertRaisesMessage ( <EOL> CommandError , <EOL> """<STR_LIT>""" , <EOL> sort_dependencies , <EOL> [ ( '<STR_LIT>' , [ Circle1 , Book , Circle2 ] ) ] , <EOL> ) <EOL> def test_dependency_self_referential ( self ) : <EOL> self . assertRaisesMessage ( <EOL> CommandError , <EOL> """<STR_LIT>""" , <EOL> sort_dependencies , <EOL> [ ( '<STR_LIT>' , [ Book , Circle3 ] ) ] , <EOL> ) <EOL> def test_dependency_sorting_long ( self ) : <EOL> self . assertRaisesMessage ( <EOL> CommandError , <EOL> """<STR_LIT>""" , <EOL> sort_dependencies , <EOL> [ ( '<STR_LIT>' , [ Person , Circle2 , Circle1 , Circle3 , Store , Book ] ) ] , <EOL> ) <EOL> def test_dependency_sorting_normal ( self ) : <EOL> sorted_deps = sort_dependencies ( <EOL> [ ( '<STR_LIT>' , [ Person , ExternalDependency , Book ] ) ] <EOL> ) <EOL> self . assertEqual ( <EOL> sorted_deps , <EOL> [ Person , Book , ExternalDependency ] <EOL> ) <EOL> def test_normal_pk ( self ) : <EOL> """<STR_LIT>""" <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> books = Book . objects . all ( ) <EOL> self . assertEqual ( <EOL> books . __repr__ ( ) , <EOL> """<STR_LIT>""" <EOL> ) <EOL> class TestTicket11101 ( TransactionTestCase ) : <EOL> def ticket_11101 ( self ) : <EOL> management . call_command ( <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> verbosity = <NUM_LIT:0> , <EOL> commit = False <EOL> ) <EOL> self . assertEqual ( Thingy . objects . count ( ) , <NUM_LIT:1> ) <EOL> transaction . rollback ( ) <EOL> self . assertEqual ( Thingy . objects . count ( ) , <NUM_LIT:0> ) <EOL> if settings . DATABASES [ DEFAULT_DB_ALIAS ] [ '<STR_LIT>' ] != '<STR_LIT>' : <EOL> def test_ticket_11101 ( self ) : <EOL> """<STR_LIT>""" <EOL> ticket_11101 = transaction . commit_manually ( self . ticket_11101 ) <EOL> ticket_11101 ( ) </s>
