Navigation Menu

Skip to content

Commit

Permalink
Implement dissociation scheduled model method and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahinkka committed Jul 16, 2013
1 parent 6b9e8a9 commit 0ef4adb
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
20 changes: 18 additions & 2 deletions membership/models.py
Expand Up @@ -38,6 +38,7 @@ class PaymentAttachedError(Exception): pass
MEMBER_STATUS = (('N', _('New')),
('P', _('Pre-approved')),
('A', _('Approved')),
('S', _('Dissociation scheduled')),
('I', _('Dissociated')),
('D', _('Deleted')))
MEMBER_STATUS_DICT = tupletuple_to_dict(MEMBER_STATUS)
Expand Down Expand Up @@ -194,6 +195,7 @@ class Meta:
extra_info = models.TextField(blank=True, verbose_name=_('Additional information'))

locked = models.DateTimeField(blank=True, null=True, verbose_name=_('Membership locked'))
dissociation_scheduled = models.DateTimeField(blank=True, null=True, verbose_name=_('Dissociation scheduled'))
dissociated = models.DateTimeField(blank=True, null=True, verbose_name=_('Member dissociated'))

objects = MembershipManager()
Expand Down Expand Up @@ -298,9 +300,23 @@ def approve(self, user):
self.save()
log_change(self, user, change_message="Approved")

def dissociate(self, user):
def schedule_dissociation(self, user):
if self.status != 'A':
raise MembershipOperationError("A membership from other state than approved can't be dissociated.")
raise MembershipOperationError("A membership from other state than approved can't be scheduled for dissociation.")
if user == None:
msg = "Membership.schedule_dissociation() needs user object as a parameter"
logger.critical("%s" % traceback.format_exc())
logger.critical(msg)
raise MembershipOperationError(msg)

self.status = 'S'
self.dissociation_scheduled = datetime.now()
self.save()
log_change(self, user, change_message="Dissociation scheduled")

def dissociate(self, user):
if self.status not in ('A', 'S'):
raise MembershipOperationError("A membership from other state than dissociation scheduled or approved can't be dissociated.")
if user == None:
msg = "Membership.dissociate() needs user object as a parameter"
logger.critical("%s" % traceback.format_exc())
Expand Down
35 changes: 35 additions & 0 deletions membership/tests.py
Expand Up @@ -978,6 +978,34 @@ def test_preapproved_deletion(self):
self.assertEquals(Alias.objects.all().count(), 1)
self.assertFalse(Alias.objects.all()[0].is_valid())

class MemberDissociationScheduledTest(TestCase):
fixtures = ['membership_fees.json', 'test_user.json']
def setUp(self):
self.user = User.objects.get(id=1)

def test_application_dissociation(self):
m = create_dummy_member('N')
self.assertRaises(MembershipOperationError, m.schedule_dissociation, self.user)

def test_preapproved_dissociation(self):
m = create_dummy_member('N')
m.preapprove(self.user)
self.assertRaises(MembershipOperationError, m.schedule_dissociation, self.user)

def test_approved_dissociation(self):
m = create_dummy_member('N')
m.preapprove(self.user)
m.approve(self.user)

self.assertIsNone(m.dissociation_scheduled)
before = datetime.now()
m.schedule_dissociation(self.user)
after = datetime.now()

self.assertIsNotNone(m.dissociation_scheduled)
self.assertTrue(m.dissociation_scheduled > before)
self.assertTrue(m.dissociation_scheduled < after)

class MemberDissociationTest(TestCase):
fixtures = ['membership_fees.json', 'test_user.json']
def setUp(self):
Expand All @@ -992,6 +1020,13 @@ def test_preapproved_dissociation(self):
m.preapprove(self.user)
self.assertRaises(MembershipOperationError, m.dissociate, self.user)

def test_dissociation_scheduled_dissociation(self):
m = create_dummy_member('N')
m.preapprove(self.user)
m.approve(self.user)
m.schedule_dissociation(self.user)
m.dissociate(self.user)

def test_approved_dissociation(self):
m = create_dummy_member('N')
m.preapprove(self.user)
Expand Down

0 comments on commit 0ef4adb

Please sign in to comment.