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

Commit

Permalink
Here's a simple implementation of takes_enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed May 10, 2016
1 parent 8685429 commit 1d7aa8d
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 12 deletions.
27 changes: 18 additions & 9 deletions gratipay/models/team/mixins/takes.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,28 @@
from __future__ import absolute_import, division, print_function, unicode_literals

from gratipay.models import add_event


class TakesMixin(object):
"""This mixing provides management of takes for
"""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.
def enable_takes(self):
"""Allow this Team to issue takes.
"""
pass

:param bool to: whether the team should have takes enabled
def disable_takes(self):
"""Prevent this Team from issuing takes.
"""
pass
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
)
)
5 changes: 5 additions & 0 deletions sql/branch.sql
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,8 @@ CREATE TRIGGER propagate_is_verified_removal
EXECUTE PROCEDURE update_has_verified_identity();

-- We don't need an INSERT trigger, because of the way the defaults play out.


-- https://github.com/gratipay/gratipay.com/pull/4017

ALTER TABLE teams ADD COLUMN takes_enabled bool NOT NULL DEFAULT false;
39 changes: 36 additions & 3 deletions tests/py/test_team_takes.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,44 @@
from __future__ import absolute_import, division, print_function, unicode_literals

from gratipay.testing import Harness
from gratipay.models.team import mixins
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):
enterprise = self.make_team('The Enterprise')
assert isinstance(enterprise, mixins.Takes)
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

0 comments on commit 1d7aa8d

Please sign in to comment.