예제 #1
0
파일: link_gen.py 프로젝트: yuanzai/voucr
def link_generator(campaign):
    char_list = string.ascii_letters + string.digits
    for i in range(campaign.count):
        while (True):
            new_char_url = ''.join(random.choice(char_list) for j in range(12))
            try:
                Voucher.objects.get(char_url=new_char_url)
            except:
                v = Voucher(campaign=campaign,char_url=new_char_url)
                v.save()
                break
예제 #2
0
파일: voucher_tests.py 프로젝트: rey/mltshp
    def setUp(self):
        super(VoucherTests, self).setUp()
        self.admin = test.factories.user()
        self.sign_in("admin", "password")

        self.shake = Shake(user_id=self.admin.id,
                           name='promotion-shake',
                           title='Promotion Shake',
                           type='group')
        self.shake.save()
        self.expired_promotion = Promotion(name="Expired Promotion",
                                           membership_months=60,
                                           expires_at=datetime.utcnow() -
                                           timedelta(seconds=50),
                                           promotion_shake_id=0)
        self.expired_promotion.save()
        self.promotion = Promotion(name="Unit Test Sale",
                                   membership_months=60,
                                   promotion_shake_id=self.shake.id,
                                   expires_at=datetime.utcnow() +
                                   timedelta(seconds=60 * 60 * 24 * 365))
        self.promotion.save()

        self.used_voucher = Voucher(offered_by_user_id=0,
                                    promotion_id=self.promotion.id,
                                    voucher_key="abc123")
        # apply_to_user saves the voucher object (because it touches the
        # claimed_by_user_id and dates) and also the user object (by
        # updating the is_paid status)
        self.used_voucher.apply_to_user(self.admin)

        self.unused_voucher = Voucher(offered_by_user_id=0,
                                      claimed_by_user_id=0,
                                      promotion_id=self.promotion.id,
                                      voucher_key="unclaimed")
        self.unused_voucher.save()

        tornado.httpclient.HTTPClient()