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.
Here's a simple implementation of Team take perms
- Loading branch information
1 parent
fd303f1
commit 910e703
Showing
5 changed files
with
82 additions
and
1 deletion.
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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .takes import TakesMixin as Takes | ||
|
||
__all__ = ['Takes'] |
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from gratipay.models import add_event | ||
|
||
|
||
class TakesMixin(object): | ||
"""This mixin provides management of takes for | ||
:py:class:`~gratipay.models.team.Team` objects. | ||
""" | ||
|
||
def set_takes_enabled(self, to): | ||
"""Update whether takes are enabled for this team. | ||
:param bool to: whether the team should have takes enabled | ||
""" | ||
if type(to) is not bool: | ||
raise TypeError('Boolean required.') | ||
with self.db.get_cursor() as cursor: | ||
cursor.run("UPDATE teams SET takes_enabled=%s WHERE id=%s", (to, self.id)) | ||
add_event( cursor | ||
, 'team' | ||
, dict( action='set takes_enabled' | ||
, id=self.id | ||
, old_value=self.takes_enabled | ||
, new_value=to | ||
) | ||
) |
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from __future__ import absolute_import, division, print_function, unicode_literals | ||
|
||
from gratipay.testing import Harness | ||
from gratipay.models.team import Team, mixins | ||
from pytest import raises | ||
|
||
|
||
class Tests(Harness): | ||
|
||
def setUp(self): | ||
self.enterprise = self.make_team('The Enterprise') | ||
|
||
|
||
def test_team_object_subclasses_takes_mixin(self): | ||
assert isinstance(self.enterprise, mixins.Takes) | ||
|
||
def test_takes_enabled_defaults_to_false(self): | ||
assert self.enterprise.takes_enabled is False | ||
|
||
|
||
# ste - set_takes_enabled | ||
|
||
def test_ste_sets_takes_enabled(self): | ||
self.enterprise.set_takes_enabled(True) | ||
assert Team.from_slug('TheEnterprise').takes_enabled is True | ||
|
||
def test_ste_sets_takes_enabled_back_to_false(self): | ||
self.enterprise.set_takes_enabled(False) | ||
assert Team.from_slug('TheEnterprise').takes_enabled is False | ||
|
||
def test_ste_sets_takes_rejects_non_boolean_values(self): | ||
raises(TypeError, self.enterprise.set_takes_enabled, None) | ||
raises(TypeError, self.enterprise.set_takes_enabled, 'foo') | ||
raises(TypeError, self.enterprise.set_takes_enabled, 123) | ||
|
||
def test_ste_setting_takes_enabled_is_a_logged_event(self): | ||
self.enterprise.set_takes_enabled(True) | ||
events = self.db.all("SELECT * FROM events") | ||
assert len(events) == 1 | ||
assert events[0].type == 'team' | ||
assert events[0].payload['action'] == 'set takes_enabled' | ||
assert events[0].payload['old_value'] == False | ||
assert events[0].payload['new_value'] == True | ||
assert events[0].payload['id'] == self.enterprise.id |