def make_report(request, hookup_pk): hookup = Hookup.objects.get(pk=hookup_pk) report = Report(owner=request.user, hookup=hookup) report.save() #if it saved successfully, check if report count is above threshold if report.pk is not None: all_reports = Report.objects.filter(hookup=hookup) #if it is, use the helper function to pay out dividends if len(all_reports)>=Hookup.REPORT_THRESHOLD: pay_dividends(hookup)
def test_payout(self): prevpoints = self.user.points helpers.pay_dividends(self.hookup) self.user=HookrUser.objects.get(pk=self.user.pk) newpoints = self.user.points self.assertEqual(newpoints-prevpoints, 220000)