def test_giving_is_updated_when_credit_card_fails(self, btd): alice = self.make_participant('alice', claimed_time='now', last_bill_result='') team = self.make_team(is_approved=True) alice.set_payment_instruction(team, '5.00') # funded assert alice.giving == D('5.00') assert T(team.slug).receiving == D('5.00') assert P(team.owner).taking == D('5.00') ExchangeRoute.from_network(alice, 'braintree-cc').update_error("Card expired") assert P('alice').giving == D('0.00') assert T(team.slug).receiving == D('0.00') assert P(team.owner).taking == D('0.00')
def test_giving_is_updated_when_credit_card_is_updated(self, btd): alice = self.make_participant('alice', claimed_time='now', last_bill_result='fail') team = self.make_team(is_approved=True) alice.set_payment_instruction(team, '5.00') # Not funded, failing card assert alice.giving == D('0.00') assert T(team.slug).receiving == D('0.00') # Alice updates her card.. ExchangeRoute.from_network(alice, 'braintree-cc').invalidate() ExchangeRoute.insert(alice, 'braintree-cc', '/cards/bar') assert alice.giving == D('5.00') assert T(team.slug).receiving == D('5.00')
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'} ) assert response.code == 401 assert T('enterprise').name == 'The Enterprise'
def test_admin_is_cool_though(self): self.make_participant('Q', is_admin=True) self.make_team() response = self.client.PxST('/TheEnterprise/edit/close', auth_as='Q') assert response.headers['Location'] == '/~Q/' assert response.code == 302 assert T('TheEnterprise').is_closed
def test_casing_of_urls_survives(self): self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='') self.post_new(dict( self.valid_data , homepage='Http://gratipay.com/' )) team = T('gratiteam') assert team.homepage == 'Http://gratipay.com/'
def test_casing_of_urls_survives(self): 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_teams_can_be_closed_via_http(self): self.make_team() response = self.client.PxST('/TheEnterprise/edit/close', auth_as='picard') assert response.headers['Location'] == '/~picard/' assert response.code == 302 assert T('TheEnterprise').is_closed
def test_ud_updates_ndistributing_to_in_the_db(self): self.enterprise.update_distributing( {self.crusher.id: { 'actual_amount': PENNY }}) fresh = T('TheEnterprise') assert fresh.distributing == PENNY assert fresh.ndistributing_to == 1
def test_casing_of_slug_survives(self): self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='') 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_all_fields_persist(self): self.make_alice() self.post_new(dict(self.valid_data)) team = T('gratiteam') assert team.name == 'Gratiteam' assert team.homepage == 'http://gratipay.com/' assert team.product_or_service == 'We make widgets.' assert team.review_url == 'some-github-issue'
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' ) assert response.code == 400 assert T('enterprise').name == 'The Enterprise'
def test_casing_of_slug_survives(self): 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_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' ) assert response.code == 200 assert T('enterprise').name == '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' ) assert response.code == 403 assert T('enterprise').name == 'The Enterprise'
def test_all_fields_persist(self): self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='') self.post_new(dict(self.valid_data)) team = T('gratiteam') assert team.name == 'Gratiteam' assert team.homepage == 'http://gratipay.com/' assert team.product_or_service == 'We make widgets.' fallback = 'https://github.com/gratipay/team-review/issues#error-401' assert team.review_url in (REVIEW_URL, fallback)
def test_only_admin_and_owner_can_edit(self): self.make_participant('alice', claimed_time='now') self.make_participant('admin', claimed_time='now', is_admin=True) self.make_team(slug='enterprise', is_approved=True) response = self.client.PxST( '/enterprise/edit/edit.json' , 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' ) assert response.code == 200 assert T('enterprise').name == 'Enterprise'
def test_admin_can_modify_is_approved(self): assert self.gratiteam.is_approved is None # Change to Approved self.hit({'status': 'approved'}) assert T('gratiteam').is_approved is True # Change to Rejected self.hit({'status': 'rejected'}) assert T('gratiteam').is_approved is False # Change back to Approved self.hit({'status': 'approved'}) assert T('gratiteam').is_approved is True # Change to Under Review self.hit({'status': 'unreviewed'}) assert T('gratiteam').is_approved is None
def test_cant_edit_closed_teams(self): self.make_team(slug='enterprise', is_approved=True) 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' ) assert response.code in (403, 410) assert T('enterprise').name == 'The Enterprise'
def check_parsing(self, lang, amount): alice = self.make_participant('alice', claimed_time='now', last_bill_result='') self.make_team(is_approved=True) self.client.POST('/TheEnterprise/payment-instruction.json', data={'amount': amount}, auth_as='alice', HTTP_ACCEPT_LANGUAGE=str(lang)) assert alice.get_payment_instruction( T('TheEnterprise'))['amount'] == D('0.05')
def test_edit_with_bad_url_raises_error(self): self.make_team( slug='enterprise' , is_approved=True , homepage='http://starwars-enterprise.com/') r = self.client.PxST( '/enterprise/edit/edit.json' , 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/'
def test_update_works(self): team = self.make_team(slug='enterprise') update_data = { 'name': 'Enterprise', 'product_or_service': 'We save galaxies.', 'homepage': 'http://starwars-enterprise.com/', 'onboarding_url': 'http://starwars-enterprise.com/onboarding', } team.update(**update_data) team = T('enterprise') for field in update_data: assert getattr(team, field) == update_data[field]
def test_casing_of_urls_survives(self): self.make_participant('alice', claimed_time='now', email_address='', last_paypal_result='') self.post_new( dict(self.valid_data, homepage='Http://gratipay.com/', onboarding_url='http://INSIDE.GRATipay.com/', todo_url='hTTPS://github.com/GRATIPAY')) team = T('gratiteam') assert team.homepage == 'Http://gratipay.com/' assert team.onboarding_url == 'http://INSIDE.GRATipay.com/' assert team.todo_url == 'hTTPS://github.com/GRATIPAY'
def test_can_only_edit_allowed_fields(self): allowed_fields = set(['name', 'image', 'product_or_service', 'homepage']) team = self.make_team(slug='enterprise', is_approved=None) fields = vars(team).keys() fields.remove('onboarding_url') # we are still keeping this in the db for now for field in fields: if field not in allowed_fields: response = self.client.POST( '/enterprise/edit/edit.json' , data={field: 'foo'} , auth_as='picard' ) new_team = T('enterprise') assert response.code == 200 assert getattr(new_team, field) == getattr(team, field)
def test_edit_supports_partial_updates(self): self.make_team(slug='enterprise', is_approved=True) edit_data = { 'product_or_service': 'We save galaxies.', 'homepage': 'http://starwars-enterprise.com/', 'image': FileUpload(IMAGE, 'logo.png'), } self.client.POST( '/enterprise/edit/edit.json' , data=edit_data , auth_as='picard' ) team = T('enterprise') assert team.name == 'The Enterprise' assert team.product_or_service == 'We save galaxies.' assert team.homepage == 'http://starwars-enterprise.com/' assert team.load_image('original') == IMAGE
def test_edit_with_empty_data_does_nothing(self): team_data = { 'slug': 'enterprise', 'is_approved': True, 'name': 'Enterprise', 'product_or_service': 'We save galaxies.', 'homepage': 'http://starwars-enterprise.com/', } self.make_team(**team_data) r = self.client.POST( '/enterprise/edit/edit.json' , data={} , auth_as='picard' ) assert r.code == 200 team = T('enterprise') for field in team_data: assert getattr(team, field) == team_data[field]
def test_edit(self): self.make_team(slug='enterprise', is_approved=True) edit_data = { 'name': 'Enterprise', 'product_or_service': 'We save galaxies.', 'homepage': 'http://starwars-enterprise.com/', 'image': FileUpload(IMAGE, 'logo.png'), } data = json.loads(self.client.POST( '/enterprise/edit/edit.json' , data=edit_data , auth_as='picard' ).body) team = T('enterprise') assert data == team.to_dict() assert team.name == 'Enterprise' assert team.product_or_service == 'We save galaxies.' assert team.homepage == 'http://starwars-enterprise.com/' assert team.load_image('original') == IMAGE
def test_team_objects_get_review_url(self): foo = self.make_team(name='foo') assert foo.review_url is None self.project_review_process.start(foo) assert foo.review_url == T('foo').review_url == 'some-github-issue'