<s> from __future__ import absolute_import <EOL> from django . core import mail <EOL> from django . core . urlresolvers import reverse <EOL> from sentry . models import AuditLogEntry , AuditLogEntryEvent , OrganizationMember <EOL> from sentry . testutils import TestCase , PermissionTestCase <EOL> class OrganizationMemberSettingsPermissionTest ( PermissionTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( OrganizationMemberSettingsPermissionTest , self ) . setUp ( ) <EOL> member = self . create_user ( ) <EOL> om = self . create_member ( user = member , organization = self . organization ) <EOL> self . path = reverse ( '<STR_LIT>' , args = [ self . organization . slug , om . id ] ) <EOL> def test_non_member_cannot_load ( self ) : <EOL> self . assert_non_member_cannot_access ( self . path ) <EOL> def test_member_can_load ( self ) : <EOL> self . assert_member_can_access ( self . path ) <EOL> class OrganizationMemberSettingsTest ( TestCase ) : <EOL> def test_renders_with_context ( self ) : <EOL> organization = self . create_organization ( name = '<STR_LIT:foo>' , owner = self . user ) <EOL> self . create_team ( name = '<STR_LIT:foo>' , organization = organization ) <EOL> team_2 = self . create_team ( name = '<STR_LIT:bar>' , organization = organization ) <EOL> user = self . create_user ( '<STR_LIT>' ) <EOL> member = self . create_member ( <EOL> organization = organization , <EOL> user = user , <EOL> role = '<STR_LIT>' , <EOL> teams = [ team_2 ] , <EOL> ) <EOL> path = reverse ( '<STR_LIT>' , <EOL> args = [ organization . slug , member . id ] ) <EOL> self . login_as ( self . user ) <EOL> resp = self . client . get ( path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> assert resp . context [ '<STR_LIT>' ] == organization <EOL> assert resp . context [ '<STR_LIT>' ] == member <EOL> assert resp . context [ '<STR_LIT>' ] <EOL> def test_setting_role ( self ) : <EOL> organization = self . create_organization ( name = '<STR_LIT:foo>' , owner = self . user ) <EOL> team_1 = self . create_team ( name = '<STR_LIT:foo>' , organization = organization ) <EOL> team_2 = self . create_team ( name = '<STR_LIT:bar>' , organization = organization ) <EOL> user = self . create_user ( '<STR_LIT>' ) <EOL> member = OrganizationMember . objects . create ( <EOL> organization = organization , <EOL> user = user , <EOL> role = '<STR_LIT>' , <EOL> ) <EOL> path = reverse ( '<STR_LIT>' , <EOL> args = [ organization . slug , member . id ] ) <EOL> self . login_as ( self . user ) <EOL> resp = self . client . post ( path , { <EOL> '<STR_LIT>' : [ team_1 . id , team_2 . id ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> assert resp . status_code == <NUM_LIT> <EOL> member = OrganizationMember . objects . get ( id = member . id ) <EOL> assert member . role == '<STR_LIT>' <EOL> assert member . teams . count ( ) == <NUM_LIT:2> <EOL> ale = AuditLogEntry . objects . get ( <EOL> organization = organization , <EOL> event = AuditLogEntryEvent . MEMBER_EDIT , <EOL> ) <EOL> assert ale . actor == self . user <EOL> assert ale . target_object == member . id <EOL> assert ale . target_user == user <EOL> assert ale . data <EOL> def test_setting_teams ( self ) : <EOL> organization = self . create_organization ( name = '<STR_LIT:foo>' , owner = self . user ) <EOL> team_1 = self . create_team ( name = '<STR_LIT:foo>' , organization = organization ) <EOL> team_2 = self . create_team ( name = '<STR_LIT:bar>' , organization = organization ) <EOL> user = self . create_user ( '<STR_LIT>' ) <EOL> member = OrganizationMember . objects . create ( <EOL> organization = organization , <EOL> user = user , <EOL> role = '<STR_LIT>' , <EOL> ) <EOL> path = reverse ( '<STR_LIT>' , <EOL> args = [ organization . slug , member . id ] ) <EOL> self . login_as ( self . user ) <EOL> resp = self . client . post ( path , { <EOL> '<STR_LIT>' : [ team_1 . id , team_2 . id ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> assert resp . status_code == <NUM_LIT> , resp . context [ '<STR_LIT>' ] . errors <EOL> member = OrganizationMember . objects . get ( id = member . id ) <EOL> assert member . role == '<STR_LIT>' <EOL> teams = list ( member . teams . all ( ) ) <EOL> assert team_1 in teams <EOL> assert team_2 in teams <EOL> assert len ( teams ) == <NUM_LIT:2> <EOL> ale = AuditLogEntry . objects . get ( <EOL> organization = organization , <EOL> event = AuditLogEntryEvent . MEMBER_EDIT , <EOL> ) <EOL> assert ale . actor == self . user <EOL> assert ale . target_object == member . id <EOL> assert ale . target_user == user <EOL> assert ale . data <EOL> def test_reinvite ( self ) : <EOL> organization = self . create_organization ( name = '<STR_LIT:foo>' , owner = self . user ) <EOL> member = OrganizationMember . objects . create ( <EOL> organization = organization , <EOL> email = '<STR_LIT>' , <EOL> ) <EOL> path = reverse ( '<STR_LIT>' , <EOL> args = [ organization . slug , member . id ] ) <EOL> self . login_as ( self . user ) <EOL> resp = self . client . post ( path , { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } ) <EOL> assert resp . status_code == <NUM_LIT> <EOL> assert len ( mail . outbox ) == <NUM_LIT:1> <EOL> assert mail . outbox [ <NUM_LIT:0> ] . to == [ '<STR_LIT>' ] <EOL> assert mail . outbox [ <NUM_LIT:0> ] . subject == '<STR_LIT>' <EOL> def test_cannot_edit_yourself ( self ) : <EOL> organization = self . create_organization ( name = '<STR_LIT:foo>' , owner = self . user ) <EOL> member = OrganizationMember . objects . get ( <EOL> organization = organization , <EOL> user = self . user , <EOL> ) <EOL> path = reverse ( '<STR_LIT>' , <EOL> args = [ organization . slug , member . id ] ) <EOL> self . login_as ( self . user ) <EOL> resp = self . client . get ( path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> assert resp . context [ '<STR_LIT>' ] == organization <EOL> assert resp . context [ '<STR_LIT>' ] == member <EOL> def test_admin_cant_edit ( self ) : <EOL> organization = self . create_organization ( name = '<STR_LIT:foo>' , owner = self . user ) <EOL> member = self . create_user ( '<STR_LIT>' , is_superuser = False ) <EOL> owner_om = OrganizationMember . objects . get ( <EOL> organization = organization , <EOL> user = self . user , <EOL> ) <EOL> OrganizationMember . objects . create ( <EOL> organization = organization , <EOL> user = member , <EOL> role = '<STR_LIT>' , <EOL> ) <EOL> path = reverse ( '<STR_LIT>' , <EOL> args = [ organization . slug , owner_om . id ] ) <EOL> self . login_as ( member ) <EOL> resp = self . client . get ( path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> assert resp . context [ '<STR_LIT>' ] == organization <EOL> assert resp . context [ '<STR_LIT>' ] == owner_om <EOL> def test_member_cant_edit ( self ) : <EOL> organization = self . create_organization ( name = '<STR_LIT:foo>' , owner = self . user ) <EOL> member = self . create_user ( '<STR_LIT>' , is_superuser = False ) <EOL> owner_om = OrganizationMember . objects . get ( <EOL> organization = organization , <EOL> user = self . user , <EOL> ) <EOL> OrganizationMember . objects . create ( <EOL> organization = organization , <EOL> user = member , <EOL> role = '<STR_LIT>' , <EOL> ) <EOL> path = reverse ( '<STR_LIT>' , <EOL> args = [ organization . slug , owner_om . id ] ) <EOL> self . login_as ( member ) <EOL> resp = self . client . get ( path ) <EOL> assert resp . status_code == <NUM_LIT:200> <EOL> self . assertTemplateUsed ( resp , '<STR_LIT>' ) <EOL> assert resp . context [ '<STR_LIT>' ] == organization <EOL> assert resp . context [ '<STR_LIT>' ] == owner_om </s>
