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

Add an is_closed attribute to Participant #2485

Merged
merged 2 commits into from
Jun 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions branch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
BEGIN;

ALTER TABLE participants ADD COLUMN is_closed bool NOT NULL DEFAULT FALSE;

END;
2 changes: 2 additions & 0 deletions gittip/models/account_elsewhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ def opt_in(self, desired_username):
user.participant.change_username(desired_username)
except ProblemChangingUsername:
pass
if user.participant.is_closed:
user.participant.update_is_closed(False)
return user, newly_claimed

def save_token(self, token, refresh_token=None, expires=None):
Expand Down
20 changes: 20 additions & 0 deletions gittip/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ def cancel(self, disbursement_strategy):
self.clear_tips_giving(cursor)
self.clear_tips_receiving(cursor)
self.clear_personal_information(cursor)
self.update_is_closed(True, cursor)

return self.archive(cursor)

Expand Down Expand Up @@ -551,6 +552,25 @@ def update_goal(self, goal):
)
self.set_attributes(goal=goal)

def update_is_closed(self, is_closed, cursor=None):
ctx = None
if cursor is None:
ctx = self.db.get_cursor()
cursor = ctx.__enter__()
try:
cursor.run( "UPDATE participants SET is_closed=%(is_closed)s "
"WHERE username=%(username)s"
, dict(username=self.username, is_closed=is_closed)
)
add_event( cursor
, 'participant'
, dict(id=self.id, action='set', values=dict(is_closed=is_closed))
)
self.set_attributes(is_closed=is_closed)
finally:
if ctx is not None:
ctx.__exit__(None, None, None)


def set_tip_to(self, tippee, amount, cursor=None):
"""Given a Participant or username, and amount as str, return a tuple.
Expand Down
27 changes: 27 additions & 0 deletions tests/py/test_cancel.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,3 +293,30 @@ def test_cpi_clears_teams(self):
alice.clear_personal_information(cursor)

assert len(team.get_takes()) == 1


# uic = update_is_closed

def test_uic_updates_is_closed(self):
alice = self.make_participant('alice')
alice.update_is_closed(True)

assert alice.is_closed
assert Participant.from_username('alice').is_closed

def test_uic_updates_is_closed_False(self):
alice = self.make_participant('alice')
alice.update_is_closed(True)
alice.update_is_closed(False)

assert not alice.is_closed
assert not Participant.from_username('alice').is_closed

def test_uic_uses_supplied_cursor(self):
alice = self.make_participant('alice')

with self.db.get_cursor() as cursor:
alice.update_is_closed(True, cursor)
assert alice.is_closed
assert not Participant.from_username('alice').is_closed
assert Participant.from_username('alice').is_closed
8 changes: 8 additions & 0 deletions tests/py/test_elsewhere.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from gittip.elsewhere import UserInfo
from gittip.models.account_elsewhere import AccountElsewhere
from gittip.models.participant import Participant
from gittip.testing import Harness
import gittip.testing.elsewhere as user_info_examples

Expand Down Expand Up @@ -33,6 +34,13 @@ def test_opt_in_doesnt_have_to_change_username(self):
actual = account.opt_in('bob')[0].participant.username
assert actual == expected

def test_opt_in_resets_is_closed_to_false(self):
alice = self.make_elsewhere('twitter', 1, 'alice')
alice.participant.update_is_closed(True)
user = alice.opt_in('alice')[0]
assert not user.participant.is_closed
assert not Participant.from_username('alice').is_closed

def test_redirect_csrf(self):
response = self.client.GxT('/on/github/redirect')
assert response.code == 405
Expand Down