<s> from __future__ import unicode_literals <EOL> from django . test import TestCase <EOL> from django . contrib . auth . models import User <EOL> from pinax . teams . models import Team , Membership , avatar_upload <EOL> import pinax . teams . receivers <EOL> class BaseTeamTests ( TestCase ) : <EOL> MANAGER_ACCESS = Team . MANAGER_ACCESS_ADD <EOL> MEMBER_ACCESS = Team . MEMBER_ACCESS_OPEN <EOL> def _create_team ( self ) : <EOL> return Team . objects . create ( <EOL> name = "<STR_LIT>" , <EOL> creator = self . user , <EOL> manager_access = self . MANAGER_ACCESS , <EOL> member_access = self . MEMBER_ACCESS <EOL> ) <EOL> def setUp ( self ) : <EOL> self . user = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> class AvatarUploadTests ( TestCase ) : <EOL> def test_avatar_upload_filename ( self ) : <EOL> path = avatar_upload ( None , "<STR_LIT>" ) <EOL> self . assertTrue ( path . startswith ( "<STR_LIT>" ) ) <EOL> self . assertTrue ( path . endswith ( "<STR_LIT>" ) ) <EOL> class TeamTests ( BaseTeamTests ) : <EOL> def test_team_creation ( self ) : <EOL> team = self . _create_team ( ) <EOL> self . assertEquals ( team . name , "<STR_LIT>" ) <EOL> self . assertEquals ( team . slug , "<STR_LIT>" ) <EOL> self . assertEquals ( team . creator , self . user ) <EOL> def test_team_absolute_url ( self ) : <EOL> team = self . _create_team ( ) <EOL> self . assertTrue ( team . slug in team . get_absolute_url ( ) ) <EOL> def test_team_str ( self ) : <EOL> team = self . _create_team ( ) <EOL> self . assertEquals ( str ( team ) , "<STR_LIT>" ) <EOL> def test_team_creation_owner_is_member ( self ) : <EOL> team = self . _create_team ( ) <EOL> team_user = team . memberships . all ( ) [ <NUM_LIT:0> ] <EOL> self . assertEquals ( str ( team_user ) , "<STR_LIT>" ) <EOL> def test_team_role_for ( self ) : <EOL> team = self . _create_team ( ) <EOL> self . assertEquals ( team . role_for ( self . user ) , Membership . ROLE_OWNER ) <EOL> def test_unknown_user ( self ) : <EOL> team = self . _create_team ( ) <EOL> other_user = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertIsNone ( team . for_user ( other_user ) ) <EOL> self . assertIsNone ( team . role_for ( other_user ) ) <EOL> def test_user_is_member ( self ) : <EOL> team = self . _create_team ( ) <EOL> other_user = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> team . add_user ( other_user , Membership . ROLE_MEMBER ) <EOL> self . assertTrue ( team . is_on_team ( other_user ) ) <EOL> def test_member_can_leave ( self ) : <EOL> team = self . _create_team ( ) <EOL> other_user = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> team . add_user ( other_user , Membership . ROLE_MEMBER ) <EOL> self . assertTrue ( team . can_leave ( other_user ) ) <EOL> def test_manager_cannot_leave ( self ) : <EOL> team = self . _create_team ( ) <EOL> self . assertFalse ( team . can_leave ( self . user ) ) <EOL> def test_owner_is_member ( self ) : <EOL> team = self . _create_team ( ) <EOL> self . assertTrue ( team . is_on_team ( self . user ) ) <EOL> class ManagerAddMemberOpenTests ( BaseTeamTests ) : <EOL> MANAGER_ACCESS = Team . MANAGER_ACCESS_ADD <EOL> MEMBER_ACCESS = Team . MEMBER_ACCESS_OPEN <EOL> def test_cannot_apply ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> self . assertFalse ( team . can_apply ( paltman ) ) <EOL> def test_can_apply ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertFalse ( team . can_apply ( paltman ) ) <EOL> def test_can_join_non_member ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertTrue ( team . can_join ( paltman ) ) <EOL> def test_can_join_invited ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> membership = team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> membership . state = Membership . STATE_INVITED <EOL> membership . save ( ) <EOL> self . assertTrue ( team . can_join ( User . objects . get ( username = "<STR_LIT>" ) ) ) <EOL> def test_can_join_declined ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> team . add_user ( paltman , Membership . STATE_DECLINED ) <EOL> self . assertFalse ( team . can_join ( paltman ) ) <EOL> class ManagerAddMemberApplicationTests ( BaseTeamTests ) : <EOL> MANAGER_ACCESS = Team . MANAGER_ACCESS_ADD <EOL> MEMBER_ACCESS = Team . MEMBER_ACCESS_APPLICATION <EOL> def test_cannot_apply ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> self . assertFalse ( team . can_apply ( paltman ) ) <EOL> def test_can_apply ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertTrue ( team . can_apply ( paltman ) ) <EOL> def test_can_join_non_member ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertFalse ( team . can_join ( paltman ) ) <EOL> def test_can_join_invited ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> membership = team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> membership . state = Membership . STATE_INVITED <EOL> membership . save ( ) <EOL> self . assertTrue ( team . can_join ( User . objects . get ( username = "<STR_LIT>" ) ) ) <EOL> def test_can_join_declined ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> team . add_user ( paltman , Membership . STATE_DECLINED ) <EOL> self . assertFalse ( team . can_join ( paltman ) ) <EOL> class ManagerAddMemberInvitationTests ( BaseTeamTests ) : <EOL> MANAGER_ACCESS = Team . MANAGER_ACCESS_ADD <EOL> MEMBER_ACCESS = Team . MEMBER_ACCESS_INVITATION <EOL> def test_cannot_apply ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> self . assertFalse ( team . can_apply ( paltman ) ) <EOL> def test_can_apply ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertFalse ( team . can_apply ( paltman ) ) <EOL> def test_can_join_non_member ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertFalse ( team . can_join ( paltman ) ) <EOL> def test_can_join_invited ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> membership = team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> membership . state = Membership . STATE_INVITED <EOL> membership . save ( ) <EOL> self . assertTrue ( team . can_join ( User . objects . get ( username = "<STR_LIT>" ) ) ) <EOL> def test_can_join_declined ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> team . add_user ( paltman , Membership . STATE_DECLINED ) <EOL> self . assertFalse ( team . can_join ( paltman ) ) <EOL> class ManagerInviteMemberOpenTests ( BaseTeamTests ) : <EOL> MANAGER_ACCESS = Team . MANAGER_ACCESS_INVITE <EOL> MEMBER_ACCESS = Team . MEMBER_ACCESS_OPEN <EOL> def test_cannot_apply ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> self . assertFalse ( team . can_apply ( paltman ) ) <EOL> def test_can_apply ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertFalse ( team . can_apply ( paltman ) ) <EOL> def test_can_join_non_member ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertTrue ( team . can_join ( paltman ) ) <EOL> def test_can_join_invited ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> membership = team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> membership . state = Membership . STATE_INVITED <EOL> membership . save ( ) <EOL> self . assertTrue ( team . can_join ( User . objects . get ( username = "<STR_LIT>" ) ) ) <EOL> def test_can_join_declined ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> membership = team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> membership . state = Membership . STATE_DECLINED <EOL> membership . save ( ) <EOL> self . assertFalse ( team . can_join ( paltman ) ) <EOL> class ManagerInviteMemberApplicationTests ( BaseTeamTests ) : <EOL> MANAGER_ACCESS = Team . MANAGER_ACCESS_INVITE <EOL> MEMBER_ACCESS = Team . MEMBER_ACCESS_APPLICATION <EOL> def test_cannot_apply ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> self . assertFalse ( team . can_apply ( paltman ) ) <EOL> def test_can_apply ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertTrue ( team . can_apply ( paltman ) ) <EOL> def test_can_join_non_member ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertFalse ( team . can_join ( paltman ) ) <EOL> def test_can_join_invited ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> membership = team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> membership . state = Membership . STATE_INVITED <EOL> membership . save ( ) <EOL> self . assertTrue ( team . can_join ( User . objects . get ( username = "<STR_LIT>" ) ) ) <EOL> def test_can_join_declined ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> membership = team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> membership . state = Membership . STATE_DECLINED <EOL> membership . save ( ) <EOL> self . assertFalse ( team . can_join ( paltman ) ) <EOL> class ManagerInviteMemberInvitationTests ( BaseTeamTests ) : <EOL> MANAGER_ACCESS = Team . MANAGER_ACCESS_INVITE <EOL> MEMBER_ACCESS = Team . MEMBER_ACCESS_INVITATION <EOL> def test_cannot_apply ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> self . assertFalse ( team . can_apply ( paltman ) ) <EOL> def test_can_apply ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertFalse ( team . can_apply ( paltman ) ) <EOL> def test_can_join_non_member ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> self . assertFalse ( team . can_join ( paltman ) ) <EOL> def test_can_join_invited ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> membership = team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> membership . state = Membership . STATE_INVITED <EOL> membership . save ( ) <EOL> self . assertTrue ( team . can_join ( User . objects . get ( username = "<STR_LIT>" ) ) ) <EOL> def test_can_join_declined ( self ) : <EOL> team = self . _create_team ( ) <EOL> paltman = User . objects . create_user ( username = "<STR_LIT>" ) <EOL> membership = team . add_user ( paltman , Membership . ROLE_MEMBER ) <EOL> membership . state = Membership . STATE_DECLINED <EOL> membership . save ( ) <EOL> self . assertFalse ( team . can_join ( paltman ) ) </s>
