<s> from huxley . api . tests import ( DestroyAPITestCase , ListAPITestCase , <EOL> PartialUpdateAPITestCase , RetrieveAPITestCase ) <EOL> from huxley . core . models import School <EOL> from huxley . utils . test import TestSchools , TestUsers <EOL> class SchoolDetailGetTestCase ( RetrieveAPITestCase ) : <EOL> url_name = '<STR_LIT>' <EOL> def test_anonymous_user ( self ) : <EOL> '''<STR_LIT>''' <EOL> school = TestSchools . new_school ( ) <EOL> response = self . get_response ( school . id ) <EOL> self . assertNotAuthenticated ( response ) <EOL> def test_self ( self ) : <EOL> '''<STR_LIT>''' <EOL> school = TestSchools . new_school ( ) <EOL> self . client . login ( username = school . advisor . username , password = '<STR_LIT:test>' ) <EOL> response = self . get_response ( school . id ) <EOL> self . assertEqual ( response . data , { <EOL> '<STR_LIT:id>' : school . id , <EOL> '<STR_LIT>' : school . registered . isoformat ( ) , <EOL> '<STR_LIT:name>' : school . name , <EOL> '<STR_LIT:address>' : school . address , <EOL> '<STR_LIT>' : school . city , <EOL> '<STR_LIT:state>' : school . state , <EOL> '<STR_LIT>' : school . zip_code , <EOL> '<STR_LIT>' : school . country , <EOL> '<STR_LIT>' : school . primary_name , <EOL> '<STR_LIT>' : school . primary_gender , <EOL> '<STR_LIT>' : school . primary_email , <EOL> '<STR_LIT>' : school . primary_phone , <EOL> '<STR_LIT>' : school . primary_type , <EOL> '<STR_LIT>' : school . secondary_name , <EOL> '<STR_LIT>' : school . secondary_gender , <EOL> '<STR_LIT>' : school . secondary_email , <EOL> '<STR_LIT>' : school . secondary_phone , <EOL> '<STR_LIT>' : school . secondary_type , <EOL> '<STR_LIT>' : school . program_type , <EOL> '<STR_LIT>' : school . times_attended , <EOL> '<STR_LIT>' : school . international , <EOL> '<STR_LIT>' : school . waitlist , <EOL> '<STR_LIT>' : school . beginner_delegates , <EOL> '<STR_LIT>' : school . intermediate_delegates , <EOL> '<STR_LIT>' : school . advanced_delegates , <EOL> '<STR_LIT>' : school . spanish_speaking_delegates , <EOL> '<STR_LIT>' : school . chinese_speaking_delegates , <EOL> '<STR_LIT>' : school . country_preference_ids , <EOL> '<STR_LIT>' : list ( school . committeepreferences . all ( ) ) , <EOL> '<STR_LIT>' : school . registration_comments , <EOL> '<STR_LIT>' : float ( school . fees_owed ) , <EOL> '<STR_LIT>' : float ( school . fees_paid ) , <EOL> '<STR_LIT>' : school . assignments_finalized , <EOL> } ) <EOL> def test_other_user ( self ) : <EOL> '''<STR_LIT>''' <EOL> school = TestSchools . new_school ( ) <EOL> TestUsers . new_user ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . get_response ( school . id ) <EOL> self . assertPermissionDenied ( response ) <EOL> def test_superuser ( self ) : <EOL> '''<STR_LIT>''' <EOL> school = TestSchools . new_school ( ) <EOL> TestUsers . new_superuser ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . get_response ( school . id ) <EOL> self . assertEqual ( response . data , { <EOL> '<STR_LIT:id>' : school . id , <EOL> '<STR_LIT>' : school . registered . isoformat ( ) , <EOL> '<STR_LIT:name>' : school . name , <EOL> '<STR_LIT:address>' : school . address , <EOL> '<STR_LIT>' : school . city , <EOL> '<STR_LIT:state>' : school . state , <EOL> '<STR_LIT>' : school . zip_code , <EOL> '<STR_LIT>' : school . country , <EOL> '<STR_LIT>' : school . primary_name , <EOL> '<STR_LIT>' : school . primary_gender , <EOL> '<STR_LIT>' : school . primary_email , <EOL> '<STR_LIT>' : school . primary_phone , <EOL> '<STR_LIT>' : school . primary_type , <EOL> '<STR_LIT>' : school . secondary_name , <EOL> '<STR_LIT>' : school . secondary_gender , <EOL> '<STR_LIT>' : school . secondary_email , <EOL> '<STR_LIT>' : school . secondary_phone , <EOL> '<STR_LIT>' : school . secondary_type , <EOL> '<STR_LIT>' : school . program_type , <EOL> '<STR_LIT>' : school . times_attended , <EOL> '<STR_LIT>' : school . international , <EOL> '<STR_LIT>' : school . waitlist , <EOL> '<STR_LIT>' : school . beginner_delegates , <EOL> '<STR_LIT>' : school . intermediate_delegates , <EOL> '<STR_LIT>' : school . advanced_delegates , <EOL> '<STR_LIT>' : school . spanish_speaking_delegates , <EOL> '<STR_LIT>' : school . chinese_speaking_delegates , <EOL> '<STR_LIT>' : school . country_preference_ids , <EOL> '<STR_LIT>' : list ( school . committeepreferences . all ( ) ) , <EOL> '<STR_LIT>' : school . registration_comments , <EOL> '<STR_LIT>' : float ( school . fees_owed ) , <EOL> '<STR_LIT>' : float ( school . fees_paid ) , <EOL> '<STR_LIT>' : school . assignments_finalized , <EOL> } ) <EOL> class SchoolDetailPatchTestCase ( PartialUpdateAPITestCase ) : <EOL> url_name = '<STR_LIT>' <EOL> params = { '<STR_LIT:name>' : '<STR_LIT:name>' , '<STR_LIT>' : '<STR_LIT>' } <EOL> def setUp ( self ) : <EOL> self . school = TestSchools . new_school ( ) <EOL> self . user = self . school . advisor <EOL> def test_anonymous_user ( self ) : <EOL> '''<STR_LIT>''' <EOL> response = self . get_response ( self . school . id ) <EOL> updated_school = School . objects . get ( id = self . school . id ) <EOL> self . assertNotAuthenticated ( response ) <EOL> self . assertEqual ( updated_school . name , self . school . name ) <EOL> self . assertEqual ( updated_school . city , self . school . city ) <EOL> def test_self ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . client . login ( username = self . user . username , password = '<STR_LIT:test>' ) <EOL> response = self . get_response ( self . school . id , params = self . params ) <EOL> self . school = School . objects . get ( id = self . school . id ) <EOL> self . assertEqual ( response . data [ '<STR_LIT:name>' ] , self . school . name ) <EOL> self . assertEqual ( response . data [ '<STR_LIT>' ] , self . school . city ) <EOL> def test_other_user ( self ) : <EOL> '''<STR_LIT>''' <EOL> TestUsers . new_user ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . get_response ( self . school . id , params = self . params ) <EOL> updated_school = School . objects . get ( id = self . school . id ) <EOL> self . assertPermissionDenied ( response ) <EOL> self . assertEqual ( updated_school . name , self . school . name ) <EOL> self . assertEqual ( updated_school . city , self . school . city ) <EOL> def test_superuser ( self ) : <EOL> '''<STR_LIT>''' <EOL> TestUsers . new_superuser ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . get_response ( self . school . id , params = self . params ) <EOL> self . school = School . objects . get ( id = self . school . id ) <EOL> self . assertEqual ( response . data [ '<STR_LIT:name>' ] , self . school . name ) <EOL> self . assertEqual ( response . data [ '<STR_LIT>' ] , self . school . city ) <EOL> class SchoolDetailDeleteTestCase ( DestroyAPITestCase ) : <EOL> url_name = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . school = TestSchools . new_school ( ) <EOL> self . user = self . school . advisor <EOL> def test_anonymous_user ( self ) : <EOL> '''<STR_LIT>''' <EOL> response = self . get_response ( self . school . id ) <EOL> self . assertNotAuthenticated ( response ) <EOL> self . assertTrue ( School . objects . filter ( id = self . school . id ) . exists ( ) ) <EOL> def test_self ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . client . login ( username = self . user . username , password = '<STR_LIT:test>' ) <EOL> response = self . get_response ( self . school . id ) <EOL> self . assertEqual ( response . data , None ) <EOL> self . assertFalse ( School . objects . filter ( id = self . school . id ) . exists ( ) ) <EOL> def test_other_user ( self ) : <EOL> '''<STR_LIT>''' <EOL> TestUsers . new_user ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . get_response ( self . school . id ) <EOL> self . assertPermissionDenied ( response ) <EOL> self . assertTrue ( School . objects . filter ( id = self . school . id ) . exists ( ) ) <EOL> def test_superuser ( self ) : <EOL> '''<STR_LIT>''' <EOL> TestUsers . new_user ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . get_response ( self . school . id ) <EOL> self . assertPermissionDenied ( response ) <EOL> self . assertTrue ( School . objects . filter ( id = self . school . id ) . exists ( ) ) <EOL> class SchoolListGetTestCase ( ListAPITestCase ) : <EOL> url_name = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> self . school = TestSchools . new_school ( ) <EOL> self . user = self . school . advisor <EOL> def test_anonymous_user ( self ) : <EOL> '''<STR_LIT>''' <EOL> response = self . get_response ( ) <EOL> self . assertMethodNotAllowed ( response , '<STR_LIT:GET>' ) <EOL> def test_self ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT:test>' ) <EOL> response = self . get_response ( ) <EOL> self . assertMethodNotAllowed ( response , '<STR_LIT:GET>' ) <EOL> def test_superuser ( self ) : <EOL> '''<STR_LIT>''' <EOL> TestUsers . new_superuser ( username = '<STR_LIT:user>' , password = '<STR_LIT:user>' ) <EOL> self . client . login ( username = '<STR_LIT:user>' , password = '<STR_LIT:user>' ) <EOL> response = self . get_response ( ) <EOL> self . assertMethodNotAllowed ( response , '<STR_LIT:GET>' ) </s>
