<s> from __future__ import absolute_import <EOL> from django . core . urlresolvers import reverse <EOL> from sentry . models import OrganizationMember , OrganizationMemberTeam , Team <EOL> from sentry . testutils import TestCase , PermissionTestCase <EOL> class CreateTeamPermissionTest ( PermissionTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( CreateTeamPermissionTest , self ) . setUp ( ) <EOL> self . path = reverse ( '<STR_LIT>' , args = [ self . organization . slug ] ) <EOL> def test_teamless_admin_can_load ( self ) : <EOL> self . assert_teamless_admin_can_access ( self . path ) <EOL> def test_team_admin_can_load ( self ) : <EOL> self . assert_team_admin_can_access ( self . path ) <EOL> def test_member_cannot_load ( self ) : <EOL> self . assert_member_cannot_access ( self . path ) <EOL> def test_owner_can_load ( self ) : <EOL> self . assert_owner_can_access ( self . path ) <EOL> class CreateTeamTest ( TestCase ) : <EOL> def test_renders_with_context ( self ) : <EOL> organization = self . create_organization ( ) <EOL> path = reverse ( '<STR_LIT>' , args = [ organization . slug ] ) <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>' ] <EOL> def test_submission ( self ) : <EOL> organization = self . create_organization ( ) <EOL> path = reverse ( '<STR_LIT>' , args = [ organization . slug ] ) <EOL> self . login_as ( self . user ) <EOL> resp = self . client . post ( path , { <EOL> '<STR_LIT:name>' : '<STR_LIT:bar>' , <EOL> } ) <EOL> assert resp . status_code == <NUM_LIT> , resp . context [ '<STR_LIT>' ] . errors <EOL> team = Team . objects . get ( organization = organization , name = '<STR_LIT:bar>' ) <EOL> member = OrganizationMember . objects . get ( <EOL> user = self . user , <EOL> organization = organization , <EOL> ) <EOL> assert OrganizationMemberTeam . objects . filter ( <EOL> organizationmember = member , <EOL> team = team , <EOL> is_active = True , <EOL> ) . exists ( ) <EOL> redirect_uri = reverse ( '<STR_LIT>' , args = [ organization . slug ] ) <EOL> assert resp [ '<STR_LIT>' ] == '<STR_LIT>' % ( <EOL> redirect_uri , team . slug ) <EOL> def test_admin_can_create_team ( self ) : <EOL> organization = self . create_organization ( ) <EOL> path = reverse ( '<STR_LIT>' , args = [ organization . slug ] ) <EOL> admin = self . create_user ( '<STR_LIT>' ) <EOL> self . create_member ( <EOL> organization = organization , <EOL> user = admin , <EOL> role = '<STR_LIT>' , <EOL> teams = [ ] , <EOL> ) <EOL> self . login_as ( admin ) <EOL> resp = self . client . post ( path , { <EOL> '<STR_LIT:name>' : '<STR_LIT:bar>' , <EOL> } ) <EOL> assert resp . status_code == <NUM_LIT> , resp . context [ '<STR_LIT>' ] . errors <EOL> assert Team . objects . filter ( <EOL> organization = organization , <EOL> name = '<STR_LIT:bar>' , <EOL> ) . exists ( ) </s>
