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

Commit

Permalink
Merge pull request #3485 from gratipay/team-tweaks
Browse files Browse the repository at this point in the history
fix bug with revenue model
  • Loading branch information
rohitpaulk committed May 27, 2015
2 parents 117a7f3 + 5e55ca4 commit c91de57
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
18 changes: 11 additions & 7 deletions gratipay/models/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,22 @@ def _from_thing(cls, thing, value):
""".format(thing), (value,))

@classmethod
def create_new(cls, owner, fields):
def insert(cls, owner, **fields):
fields['slug_lower'] = fields['slug'].lower()
fields['owner'] = owner.username
return cls.db.one("""
INSERT INTO teams
(slug, slug_lower, name, homepage, product_or_service,
getting_involved, getting_paid, owner)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s)
(slug, slug_lower, name, homepage,
product_or_service, revenue_model, getting_involved, getting_paid,
owner)
VALUES (%(slug)s, %(slug_lower)s, %(name)s, %(homepage)s,
%(product_or_service)s, %(revenue_model)s, %(getting_involved)s,
%(getting_paid)s,
%(owner)s)
RETURNING teams.*::teams
""", (fields['slug'], fields['slug'].lower(), fields['name'], fields['homepage'],
fields['product_or_service'], fields['getting_involved'], fields['getting_paid'],
owner.username))
""", fields)

def get_og_title(self):
out = self.name
Expand Down
13 changes: 12 additions & 1 deletion tests/py/test_teams.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TestNewTeams(Harness):
'homepage': 'http://gratipay.com/',
'agree_terms': 'true',
'product_or_service': 'We make widgets.',
'revenue_model': 'People pay us',
'revenue_model': 'People pay us.',
'getting_involved': 'People do stuff.',
'getting_paid': 'We pay people.'
}
Expand Down Expand Up @@ -46,6 +46,17 @@ def test_can_create_new_team(self):
assert team
assert team.owner == 'alice'

def test_all_fields_persist(self):
self.make_participant('alice', claimed_time='now', email_address='', last_ach_result='')
self.post_new(dict(self.valid_data))
team = Team.from_slug('gratiteam')
assert team.name == 'Gratiteam'
assert team.homepage == 'http://gratipay.com/'
assert team.product_or_service == 'We make widgets.'
assert team.revenue_model == 'People pay us.'
assert team.getting_involved == 'People do stuff.'
assert team.getting_paid == 'We pay people.'

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
Expand Down
2 changes: 1 addition & 1 deletion www/teams/create.json.spt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ if request.method == 'POST':
fields['slug'] = slugize(fields['name'])

try:
Team.create_new(user.participant, fields)
Team.insert(user.participant, **fields)
except IntegrityError:
raise Response(400, _("Sorry, there is already a team using '{}'.", fields['slug']))

Expand Down

0 comments on commit c91de57

Please sign in to comment.