This repository has been archived by the owner on Feb 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 308
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0ce0e34
commit 3d47be8
Showing
1 changed file
with
28 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -160,7 +160,7 @@ | |
AABJRU5ErkJggg==""") | ||
|
||
|
||
class TestTeams(Harness): | ||
class TestTeams(QueuedEmailHarness): | ||
|
||
valid_data = { | ||
'name': 'Gratiteam', | ||
|
@@ -198,16 +198,23 @@ def test_can_construct_from_id(self): | |
assert team.name == 'The Enterprise' | ||
assert team.owner == 'picard' | ||
|
||
def make_alice(self): | ||
self.make_participant( 'alice' | ||
, claimed_time='now' | ||
, email_address='[email protected]' | ||
, last_paypal_result='' | ||
) | ||
|
||
def test_can_create_new_team(self): | ||
self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='') | ||
self.make_alice() | ||
r = self.post_new(dict(self.valid_data)) | ||
team = self.db.one("SELECT * FROM teams") | ||
assert team | ||
assert team.owner == 'alice' | ||
assert json.loads(r.body)['review_url'] == team.review_url | ||
|
||
def test_all_fields_persist(self): | ||
self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='') | ||
self.make_alice() | ||
self.post_new(dict(self.valid_data)) | ||
team = T('gratiteam') | ||
assert team.name == 'Gratiteam' | ||
|
@@ -216,22 +223,31 @@ def test_all_fields_persist(self): | |
assert team.review_url == 'some-github-issue' | ||
|
||
def test_casing_of_urls_survives(self): | ||
self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='') | ||
self.make_alice() | ||
self.post_new(dict( self.valid_data | ||
, homepage='Http://gratipay.com/' | ||
)) | ||
team = T('gratiteam') | ||
assert team.homepage == 'Http://gratipay.com/' | ||
|
||
def test_casing_of_slug_survives(self): | ||
self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='') | ||
self.make_alice() | ||
data = dict(self.valid_data) | ||
data['name'] = 'GratiTeam' | ||
self.post_new(dict(data)) | ||
team = T('GratiTeam') | ||
assert team is not None | ||
assert team.slug_lower == 'gratiteam' | ||
|
||
def test_application_email_sent_to_owner(self): | ||
self.make_alice() | ||
self.post_new(dict(self.valid_data)) | ||
last_email = self.get_last_email() | ||
self.app.email_queue.flush() | ||
assert last_email['to'] == 'alice <[email protected]>' | ||
expected = "Thanks for your project application for" | ||
assert expected in last_email['body_text'] | ||
|
||
def test_401_for_anon_creating_new_team(self): | ||
self.post_new(self.valid_data, auth_as=None, expected=401) | ||
assert self.db.one("SELECT COUNT(*) FROM teams") == 0 | ||
|
@@ -249,53 +265,52 @@ def test_error_message_for_no_payout_route(self): | |
assert "You must attach a PayPal account to apply for a new team." in r.body | ||
|
||
def test_error_message_for_public_review(self): | ||
self.make_participant('alice', claimed_time='now', email_address='[email protected]', last_paypal_result='') | ||
self.make_alice() | ||
data = dict(self.valid_data) | ||
del data['agree_public'] | ||
r = self.post_new(data, expected=400) | ||
assert self.db.one("SELECT COUNT(*) FROM teams") == 0 | ||
assert "Sorry, you must agree to have your application publicly reviewed." in r.body | ||
|
||
def test_error_message_for_terms(self): | ||
self.make_participant('alice', claimed_time='now', email_address='[email protected]', last_paypal_result='') | ||
self.make_alice() | ||
data = dict(self.valid_data) | ||
del data['agree_terms'] | ||
r = self.post_new(data, expected=400) | ||
assert self.db.one("SELECT COUNT(*) FROM teams") == 0 | ||
assert "Sorry, you must agree to the terms of service." in r.body | ||
|
||
def test_error_message_for_missing_fields(self): | ||
self.make_participant('alice', claimed_time='now', email_address='[email protected]', last_paypal_result='') | ||
self.make_alice() | ||
data = dict(self.valid_data) | ||
del data['name'] | ||
r = self.post_new(data, expected=400) | ||
assert self.db.one("SELECT COUNT(*) FROM teams") == 0 | ||
assert "Please fill out the 'Team Name' field." in r.body | ||
|
||
def test_error_message_for_bad_url(self): | ||
self.make_participant('alice', claimed_time='now', email_address='[email protected]', last_paypal_result='') | ||
|
||
self.make_alice() | ||
r = self.post_new(dict(self.valid_data, homepage='foo'), expected=400) | ||
assert self.db.one("SELECT COUNT(*) FROM teams") == 0 | ||
assert "Please enter an http[s]:// URL for the 'Homepage' field." in r.body | ||
|
||
def test_error_message_for_invalid_team_name(self): | ||
self.make_participant('alice', claimed_time='now', email_address='[email protected]', last_paypal_result='') | ||
self.make_alice() | ||
data = dict(self.valid_data) | ||
data['name'] = '~Invalid:Name;' | ||
r = self.post_new(data, expected=400) | ||
assert self.db.one("SELECT COUNT(*) FROM teams") == 0 | ||
assert "Sorry, your team name is invalid." in r.body | ||
|
||
def test_error_message_for_slug_collision(self): | ||
self.make_participant('alice', claimed_time='now', email_address='[email protected]', last_paypal_result='') | ||
self.make_alice() | ||
self.post_new(dict(self.valid_data)) | ||
r = self.post_new(dict(self.valid_data), expected=400) | ||
assert self.db.one("SELECT COUNT(*) FROM teams") == 1 | ||
assert "Sorry, there is already a team using 'Gratiteam'." in r.body | ||
|
||
def test_stripping_required_inputs(self): | ||
self.make_participant('alice', claimed_time='now', email_address='[email protected]', last_paypal_result='') | ||
self.make_alice() | ||
data = dict(self.valid_data) | ||
data['name'] = " " | ||
r = self.post_new(data, expected=400) | ||
|
@@ -513,35 +528,3 @@ def test_canonicalizes(self): | |
response = self.client.GxT('/theenterprise/', return_after='cast') | ||
assert response.code == 302 | ||
assert response.headers['Location'] == '/TheEnterprise/' | ||
|
||
|
||
class TestTeamEmails(QueuedEmailHarness,Harness): | ||
|
||
valid_data = { | ||
'name': 'Gratiteam', | ||
'product_or_service': 'We make widgets.', | ||
'homepage': 'http://gratipay.com/', | ||
'onboarding_url': 'http://inside.gratipay.com/', | ||
'agree_public': 'true', | ||
'agree_payroll': 'true', | ||
'agree_terms': 'true', | ||
'image': FileUpload(IMAGE, 'logo.png'), | ||
} | ||
|
||
def post_new(self, data, auth_as='alice', expected=200): | ||
r = self.client.POST( '/teams/create.json' | ||
, data=data | ||
, auth_as=auth_as | ||
, raise_immediately=False | ||
) | ||
assert r.code == expected | ||
return r | ||
|
||
def test_application_email_sent_to_owner(self): | ||
self.make_participant('alice', claimed_time='now', email_address='[email protected]', last_paypal_result='') | ||
self.post_new(dict(self.valid_data)) | ||
last_email = self.get_last_email() | ||
self.app.email_queue.flush() | ||
assert last_email['to'] == 'alice <[email protected]>' | ||
expected = "Thanks for your project application for" | ||
assert expected in last_email['body_text'] |