def test_use_reuse(self): time = datetime.timedelta(days=30, hours=11) gc = GiftCode(time=time) gc.use(self.u) self.assertEqual(self.u.paid_time_left().days, time.days) self.assertRaises(models.AlreadyUsedGiftCode, gc.use, self.u) self.assertEqual(self.u.paid_time_left().days, time.days) gc.use(self.u, reuse=True) self.assertTrue(self.u.is_paid) self.assertEqual(self.u.paid_time_left().days, time.days*2)
def setUp(self): super().setUp() self.testuser = User(username='******', password='******') self.session.add(self.testuser) self.testadmin = User(username='******', password='******') self.testadmin.is_admin = True self.session.add(self.testadmin) self.session.flush() self.testcode = GiftCode(datetime.timedelta(days=7)) self.session.add(self.testcode) self.session.flush()
def order_post_gc(request, code): try: gc = GiftCode.one(code=code) gc.use(request.user) time = gc.time.days request.messages.info('OK! Added %d days to your account.' % time) DBSession.flush() except (NoResultFound, MultipleResultsFound): request.messages.error('Unknown code.') except AlreadyUsedGiftCode: request.messages.error('Already used code') return HTTPSeeOther(location=request.route_url('account'))
def order_post_gc(request, code): _ = request.translate try: gc = GiftCode.one(code=code) gc.use(request.user) time = gc.time.days request.messages.info(_('OK! Added ${time} days to your account.', mapping={'time': time})) DBSession.flush() except (NoResultFound, MultipleResultsFound): request.messages.error(_('Unknown gift code.')) except AlreadyUsedGiftCode: request.messages.error(_('Gift code already used.')) return HTTPSeeOther(location=request.route_url('account'))
def setUp(self): settings = {'mako.directories': 'ccvpn:templates/'} self.config = testing.setUp(settings=settings) setup_routes(self.config) self.session = setup_database() self.testuser = User(username='******', password='******') self.session.add(self.testuser) self.testadmin = User(username='******', password='******') self.testadmin.is_admin = True self.session.add(self.testadmin) self.session.flush() self.testcode = GiftCode(datetime.timedelta(days=7)) self.session.add(self.testcode) self.session.flush()
def test_use_reuse(self): time = datetime.timedelta(days=30, hours=11) gc = GiftCode(time=time) gc.use(self.u) self.assertEqual(self.u.paid_time_left.days, time.days) self.assertRaises(models.AlreadyUsedGiftCode, gc.use, self.u) self.assertEqual(self.u.paid_time_left.days, time.days) gc.use(self.u, reuse=True) self.assertTrue(self.u.is_paid) self.assertEqual(self.u.paid_time_left.days, time.days * 2)
def test_use_freeonly(self): gc = GiftCode() gc.free_only = True self.assertRaises(models.AlreadyUsedGiftCode, gc.use, self.pu) gc.use(self.u) self.assertTrue(self.u.is_paid)
def test_username_if_used(self): gc = GiftCode() self.assertIs(gc.username_if_used, False) gc.used = self.u.id gc.user = self.u self.assertEqual(gc.username_if_used, self.u.username)