Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Fix formatting in test_team_edit
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Dec 9, 2016
1 parent b9f3f99 commit 5f25219
Showing 1 changed file with 41 additions and 27 deletions.
68 changes: 41 additions & 27 deletions tests/py/test_team_edit.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ def test_edit(self):
}
data = json.loads(self.client.POST( '/enterprise/edit/edit.json'
, data=edit_data
, auth_as='picard').body)
, auth_as='picard'
).body)

team = T('enterprise')
assert data == team.to_dict()
Expand All @@ -265,8 +266,9 @@ def test_edit_supports_partial_updates(self):
'image': FileUpload(IMAGE, 'logo.png'),
}
self.client.POST( '/enterprise/edit/edit.json'
, data=edit_data
, auth_as='picard')
, data=edit_data
, auth_as='picard'
)

team = T('enterprise')
assert team.name == 'The Enterprise'
Expand All @@ -278,7 +280,8 @@ def test_edit_supports_partial_updates(self):
def test_edit_needs_auth(self):
self.make_team(slug='enterprise', is_approved=True)
response = self.client.PxST( '/enterprise/edit/edit.json'
, data={ 'name': 'Enterprise' })
, data={'name': 'Enterprise'}
)
assert response.code == 401
assert T('enterprise').name == 'The Enterprise'

Expand All @@ -288,14 +291,16 @@ def test_only_admin_and_owner_can_edit(self):
self.make_team(slug='enterprise', is_approved=True)

response = self.client.PxST( '/enterprise/edit/edit.json'
, data={ 'name': 'Enterprise' }
, auth_as='alice')
, data={'name': 'Enterprise'}
, auth_as='alice'
)
assert response.code == 403
assert T('enterprise').name == 'The Enterprise'

response = self.client.POST( '/enterprise/edit/edit.json'
, data={ 'name': 'Enterprise' }
, auth_as='admin')
, data={'name': 'Enterprise'}
, auth_as='admin'
)
assert response.code == 200
assert T('enterprise').name == 'Enterprise'

Expand All @@ -306,24 +311,27 @@ def test_cant_edit_closed_teams(self):
self.db.run("UPDATE teams SET is_closed = true WHERE slug = 'enterprise'")

response = self.client.PxST( '/enterprise/edit/edit.json'
, data={ 'name': 'Enterprise' }
, auth_as='picard')
, data={'name': 'Enterprise'}
, auth_as='picard'
)
assert response.code in (403, 410)
assert T('enterprise').name == 'The Enterprise'

def test_cant_edit_rejected_teams(self):
self.make_team(slug='enterprise', is_approved=False)
response = self.client.PxST( '/enterprise/edit/edit.json'
, data={ 'name': 'Enterprise' }
, auth_as='picard')
, data={'name': 'Enterprise'}
, auth_as='picard'
)
assert response.code == 403
assert T('enterprise').name == 'The Enterprise'

def test_can_edit_teams_under_review(self):
self.make_team(slug='enterprise', is_approved=None)
response = self.client.POST( '/enterprise/edit/edit.json'
, data={ 'name': 'Enterprise' }
, auth_as='picard')
, data={'name': 'Enterprise'}
, auth_as='picard'
)
assert response.code == 200
assert T('enterprise').name == 'Enterprise'

Expand All @@ -337,8 +345,9 @@ def test_can_only_edit_allowed_fields(self):
for field in fields:
if field not in allowed_fields:
response = self.client.POST( '/enterprise/edit/edit.json'
, data={ field: 'foo' }
, auth_as='picard')
, data={field: 'foo'}
, auth_as='picard'
)
new_team = T('enterprise')
assert response.code == 200
assert getattr(new_team, field) == getattr(team, field)
Expand All @@ -348,30 +357,33 @@ def test_edit_accepts_jpeg_and_png(self):
image_types = ['png', 'jpg', 'jpeg']
for i_type in image_types:
team.save_image(original='', large='', small='', image_type='image/png')
data = { 'image': FileUpload(IMAGE, 'logo.'+i_type) }
data = {'image': FileUpload(IMAGE, 'logo.'+i_type)}
response = self.client.POST( '/enterprise/edit/edit.json'
, data=data
, auth_as='picard')
, data=data
, auth_as='picard'
)
assert response.code == 200
assert team.load_image('original') == IMAGE

def test_edit_with_invalid_image_type_raises_error(self):
team = self.make_team(slug='enterprise', is_approved=True)
invalid_image_types = ['tiff', 'gif', 'bmp', 'svg']
for i_type in invalid_image_types:
data = { 'image': FileUpload(IMAGE, 'logo.'+i_type) }
data = {'image': FileUpload(IMAGE, 'logo.'+i_type)}
response = self.client.PxST( '/enterprise/edit/edit.json'
, data=data
, auth_as='picard')
, data=data
, auth_as='picard'
)
assert response.code == 400
assert "Please upload a PNG or JPG image." in response.body
assert team.load_image('original') == None

def test_edit_with_empty_values_raises_error(self):
self.make_team(slug='enterprise', is_approved=True)
response = self.client.PxST( '/enterprise/edit/edit.json'
, data={ 'name': ' ' }
, auth_as='picard')
, data={'name': ' '}
, auth_as='picard'
)
assert response.code == 400
assert T('enterprise').name == 'The Enterprise'

Expand All @@ -381,8 +393,9 @@ def test_edit_with_bad_url_raises_error(self):
, homepage='http://starwars-enterprise.com/')

r = self.client.PxST( '/enterprise/edit/edit.json'
, data={ 'homepage': 'foo' }
, auth_as='picard')
, data={'homepage': 'foo'}
, auth_as='picard'
)
assert r.code == 400
assert "Please enter an http[s]:// URL for the 'Homepage' field." in r.body
assert T('enterprise').homepage == 'http://starwars-enterprise.com/'
Expand All @@ -399,7 +412,8 @@ def test_edit_with_empty_data_does_nothing(self):
self.make_team(**team_data)
r = self.client.POST( '/enterprise/edit/edit.json'
, data={}
, auth_as='picard')
, auth_as='picard'
)
assert r.code == 200

team = T('enterprise')
Expand Down

0 comments on commit 5f25219

Please sign in to comment.