def test_redeem_voucher_with_good_voucher(self): self.sign_out() user = test.factories.user(name="free_user", email="*****@*****.**") user.is_paid = 0 user.save() self.sign_in(user.name, "password") response = self.fetch_url("/account/settings") # verify this account is currently free self.assertTrue( response.body.find("You are currently using a free account.") > -1) arguments = {"key": "unclaimed"} # this will post and redirect to the settings page which should # then reflect that we are a paid user with 5 years of credit response = self.post_url("/account/redeem", arguments) self.assertTrue(response.body.find("5 Years") > -1) payments = PaymentLog.where("user_id=%s", user.id) self.assertEquals(len(payments), 1) self.assertEquals(payments[0].operation, "redeem") self.assertEquals(payments[0].status, "credit") self.assertEquals(payments[0].reference_id, str(self.promotion.id)) self.assertEquals(payments[0].transaction_id, arguments['key']) self.assertEquals(payments[0].buyer_email, user.email) self.assertEquals(payments[0].buyer_name, user.name) # self.assertEquals(payments[0].next_transaction_date, ) voucher = Voucher.get("claimed_by_user_id=%s", user.id) self.assertEquals(voucher.promotion_id, self.promotion.id) self.assertEquals(voucher.claimed_by_user_id, user.id) self.assertEquals(voucher.offered_by_user_id, self.admin.id)
def get(self): vid = self.get_argument('vid', None) shake = None promotion = None voucher = None user = self.get_current_user_object() if vid is not None: voucher = Voucher.get("id=%s", vid) if voucher is not None and voucher.claimed_by_user_id == user.id: if voucher.promotion_id: promotion = Promotion.get("id=%s", voucher.promotion_id) if promotion is not None: shake = promotion.shake() return self.render( "account/confirm.html", promotion=promotion, promotion_shake=shake, voucher=voucher, current_user_obj=user)