<s> from functools import partial <EOL> from django . test import TestCase <EOL> from django . contrib . auth . models import User <EOL> from django . test . utils import override_settings <EOL> from organizations . models import Organization <EOL> from organizations . utils import create_organization , model_field_attr <EOL> from test_accounts . models import Account <EOL> @ override_settings ( USE_TZ = True ) <EOL> class CreateOrgTests ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def setUp ( self ) : <EOL> self . user = User . objects . get ( username = "<STR_LIT>" ) <EOL> def test_create_organization ( self ) : <EOL> acme = create_organization ( self . user , "<STR_LIT>" , org_defaults = { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> self . assertTrue ( isinstance ( acme , Organization ) ) <EOL> self . assertEqual ( self . user , acme . owner . organization_user . user ) <EOL> self . assertTrue ( acme . owner . organization_user . is_admin ) <EOL> def test_create_custom_org ( self ) : <EOL> custom = create_organization ( self . user , "<STR_LIT>" , model = Account ) <EOL> self . assertTrue ( isinstance ( custom , Account ) ) <EOL> self . assertEqual ( self . user , custom . owner . organization_user . user ) <EOL> def test_defaults ( self ) : <EOL> """<STR_LIT>""" <EOL> org = create_organization ( self . user , "<STR_LIT>" , <EOL> org_defaults = { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : False } , <EOL> org_user_defaults = { "<STR_LIT>" : False } ) <EOL> self . assertFalse ( org . is_active ) <EOL> self . assertFalse ( org . owner . organization_user . is_admin ) <EOL> create_account = partial ( create_organization , model = Account , <EOL> org_defaults = { '<STR_LIT>' : <NUM_LIT> } , <EOL> org_user_defaults = { '<STR_LIT>' : '<STR_LIT:B>' } ) <EOL> myaccount = create_account ( self . user , name = "<STR_LIT>" ) <EOL> self . assertEqual ( myaccount . monthly_subscription , <NUM_LIT> ) <EOL> def test_backwards_compat ( self ) : <EOL> """<STR_LIT>""" <EOL> org = create_organization ( self . user , "<STR_LIT>" , "<STR_LIT>" , is_active = False ) <EOL> self . assertFalse ( org . is_active ) <EOL> custom = create_organization ( self . user , "<STR_LIT>" , org_model = Account ) <EOL> self . assertTrue ( isinstance ( custom , Account ) ) <EOL> class AttributeUtilTests ( TestCase ) : <EOL> def test_present_field ( self ) : <EOL> self . assertTrue ( model_field_attr ( User , '<STR_LIT:username>' , '<STR_LIT:max_length>' ) ) <EOL> def test_absent_field ( self ) : <EOL> self . assertRaises ( KeyError , model_field_attr , User , '<STR_LIT>' , <EOL> '<STR_LIT:max_length>' ) <EOL> def test_absent_attr ( self ) : <EOL> self . assertRaises ( AttributeError , model_field_attr , User , '<STR_LIT:username>' , <EOL> '<STR_LIT>' ) </s>
