<s> """<STR_LIT>""" <EOL> import datetime <EOL> from django . test import TestCase <EOL> from django . test . client import Client <EOL> from django . core . urlresolvers import reverse <EOL> from django . contrib . auth . models import User as DjangoUser <EOL> from treeio . identities . models import Contact <EOL> from treeio . core . models import User , Group , ModuleSetting , Module , Object , Perspective , AccessEntity <EOL> class CoreModelsTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_model_AccessEntity ( self ) : <EOL> obj = AccessEntity ( ) <EOL> obj . save ( ) <EOL> self . assertTrue ( obj . last_updated - datetime . datetime . now ( ) < datetime . timedelta ( seconds = <NUM_LIT:1> ) ) <EOL> self . assertIsNone ( obj . get_entity ( ) ) <EOL> self . assertFalse ( obj . is_user ( ) ) <EOL> self . assertEqual ( obj . __unicode__ ( ) , str ( obj . id ) ) <EOL> self . assertEqual ( obj . get_absolute_url ( ) , '<STR_LIT>' ) <EOL> def test_model_Group_basic ( self ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> obj = Group ( name = name ) <EOL> obj . save ( ) <EOL> self . assertIsNone ( obj . parent ) <EOL> self . assertIsNone ( obj . details ) <EOL> self . assertQuerysetEqual ( obj . child_set . all ( ) , [ ] ) <EOL> self . assertEqual ( obj . get_absolute_url ( ) , '<STR_LIT>' . format ( obj . id ) ) <EOL> self . assertEqual ( obj . get_root ( ) , obj ) <EOL> self . assertEqual ( obj . get_tree_path ( ) , [ obj ] ) <EOL> self . assertIsNone ( obj . get_contact ( ) ) <EOL> self . assertFalse ( obj . has_contact ( ) ) <EOL> self . assertEqual ( obj . get_fullname ( ) , name ) <EOL> self . assertEqual ( obj . get_perspective ( ) , Perspective . objects . all ( ) [ <NUM_LIT:0> ] ) <EOL> def test_model_User_profile ( self ) : <EOL> """<STR_LIT>""" <EOL> username = "<STR_LIT>" <EOL> password = "<STR_LIT:password>" <EOL> user = DjangoUser ( username = username ) <EOL> user . set_password ( password ) <EOL> user . save ( ) <EOL> self . assertEquals ( user . username , username ) <EOL> self . assertIsNotNone ( user . id ) <EOL> profile = user . profile <EOL> self . assertEquals ( profile . name , username ) <EOL> self . assertEquals ( profile . default_group , Group . objects . all ( ) [ <NUM_LIT:0> ] ) <EOL> self . assertQuerysetEqual ( profile . other_groups . all ( ) , [ ] ) <EOL> self . assertFalse ( profile . disabled ) <EOL> self . assertTrue ( profile . last_access - datetime . datetime . now ( ) < datetime . timedelta ( seconds = <NUM_LIT:1> ) ) <EOL> self . assertEqual ( profile . get_absolute_url ( ) , '<STR_LIT>' . format ( profile . id ) ) <EOL> oldpsw = profile . user . password <EOL> self . assertNotEqual ( profile . generate_new_password ( ) , oldpsw ) <EOL> self . assertQuerysetEqual ( profile . get_groups ( ) , map ( repr , [ profile . default_group ] ) ) <EOL> self . assertTrue ( profile . is_admin ( ) ) <EOL> self . assertEqual ( profile . get_username ( ) , username ) <EOL> self . assertEqual ( profile . get_perspective ( ) , Perspective . objects . get ( name = '<STR_LIT>' ) ) <EOL> self . assertEqual ( profile . get_contact ( ) , Contact . objects . get ( related_user = profile ) ) <EOL> self . assertTrue ( profile . has_contact ( ) ) <EOL> self . assertEqual ( profile . __unicode__ ( ) , username ) <EOL> def test_model_User_profile_change_default_group ( self ) : <EOL> username = "<STR_LIT>" <EOL> user = DjangoUser ( username = username ) <EOL> user . save ( ) <EOL> profile = user . profile <EOL> group = Group ( name = '<STR_LIT>' ) <EOL> group . save ( ) <EOL> profile . default_group = group <EOL> profile . save ( ) <EOL> profile = User . objects . get ( user = user ) <EOL> self . assertEquals ( profile . default_group , group ) <EOL> def test_model_Module_basic ( self ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> title = '<STR_LIT>' <EOL> url = '<STR_LIT>' <EOL> obj = Module ( name = name , title = title , url = url ) <EOL> obj . save ( ) <EOL> self . assertIsNotNone ( obj . id ) <EOL> obj = Module . objects . get ( id = obj . id ) <EOL> self . assertEquals ( obj . name , name ) <EOL> self . assertEquals ( obj . title , title ) <EOL> self . assertEquals ( obj . url , url ) <EOL> self . assertEquals ( obj . details , '<STR_LIT>' ) <EOL> self . assertTrue ( obj . display ) <EOL> self . assertTrue ( obj . system ) <EOL> self . assertEqual ( obj . get_absolute_url ( ) , '<STR_LIT>' . format ( obj . id ) ) <EOL> def test_model_Perspective_basic ( self ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT:test>' <EOL> obj = Perspective ( name = name ) <EOL> obj . save ( ) <EOL> self . assertIsNotNone ( obj . id ) <EOL> obj = Perspective . objects . get ( id = obj . id ) <EOL> self . assertEqual ( obj . name , name ) <EOL> self . assertEqual ( obj . details , '<STR_LIT>' ) <EOL> self . assertQuerysetEqual ( obj . modules . all ( ) , [ ] ) <EOL> self . assertQuerysetEqual ( obj . get_modules ( ) , map ( repr , Module . objects . all ( ) ) ) <EOL> self . assertEqual ( obj . get_absolute_url ( ) , '<STR_LIT>' . format ( obj . id ) ) <EOL> def test_model_Perspective_full ( self ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT:test>' <EOL> details = '<STR_LIT>' <EOL> obj = Perspective ( name = '<STR_LIT:test>' , details = details ) <EOL> obj . save ( ) <EOL> self . assertIsNotNone ( obj . id ) <EOL> obj = Perspective . objects . get ( id = obj . id ) <EOL> self . assertEqual ( obj . name , name ) <EOL> self . assertEqual ( obj . details , details ) <EOL> module = Module . objects . all ( ) [ <NUM_LIT:0> ] <EOL> obj . modules . add ( module ) <EOL> self . assertQuerysetEqual ( obj . modules . all ( ) , map ( repr , [ module ] ) ) <EOL> self . assertQuerysetEqual ( obj . get_modules ( ) , map ( repr , [ module ] ) ) <EOL> self . assertEqual ( obj . get_absolute_url ( ) , '<STR_LIT>' . format ( obj . id ) ) <EOL> class CoreViewsTestLoggedIn ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> username = "<STR_LIT:test>" <EOL> password = "<STR_LIT:password>" <EOL> def setUp ( self ) : <EOL> self . group , created = Group . objects . get_or_create ( name = '<STR_LIT:test>' ) <EOL> duser , created = DjangoUser . objects . get_or_create ( username = self . username ) <EOL> duser . set_password ( self . password ) <EOL> duser . save ( ) <EOL> self . user = duser <EOL> self . perspective = Perspective ( name = '<STR_LIT:test>' ) <EOL> self . perspective . set_default_user ( ) <EOL> self . perspective . save ( ) <EOL> self . client . login ( username = self . username , password = self . password ) <EOL> def test_user_logout ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> self . assertNotIn ( '<STR_LIT>' , self . client . session ) <EOL> def test_user_login ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , { '<STR_LIT:username>' : self . username , '<STR_LIT:password>' : self . password } ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_home_login ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( '<STR_LIT:/>' ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertEqual ( self . client . session [ '<STR_LIT>' ] , self . user . pk ) <EOL> def test_index_perspectives_login ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_perspective_add ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_perspective_view ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . perspective . id ] ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_perspective_edit ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . perspective . id ] ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_perspective_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . perspective . id ] ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_index_modules_login ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_index_users_login ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_core_user_add ( self ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> password = '<STR_LIT>' <EOL> data = { '<STR_LIT:name>' : name , '<STR_LIT:password>' : password , '<STR_LIT>' : password } <EOL> response = self . client . post ( path = reverse ( '<STR_LIT>' ) , data = data ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> profile = User . objects . get ( name = name ) <EOL> self . assertEquals ( profile . name , name ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' , args = [ profile . id ] ) ) <EOL> self . assertEquals ( self . client . login ( username = name , password = password ) , True ) <EOL> self . client . logout ( ) <EOL> response = self . client . post ( '<STR_LIT>' , { '<STR_LIT:username>' : name , '<STR_LIT:password>' : password } ) <EOL> self . assertRedirects ( response , '<STR_LIT:/>' ) <EOL> def test_core_user_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> name = '<STR_LIT>' <EOL> password = '<STR_LIT>' <EOL> user , created = DjangoUser . objects . get_or_create ( username = name ) <EOL> if created : <EOL> user . set_password ( password ) <EOL> user . save ( ) <EOL> response = self . client . post ( path = reverse ( '<STR_LIT>' , args = [ user . profile . id ] ) , <EOL> data = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> with self . assertRaises ( User . DoesNotExist ) : <EOL> User . objects . get ( name = name ) <EOL> with self . assertRaises ( DjangoUser . DoesNotExist ) : <EOL> DjangoUser . objects . get ( username = name ) <EOL> def test_core_user_invite ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_index_groups_login ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_core_group_add ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_core_group_view ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . group . id ] ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_core_group_edit ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . group . id ] ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_core_group_delete ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . group . id ] ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_core_settings_view ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_core_settings_edit ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> class CoreViewsTestNoLogin ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> username = "<STR_LIT:test>" <EOL> password = "<STR_LIT:password>" <EOL> def setUp ( self ) : <EOL> self . group , created = Group . objects . get_or_create ( name = '<STR_LIT:test>' ) <EOL> duser , created = DjangoUser . objects . get_or_create ( username = self . username ) <EOL> duser . set_password ( self . password ) <EOL> duser . save ( ) <EOL> self . user = duser <EOL> self . perspective = Perspective ( name = '<STR_LIT:test>' ) <EOL> self . perspective . set_default_user ( ) <EOL> self . perspective . save ( ) <EOL> def test_user_logout ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> self . assertNotIn ( '<STR_LIT>' , self . client . session ) <EOL> def test_user_login ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( reverse ( '<STR_LIT>' ) , { '<STR_LIT:username>' : self . username , '<STR_LIT:password>' : self . password } ) <EOL> self . assertRedirects ( response , '<STR_LIT:/>' ) <EOL> self . assertEqual ( self . client . session [ '<STR_LIT>' ] , self . user . pk ) <EOL> def test_logo ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT:200> ) <EOL> def test_home ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( '<STR_LIT:/>' ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_index_perspectives_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_perspective_add_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_perspective_view_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . perspective . id ] ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_perspective_edit_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . perspective . id ] ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_perspective_delete_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . perspective . id ] ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_index_modules_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_index_users_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_core_user_add_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_core_user_invite_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_index_groups_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_core_group_add_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_core_group_view_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . group . id ] ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_core_group_edit_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . group . id ] ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_core_group_delete_out ( self ) : <EOL> "<STR_LIT>" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' , args = [ self . group . id ] ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_core_settings_view_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> def test_core_settings_edit_out ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertRedirects ( response , reverse ( '<STR_LIT>' ) ) <EOL> class MiddlewareChatTest ( TestCase ) : <EOL> """<STR_LIT>""" <EOL> username = "<STR_LIT:test>" <EOL> password = "<STR_LIT:password>" <EOL> def setUp ( self ) : <EOL> self . group , created = Group . objects . get_or_create ( name = '<STR_LIT:test>' ) <EOL> duser , created = DjangoUser . objects . get_or_create ( username = self . username ) <EOL> duser . set_password ( self . password ) <EOL> duser . save ( ) <EOL> self . perspective = Perspective ( name = '<STR_LIT:test>' ) <EOL> self . perspective . set_default_user ( ) <EOL> self . perspective . save ( ) <EOL> def test_chat_get_new_messages ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( <EOL> '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_chat_connect ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( <EOL> '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_chat_disconnect ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( <EOL> '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_chat_add_new_message ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( <EOL> '<STR_LIT>' , { <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_chat_exit_from_conference ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( <EOL> '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_chat_add_users_in_conference ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( <EOL> '<STR_LIT>' , { <EOL> '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_chat_create_conference ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . post ( <EOL> '<STR_LIT>' , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) </s>
