def testSubscribeAndPayDues(self): rank = self.createGroup('test').rank rank.monthlyDues = 15 rank.save() period = SubscriptionPeriod.objects.create( name = 'Monthly', dayOfMonth=1 ) plan = models.RankSubscriptionPlan.objects.create( rank = rank, member = self.user.member, period = period ) self.postAPI('/v1/subscription/', { 'user': '******', 'plan': '/v1/subscriptionplan/1/', } ) self.assertEqual(len(self.user.invoices.all()), 0) subscriptionAPI.processSubscriptions() self.assertEqual(len(self.user.invoices.all()), 1) subscriptionAPI.processSubscriptions() self.assertEqual(len(self.user.invoices.all()), 1) self.postAPI('/v1/payment/', { 'invoice': '/v1/invoice/1/', 'value': 15, 'method': 0, 'user': '******' } ) self.assertTrue(self.user.groups.filter(name='test').exists()) today = datetime.date.today() monthStart = datetime.date(year=today.year, month=today.month, day=1) monthEnd = datetime.date(year=today.year, month=today.month, day=calendar.monthrange(today.year, today.month)[1]) monthEnd += datetime.timedelta(days=1) membershipPeriod = self.user.member.membershipPeriods.all()[0] self.assertEqual(membershipPeriod.activeFromDate.date(), monthStart) self.assertEqual(membershipPeriod.activeToDate.date(), monthEnd) subscriptionAPI.processSubscriptions() self.assertEqual(len(self.user.invoices.all()), 1)
def handle(self, *args, **options): processSubscriptions()