Esempio n. 1
0
    def test_valid_referral(self):
        with transaction.manager:
            referrer = User(username='******', password='******')
            self.session.add(referrer)
        self.assertFalse(referrer.is_paid)

        req = DummyRequest(post={
            'username': '******',
            'password': '******',
            'password2': 'newpw',
            'email': 'email@host'
        }, params={
            'ref': str(referrer.id),
        })
        resp = views.account.signup(req)

        newuser = self.session.query(User).filter_by(username='******').first()
        self.assertIsInstance(resp, httpexceptions.HTTPSeeOther)
        self.assertTrue(resp.location.endswith('/account/'))
        self.assertEqual(newuser.referrer_id, referrer.id)

        self.assertFalse(referrer.is_paid)

        with transaction.manager:
            testorder = Order(user=newuser, amount=1,
                              method=Order.METHOD.BITCOIN,
                              time=datetime.timedelta(days=30))
            self.session.add(testorder)
        testorder.close(force=True)

        self.assertTrue(referrer.is_paid)
Esempio n. 2
0
    def test_view_btc(self):
        testorder = Order(user=self.testuser.id, amount=1,
                          method=Order.METHOD.BITCOIN,
                          time=datetime.timedelta(days=30))
        testorder.payment = {'btc_address': 'TESTADDRESS'}
        self.session.add(testorder)
        self.session.flush()

        req = DummyRequest()
        req.session['uid'] = self.testuser.id
        req.matchdict['hexid'] = '%x' % testorder.id
        resp = views.order.order_view(req)
        self.assertIsInstance(resp, dict)
        self.assertEqual(resp['o'], testorder)
Esempio n. 3
0
    def test_view_btc(self):
        testorder = Order(user=self.testuser.id,
                          amount=1,
                          method=Order.METHOD.BITCOIN,
                          time=datetime.timedelta(days=30))
        testorder.payment = {'btc_address': 'TESTADDRESS'}
        self.session.add(testorder)
        self.session.flush()

        req = DummyRequest()
        req.session['uid'] = self.testuser.id
        req.matchdict['hexid'] = '%x' % testorder.id
        resp = views.order.order_view(req)
        self.assertIsInstance(resp, dict)
        self.assertEqual(resp['o'], testorder)
Esempio n. 4
0
    def test_valid_referral(self):
        with transaction.manager:
            _referrer = User(username='******', password='******')
            self.session.add(_referrer)

        referrer = self.session.query(User).filter_by(username='******').first()
        self.assertFalse(referrer.is_paid)

        req = DummyRequest(post={
            'username': '******',
            'password': '******',
            'password2': 'newpw',
            'email': 'email@host'
        },
                           params={
                               'ref': str(referrer.id),
                           })
        resp = views.account.signup(req)

        newuser = self.session.query(User).filter_by(username='******') \
                              .first()
        self.assertIsInstance(resp, httpexceptions.HTTPSeeOther)
        self.assertTrue(resp.location.endswith('/account/'))
        self.assertEqual(newuser.referrer_id, referrer.id)

        self.assertFalse(referrer.is_paid)

        testorder = Order(user=newuser,
                          amount=1,
                          method=Order.METHOD.BITCOIN,
                          time=datetime.timedelta(days=30))
        self.session.add(testorder)
        self.session.add(referrer)
        self.session.flush()
        testorder.close(force=True)
        self.session.flush()

        self.session.refresh(referrer)
        self.assertTrue(referrer.is_paid)
Esempio n. 5
0
    def test_view_paypal(self):
        testorder = Order(user=self.testuser.id,
                          amount=1,
                          method=Order.METHOD.PAYPAL,
                          time=datetime.timedelta(days=30))
        self.session.add(testorder)
        self.session.flush()

        req = DummyRequest()
        req.session['uid'] = self.testuser.id
        req.matchdict['hexid'] = '%x' % testorder.id
        resp = views.order.order_view(req)
        self.assertIsInstance(resp, dict)
        self.assertEqual(resp['o'], testorder)
Esempio n. 6
0
def order_post(request):
    code = request.POST.get('code')
    if code:
        return order_post_gc(request, code)

    times = (1, 3, 6, 12)
    try:
        method_name = request.POST.get('method')
        time_months = int(request.POST.get('time'))
    except ValueError:
        return HTTPBadRequest('invalid POST data')
    if method_name not in methods.METHODS or time_months not in times:
        return HTTPBadRequest('Invalid method/time')

    time = datetime.timedelta(days=30 * time_months)
    o = Order(user=request.user, time=time, amount=0, method=0)
    o.close_date = datetime.datetime.now() + datetime.timedelta(days=7)
    o.paid = False
    o.payment = {}
    method = methods.METHODS[method_name]()
    method.init(request, o)
    DBSession.add(o)
    DBSession.flush()
    return method.start(request, o)
Esempio n. 7
0
    def test_view_not_owned(self):
        otheruser = User(username='******', password='******')
        self.session.add(otheruser)
        self.session.flush()

        testorder = Order(user=otheruser.id,
                          amount=1,
                          method=Order.METHOD.PAYPAL,
                          time=datetime.timedelta(days=30))
        self.session.add(testorder)
        self.session.flush()

        req = DummyRequest()
        req.session['uid'] = self.testuser.id
        req.matchdict['hexid'] = '%x' % testorder.id
        resp = views.order.order_view(req)
        self.assertIsInstance(resp, httpexceptions.HTTPUnauthorized)