<s> """<STR_LIT>""" <EOL> import datetime <EOL> from operator import attrgetter <EOL> from django . test import TestCase <EOL> from models import ( Place , Restaurant , ItalianRestaurant , ParkingLot , <EOL> ParkingLot2 , ParkingLot3 , Supplier , Wholesaler , Child , SelfRefParent , <EOL> SelfRefChild , ArticleWithAuthor , M2MChild , QualityControl , DerivedM , <EOL> Person , BirthdayParty , BachelorParty , MessyBachelorParty , <EOL> InternalCertificationAudit ) <EOL> class ModelInheritanceTest ( TestCase ) : <EOL> def test_model_inheritance ( self ) : <EOL> place1 = Place ( <EOL> name = "<STR_LIT>" , <EOL> address = '<STR_LIT>' ) <EOL> place1 . save_base ( raw = True ) <EOL> restaurant = Restaurant ( <EOL> place_ptr = place1 , <EOL> serves_hot_dogs = True , <EOL> serves_pizza = False ) <EOL> restaurant . save_base ( raw = True ) <EOL> italian_restaurant = ItalianRestaurant ( <EOL> restaurant_ptr = restaurant , <EOL> serves_gnocchi = True ) <EOL> italian_restaurant . save_base ( raw = True ) <EOL> place2 = Place ( name = '<STR_LIT>' , address = '<STR_LIT>' ) <EOL> place2 . save_base ( raw = True ) <EOL> park = ParkingLot ( parent = place2 , capacity = <NUM_LIT:100> ) <EOL> park . save_base ( raw = True ) <EOL> places = list ( Place . objects . all ( ) ) <EOL> self . assertEqual ( places , [ place1 , place2 ] ) <EOL> dicts = list ( Restaurant . objects . values ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( dicts , [ { <EOL> '<STR_LIT:name>' : u"<STR_LIT>" , <EOL> '<STR_LIT>' : True <EOL> } ] ) <EOL> dicts = list ( ItalianRestaurant . objects . values ( <EOL> '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( dicts , [ { <EOL> '<STR_LIT:name>' : u"<STR_LIT>" , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : True , <EOL> } ] ) <EOL> dicts = list ( ParkingLot . objects . values ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( dicts , [ { <EOL> '<STR_LIT>' : <NUM_LIT:100> , <EOL> '<STR_LIT:name>' : u'<STR_LIT>' , <EOL> } ] ) <EOL> place1 . name = "<STR_LIT>" <EOL> place1 . save_base ( raw = True ) <EOL> restaurant . serves_hot_dogs = False <EOL> restaurant . save_base ( raw = True ) <EOL> italian_restaurant . serves_gnocchi = False <EOL> italian_restaurant . save_base ( raw = True ) <EOL> place2 . name = '<STR_LIT>' <EOL> place2 . save_base ( raw = True ) <EOL> park . capacity = <NUM_LIT:50> <EOL> park . save_base ( raw = True ) <EOL> places = list ( Place . objects . all ( ) ) <EOL> self . assertEqual ( places , [ place2 , place1 ] ) <EOL> self . assertEqual ( places [ <NUM_LIT:0> ] . name , '<STR_LIT>' ) <EOL> self . assertEqual ( places [ <NUM_LIT:1> ] . name , "<STR_LIT>" ) <EOL> dicts = list ( Restaurant . objects . values ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( dicts , [ { <EOL> '<STR_LIT:name>' : u"<STR_LIT>" , <EOL> '<STR_LIT>' : False , <EOL> } ] ) <EOL> dicts = list ( ItalianRestaurant . objects . values ( <EOL> '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( dicts , [ { <EOL> '<STR_LIT:name>' : u"<STR_LIT>" , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> } ] ) <EOL> dicts = list ( ParkingLot . objects . values ( '<STR_LIT:name>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( dicts , [ { <EOL> '<STR_LIT>' : <NUM_LIT:50> , <EOL> '<STR_LIT:name>' : u'<STR_LIT>' , <EOL> } ] ) <EOL> italian_restaurant . name = "<STR_LIT>" <EOL> italian_restaurant . save_base ( raw = True ) <EOL> dicts = list ( ItalianRestaurant . objects . values ( <EOL> '<STR_LIT:name>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( dicts , [ { <EOL> '<STR_LIT:name>' : u"<STR_LIT>" , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> } ] ) <EOL> def test_issue_7105 ( self ) : <EOL> obj = Child . objects . create ( <EOL> name = '<STR_LIT>' , <EOL> created = datetime . datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> dates = list ( Child . objects . dates ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEqual ( dates , [ datetime . datetime ( <NUM_LIT> , <NUM_LIT:6> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:0> ) ] ) <EOL> def test_issue_7276 ( self ) : <EOL> place1 = Place ( <EOL> name = "<STR_LIT>" , <EOL> address = '<STR_LIT>' ) <EOL> place1 . save_base ( raw = True ) <EOL> restaurant = Restaurant ( <EOL> place_ptr = place1 , <EOL> serves_hot_dogs = True , <EOL> serves_pizza = False ) <EOL> restaurant . save_base ( raw = True ) <EOL> italian_restaurant = ItalianRestaurant ( <EOL> restaurant_ptr = restaurant , <EOL> serves_gnocchi = True ) <EOL> italian_restaurant . save_base ( raw = True ) <EOL> ident = ItalianRestaurant . objects . all ( ) [ <NUM_LIT:0> ] . id <EOL> self . assertEqual ( Place . objects . get ( pk = ident ) , place1 ) <EOL> xx = Restaurant . objects . create ( <EOL> name = '<STR_LIT:a>' , <EOL> address = '<STR_LIT>' , <EOL> serves_hot_dogs = True , <EOL> serves_pizza = False ) <EOL> Restaurant . objects . all ( ) . delete ( ) <EOL> self . assertRaises ( <EOL> Place . DoesNotExist , <EOL> Place . objects . get , <EOL> pk = ident ) <EOL> self . assertRaises ( <EOL> ItalianRestaurant . DoesNotExist , <EOL> ItalianRestaurant . objects . get , <EOL> pk = ident ) <EOL> def test_issue_6755 ( self ) : <EOL> """<STR_LIT>""" <EOL> r = Restaurant ( serves_pizza = False ) <EOL> r . save ( ) <EOL> self . assertEqual ( r . id , r . place_ptr_id ) <EOL> orig_id = r . id <EOL> r = Restaurant ( place_ptr_id = orig_id , serves_pizza = True ) <EOL> r . save ( ) <EOL> self . assertEqual ( r . id , orig_id ) <EOL> self . assertEqual ( r . id , r . place_ptr_id ) <EOL> def test_issue_7488 ( self ) : <EOL> suppliers = Supplier . objects . filter ( <EOL> restaurant = Restaurant ( name = '<STR_LIT>' , address = '<STR_LIT>' ) ) <EOL> suppliers = list ( suppliers ) <EOL> self . assertEqual ( suppliers , [ ] ) <EOL> def test_issue_11764 ( self ) : <EOL> """<STR_LIT>""" <EOL> wholesalers = list ( Wholesaler . objects . all ( ) . select_related ( ) ) <EOL> self . assertEqual ( wholesalers , [ ] ) <EOL> def test_issue_7853 ( self ) : <EOL> """<STR_LIT>""" <EOL> obj = SelfRefChild . objects . create ( child_data = <NUM_LIT> , parent_data = <NUM_LIT> ) <EOL> obj . delete ( ) <EOL> def test_get_next_previous_by_date ( self ) : <EOL> """<STR_LIT>""" <EOL> c1 = ArticleWithAuthor ( <EOL> headline = '<STR_LIT>' , <EOL> author = "<STR_LIT>" , <EOL> pub_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:1> , <NUM_LIT:3> , <NUM_LIT:0> ) ) <EOL> c1 . save ( ) <EOL> c2 = ArticleWithAuthor ( <EOL> headline = '<STR_LIT>' , <EOL> author = "<STR_LIT>" , <EOL> pub_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:1> , <NUM_LIT:10> , <NUM_LIT:0> ) ) <EOL> c2 . save ( ) <EOL> c3 = ArticleWithAuthor ( <EOL> headline = '<STR_LIT>' , <EOL> author = "<STR_LIT>" , <EOL> pub_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:2> ) ) <EOL> c3 . save ( ) <EOL> self . assertEqual ( c1 . get_next_by_pub_date ( ) , c2 ) <EOL> self . assertEqual ( c2 . get_next_by_pub_date ( ) , c3 ) <EOL> self . assertRaises ( <EOL> ArticleWithAuthor . DoesNotExist , <EOL> c3 . get_next_by_pub_date ) <EOL> self . assertEqual ( c3 . get_previous_by_pub_date ( ) , c2 ) <EOL> self . assertEqual ( c2 . get_previous_by_pub_date ( ) , c1 ) <EOL> self . assertRaises ( <EOL> ArticleWithAuthor . DoesNotExist , <EOL> c1 . get_previous_by_pub_date ) <EOL> def test_inherited_fields ( self ) : <EOL> """<STR_LIT>""" <EOL> m2mchildren = list ( M2MChild . objects . filter ( articles__isnull = False ) ) <EOL> self . assertEqual ( m2mchildren , [ ] ) <EOL> qs = ArticleWithAuthor . objects . order_by ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> sql = qs . query . get_compiler ( qs . db ) . as_sql ( ) [ <NUM_LIT:0> ] <EOL> fragment = sql [ sql . find ( '<STR_LIT>' ) : ] <EOL> pos = fragment . find ( '<STR_LIT>' ) <EOL> self . assertEqual ( fragment . find ( '<STR_LIT>' , pos + <NUM_LIT:1> ) , - <NUM_LIT:1> ) <EOL> def test_queryset_update_on_parent_model ( self ) : <EOL> """<STR_LIT>""" <EOL> article = ArticleWithAuthor . objects . create ( <EOL> author = "<STR_LIT>" , <EOL> headline = "<STR_LIT>" , <EOL> pub_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT:0> ) ) <EOL> update = ArticleWithAuthor . objects . filter ( <EOL> author = "<STR_LIT>" ) . update ( headline = "<STR_LIT>" ) <EOL> self . assertEqual ( update , <NUM_LIT:1> ) <EOL> update = ArticleWithAuthor . objects . filter ( <EOL> pk = article . pk ) . update ( headline = "<STR_LIT>" ) <EOL> self . assertEqual ( update , <NUM_LIT:1> ) <EOL> derivedm1 = DerivedM . objects . create ( <EOL> customPK = <NUM_LIT> , <EOL> base_name = "<STR_LIT>" , <EOL> derived_name = "<STR_LIT>" ) <EOL> self . assertEqual ( derivedm1 . customPK , <NUM_LIT> ) <EOL> self . assertEqual ( derivedm1 . base_name , '<STR_LIT>' ) <EOL> self . assertEqual ( derivedm1 . derived_name , '<STR_LIT>' ) <EOL> derivedms = list ( DerivedM . objects . all ( ) ) <EOL> self . assertEqual ( derivedms , [ derivedm1 ] ) <EOL> def test_use_explicit_o2o_to_parent_as_pk ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEqual ( ParkingLot2 . _meta . pk . name , "<STR_LIT>" ) <EOL> self . assertEqual ( ParkingLot3 . _meta . pk . name , "<STR_LIT:primary_key>" ) <EOL> self . assertEqual ( <EOL> ParkingLot3 . _meta . get_ancestor_link ( Place ) . name , <EOL> "<STR_LIT>" ) <EOL> def test_all_fields_from_abstract_base_class ( self ) : <EOL> """<STR_LIT>""" <EOL> QualityControl . objects . create ( <EOL> headline = "<STR_LIT>" , <EOL> pub_date = datetime . datetime . now ( ) , <EOL> quality = <NUM_LIT:10> , <EOL> assignee = "<STR_LIT>" ) <EOL> def test_abstract_base_class_m2m_relation_inheritance ( self ) : <EOL> p1 = Person . objects . create ( name = '<STR_LIT>' ) <EOL> p2 = Person . objects . create ( name = '<STR_LIT>' ) <EOL> p3 = Person . objects . create ( name = '<STR_LIT>' ) <EOL> p4 = Person . objects . create ( name = '<STR_LIT>' ) <EOL> birthday = BirthdayParty . objects . create ( <EOL> name = '<STR_LIT>' ) <EOL> birthday . attendees = [ p1 , p3 ] <EOL> bachelor = BachelorParty . objects . create ( name = '<STR_LIT>' ) <EOL> bachelor . attendees = [ p2 , p4 ] <EOL> parties = list ( p1 . birthdayparty_set . all ( ) ) <EOL> self . assertEqual ( parties , [ birthday ] ) <EOL> parties = list ( p1 . bachelorparty_set . all ( ) ) <EOL> self . assertEqual ( parties , [ ] ) <EOL> parties = list ( p2 . bachelorparty_set . all ( ) ) <EOL> self . assertEqual ( parties , [ bachelor ] ) <EOL> self . assertFalse ( hasattr ( p2 , '<STR_LIT>' ) ) <EOL> messy = MessyBachelorParty . objects . create ( <EOL> name = '<STR_LIT>' ) <EOL> messy . attendees = [ p4 ] <EOL> messy_parent = messy . bachelorparty_ptr <EOL> parties = list ( p4 . bachelorparty_set . all ( ) ) <EOL> self . assertEqual ( parties , [ bachelor , messy_parent ] ) <EOL> def test_11369 ( self ) : <EOL> """<STR_LIT>""" <EOL> self . assertEquals ( <EOL> InternalCertificationAudit . _meta . verbose_name_plural , <EOL> u'<STR_LIT>' <EOL> ) <EOL> def test_inherited_nullable_exclude ( self ) : <EOL> obj = SelfRefChild . objects . create ( child_data = <NUM_LIT> , parent_data = <NUM_LIT> ) <EOL> self . assertQuerysetEqual ( <EOL> SelfRefParent . objects . exclude ( self_data = <NUM_LIT> ) , [ <EOL> obj . pk <EOL> ] , <EOL> attrgetter ( "<STR_LIT>" ) <EOL> ) <EOL> self . assertQuerysetEqual ( <EOL> SelfRefChild . objects . exclude ( self_data = <NUM_LIT> ) , [ <EOL> obj . pk <EOL> ] , <EOL> attrgetter ( "<STR_LIT>" ) <EOL> ) </s>
