<s> from __future__ import absolute_import <EOL> import copy <EOL> from django . conf import settings <EOL> from django . db import models <EOL> from django . db . models . loading import cache <EOL> from django . test import TestCase <EOL> from django . test . utils import override_settings <EOL> from . models import ( <EOL> Child1 , <EOL> Child2 , <EOL> Child3 , <EOL> Child4 , <EOL> Child5 , <EOL> Child6 , <EOL> Child7 , <EOL> AbstractBase1 , <EOL> AbstractBase2 , <EOL> AbstractBase3 , <EOL> ) <EOL> class ManagersRegressionTests ( TestCase ) : <EOL> def test_managers ( self ) : <EOL> Child1 . objects . create ( name = '<STR_LIT>' , data = '<STR_LIT>' ) <EOL> Child1 . objects . create ( name = '<STR_LIT>' , data = '<STR_LIT>' ) <EOL> Child2 . objects . create ( name = '<STR_LIT>' , data = '<STR_LIT>' , value = <NUM_LIT:1> ) <EOL> Child2 . objects . create ( name = '<STR_LIT>' , data = '<STR_LIT>' , value = <NUM_LIT> ) <EOL> Child3 . objects . create ( name = '<STR_LIT>' , data = '<STR_LIT>' , comment = '<STR_LIT:yes>' ) <EOL> Child3 . objects . create ( name = '<STR_LIT>' , data = '<STR_LIT>' , comment = '<STR_LIT>' ) <EOL> Child4 . objects . create ( name = '<STR_LIT>' , data = '<STR_LIT>' ) <EOL> Child4 . objects . create ( name = '<STR_LIT>' , data = '<STR_LIT>' ) <EOL> Child5 . objects . create ( name = '<STR_LIT>' , comment = '<STR_LIT:yes>' ) <EOL> Child5 . objects . create ( name = '<STR_LIT>' , comment = '<STR_LIT>' ) <EOL> Child6 . objects . create ( name = '<STR_LIT>' , data = '<STR_LIT>' , value = <NUM_LIT> ) <EOL> Child6 . objects . create ( name = '<STR_LIT>' , data = '<STR_LIT>' , value = <NUM_LIT> ) <EOL> Child7 . objects . create ( name = '<STR_LIT>' ) <EOL> Child7 . objects . create ( name = '<STR_LIT>' ) <EOL> self . assertQuerysetEqual ( Child1 . manager1 . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( Child1 . manager2 . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( Child1 . _default_manager . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( Child2 . _default_manager . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( Child2 . restricted . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( Child3 . _default_manager . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( Child3 . manager1 . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( Child3 . manager2 . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( Child4 . _default_manager . order_by ( '<STR_LIT:data>' ) , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> ) <EOL> self . assertQuerysetEqual ( Child4 . manager1 . all ( ) , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] , <EOL> ordered = False <EOL> ) <EOL> self . assertQuerysetEqual ( Child5 . _default_manager . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( Child6 . _default_manager . all ( ) , [ "<STR_LIT>" ] ) <EOL> self . assertQuerysetEqual ( Child7 . _default_manager . order_by ( '<STR_LIT:name>' ) , [ <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" <EOL> ] <EOL> ) <EOL> def test_abstract_manager ( self ) : <EOL> try : <EOL> AbstractBase3 . objects . all ( ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except AttributeError as e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> def test_custom_abstract_manager ( self ) : <EOL> try : <EOL> AbstractBase2 . restricted . all ( ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except AttributeError as e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> def test_explicit_abstract_manager ( self ) : <EOL> try : <EOL> AbstractBase1 . objects . all ( ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except AttributeError as e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> def test_swappable_manager ( self ) : <EOL> try : <EOL> old_app_models = copy . deepcopy ( cache . app_models ) <EOL> old_app_store = copy . deepcopy ( cache . app_store ) <EOL> settings . TEST_SWAPPABLE_MODEL = '<STR_LIT>' <EOL> class SwappableModel ( models . Model ) : <EOL> class Meta : <EOL> swappable = '<STR_LIT>' <EOL> try : <EOL> SwappableModel . objects . all ( ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except AttributeError as e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> finally : <EOL> del settings . TEST_SWAPPABLE_MODEL <EOL> cache . app_models = old_app_models <EOL> cache . app_store = old_app_store <EOL> def test_custom_swappable_manager ( self ) : <EOL> try : <EOL> old_app_models = copy . deepcopy ( cache . app_models ) <EOL> old_app_store = copy . deepcopy ( cache . app_store ) <EOL> settings . TEST_SWAPPABLE_MODEL = '<STR_LIT>' <EOL> class SwappableModel ( models . Model ) : <EOL> stuff = models . Manager ( ) <EOL> class Meta : <EOL> swappable = '<STR_LIT>' <EOL> try : <EOL> SwappableModel . stuff . all ( ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except AttributeError as e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> finally : <EOL> del settings . TEST_SWAPPABLE_MODEL <EOL> cache . app_models = old_app_models <EOL> cache . app_store = old_app_store <EOL> def test_explicit_swappable_manager ( self ) : <EOL> try : <EOL> old_app_models = copy . deepcopy ( cache . app_models ) <EOL> old_app_store = copy . deepcopy ( cache . app_store ) <EOL> settings . TEST_SWAPPABLE_MODEL = '<STR_LIT>' <EOL> class SwappableModel ( models . Model ) : <EOL> objects = models . Manager ( ) <EOL> class Meta : <EOL> swappable = '<STR_LIT>' <EOL> try : <EOL> SwappableModel . objects . all ( ) <EOL> self . fail ( '<STR_LIT>' ) <EOL> except AttributeError as e : <EOL> self . assertEqual ( str ( e ) , "<STR_LIT>" ) <EOL> finally : <EOL> del settings . TEST_SWAPPABLE_MODEL <EOL> cache . app_models = old_app_models <EOL> cache . app_store = old_app_store </s>
