def test_free_membership(self): self.user_membership.begins_at = session.utcnow().replace( day=self.membership_fee_current.booking_end.days + 1) end_date = last_day_of_month(session.utcnow().date()) self.assertEquals(0.00, estimate_balance(self.user, end_date))
def check_current_and_next_month(self, base): # End in grace-period in current month end_date = session.utcnow().date().replace( day=self.membership_fee_current.booking_begin.days - 1) self.assertEquals(base, estimate_balance(self.user, end_date)) # End after grace-period in current month end_date = self.membership_fee_current.ends_on self.assertEquals(base - 5.00, estimate_balance(self.user, end_date)) # End in the middle of next month end_date = session.utcnow().date().replace(day=14) + timedelta(weeks=4) self.assertEquals(base - 10.00, estimate_balance(self.user, end_date)) # End in grace-period of next month end_date = end_date.replace( day=self.membership_fee_current.booking_begin.days - 1) self.assertEquals(base - 5.00, estimate_balance(self.user, end_date))
def get(self, user_id): """ :param user_id: The ID of the user :return: The estimated balance of the given end_date """ parser = reqparse.RequestParser() parser.add_argument('end_date', dest='end_date', required=True, type=parse_iso_date) args = parser.parse_args() user = get_user_or_404(user_id) estimated_balance = estimate_balance(session.session, user, args.end_date) return jsonify(estimated_balance=estimated_balance)
def test_free_membership(self): new_start = session.utcnow().replace( day=self.membership_fee_current.booking_end.days + 1) self.user_membership.active_during = closedopen(new_start, None) end_date = last_day_of_month(session.utcnow().date()) assert estimate_balance(self.session, self.user, end_date) == 0.00