Пример #1
0
 def test_post_unknown_code(self):
     req = DummyRequest(post={'code': 'fail'})
     req.session['uid'] = self.testuser.id
     resp = views.order.order_post(req)
     self.assertIsInstance(resp, httpexceptions.HTTPSeeOther)
     self.assertTrue(resp.location.endswith('/account/'))
     self.assertFalse(self.testuser.is_paid)
Пример #2
0
 def test_invalid_email(self):
     req = DummyRequest(post={
         'username': '******',
     })
     req.remote_addr = '127.0.0.1'
     resp = views.account.forgot(req)
     self.assertEqual(req.response.status_code, 400)
     self.assertIsInstance(resp, dict)
Пример #3
0
 def test_post_order_paypal_invalid_method(self):
     req = DummyRequest(post={
         'method': 'dogecoin',
         'time': '1'
     })
     req.session['uid'] = self.testuser.id
     resp = views.order.order_post(req)
     self.assertIsInstance(resp, httpexceptions.HTTPBadRequest)
Пример #4
0
 def test_post_order_paypal_invalid_time(self):
     req = DummyRequest(post={
         'method': 'paypal',
         'time': 'one'
     })
     req.session['uid'] = self.testuser.id
     resp = views.order.order_post(req)
     self.assertIsInstance(resp, httpexceptions.HTTPSeeOther)
Пример #5
0
 def test_post_order_paypal(self):
     req = DummyRequest(post={
         'method': 'paypal',
         'time': '1'
     })
     req.session['uid'] = self.testuser.id
     resp = views.order.order_post(req)
     self.assertIsInstance(resp, httpexceptions.HTTPSeeOther)
     self.assertIn('paypal.com', resp.location)
Пример #6
0
 def test_get(self):
     gw = bytes(views.account.openvpn_gateway, 'ascii')
     ca = bytes(views.account.openvpn_ca, 'ascii')
     req = DummyRequest()
     req.session['uid'] = self.testuser.id
     resp = views.account.config(req)
     self.assertEqual(resp.status_code, 200)
     self.assertIn(gw, resp.body)
     self.assertIn(ca, resp.body)
Пример #7
0
 def test_invalid_password(self):
     req = DummyRequest(post={
         'password': '******',
         'password2': 'notpw'
     })
     req.matchdict['token'] = self.token.token
     req.remote_addr = '127.0.0.1'
     resp = views.account.reset(req)
     self.assertEqual(req.response.status_code, 400)
     self.assertIsInstance(resp, dict)
Пример #8
0
    def test_valid(self):
        req = DummyRequest(post={
            'username': '******',
        })
        req.remote_addr = '127.0.0.1'
        resp = views.account.forgot(req)
        self.assertEqual(req.response.status_code, 200)
        self.assertIsInstance(resp, dict)

        registry = self.config.registry
        mailer = get_mailer(registry)
        self.assertEqual(len(mailer.outbox), 1)
Пример #9
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)
Пример #10
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)
Пример #11
0
    def test_post_code(self):
        req = DummyRequest(post={'code': self.testcode.code})
        req.session['uid'] = self.testuser.id
        resp = views.order.order_post(req)
        self.assertIsInstance(resp, httpexceptions.HTTPSeeOther)
        self.assertTrue(resp.location.endswith('/account/'))
        self.assertTrue(self.testuser.is_paid)
        until = self.testuser.paid_until

        resp = views.order.order_post(req)
        self.assertIsInstance(resp, httpexceptions.HTTPSeeOther)
        self.assertTrue(resp.location.endswith('/account/'))
        self.assertTrue(self.testuser.is_paid)
        self.assertEquals(self.testuser.paid_until, until)
Пример #12
0
    def test_post_admin(self):
        req = DummyRequest(post={'method': 'admin', 'time': '3'})

        req.session['uid'] = self.testuser.id
        resp = views.order.order_post(req)
        self.assertIsInstance(resp, httpexceptions.HTTPBadRequest)
        self.assertFalse(self.testuser.is_paid)

        req = DummyRequest(post={'method': 'admin', 'time': '3'})
        req.session['uid'] = self.testadmin.id
        resp = views.order.order_post(req)
        self.assertIsInstance(resp, httpexceptions.HTTPSeeOther)
        self.assertTrue(resp.location.endswith('/account/'))
        self.assertTrue(self.testadmin.is_paid)
Пример #13
0
    def test_view_not_owned(self):
        with transaction.manager:
            otheruser = User(username='******', password='******')
            self.session.add(otheruser)
        with transaction.manager:
            testorder = Order(user=otheruser.id, amount=1,
                              method=Order.METHOD.PAYPAL,
                              time=datetime.timedelta(days=30))
            self.session.add(testorder)

        req = DummyRequest()
        req.session['uid'] = self.testuser.id
        req.matchdict['hexid'] = '%x' % testorder.id
        resp = views.account.order_view(req)
        self.assertIsInstance(resp, httpexceptions.HTTPUnauthorized)
Пример #14
0
    def test_valid(self):
        req = DummyRequest(post={
            'password': '******',
            'password2': 'newpw',
        })
        req.matchdict['token'] = self.token.token
        req.remote_addr = '127.0.0.1'
        resp = views.account.reset(req)
        self.assertIsInstance(resp, httpexceptions.HTTPMovedPermanently)
        self.assertTrue(resp.location.endswith('/account/login'))

        registry = self.config.registry
        mailer = get_mailer(registry)
        self.assertEqual(len(mailer.outbox), 1)

        # Should not be able to use a token > 1 time
        req = DummyRequest(post={
            'password': '******',
            'password2': 'newpw',
        })
        req.matchdict['token'] = self.token.token
        req.remote_addr = '127.0.0.1'
        resp = views.account.reset(req)
        self.assertIsInstance(resp, httpexceptions.HTTPMovedPermanently)
        self.assertTrue(resp.location.endswith('/account/forgot'))

        registry = self.config.registry
        mailer = get_mailer(registry)
        self.assertEqual(len(mailer.outbox), 1)
Пример #15
0
    def test_form(self):
        req = DummyRequest()
        req.matchdict['token'] = self.token.token
        req.remote_addr = '127.0.0.1'
        resp = views.account.reset(req)
        self.assertEqual(req.response.status_code, 200)
        self.assertIsInstance(resp, dict)

        req = DummyRequest(post={})
        req.matchdict['token'] = self.token.token
        req.remote_addr = '127.0.0.1'
        resp = views.account.reset(req)
        self.assertEqual(req.response.status_code, 200)
        self.assertIsInstance(resp, dict)
Пример #16
0
 def test_page(self):
     req = DummyRequest()
     req.matchdict['page'] = 'help'
     resp = views.page(req)
     self.assertIsInstance(resp, dict)
     self.assertIn('Installation guides:', resp['content'])
Пример #17
0
 def test_home(self):
     req = DummyRequest()
     resp = views.home(req)
     self.assertIsInstance(resp, dict)
Пример #18
0
 def test_invalid_token(self):
     req = DummyRequest()
     req.matchdict['token'] = 'invalidtoken'
     req.remote_addr = '127.0.0.1'
     resp = views.account.reset(req)
     self.assertIsInstance(resp, httpexceptions.HTTPMovedPermanently)
Пример #19
0
 def test_page(self):
     req = DummyRequest()
     req.matchdict['page'] = 'docs'
     resp = views.page(req)
     self.assertIsInstance(resp, dict)
     self.assertIn('Docs', resp['content'])
Пример #20
0
 def test_page(self):
     req = DummyRequest()
     req.matchdict['page'] = 'help'
     resp = views.page(req)
     self.assertIsInstance(resp, dict)
     self.assertIn('Installation guides:', resp['content'])
Пример #21
0
 def test_page_fail(self):
     req = DummyRequest()
     req.matchdict['page'] = 'does-not-exists'
     resp = views.page(req)
     self.assertIsInstance(resp, httpexceptions.HTTPNotFound)
Пример #22
0
 def test_invalid_token(self):
     req = DummyRequest()
     req.matchdict['token'] = 'invalidtoken'
     req.remote_addr = '127.0.0.1'
     resp = views.account.reset(req)
     self.assertIsInstance(resp, httpexceptions.HTTPMovedPermanently)
Пример #23
0
 def test_view_not_found(self):
     req = DummyRequest()
     req.session['uid'] = self.testuser.id
     req.matchdict['hexid'] = '%x' % 4242
     resp = views.order.order_view(req)
     self.assertIsInstance(resp, httpexceptions.HTTPNotFound)
Пример #24
0
 def test_account_page(self):
     req = DummyRequest()
     req.session['uid'] = self.testuser.id
     resp = views.account.account(req)
     self.assertIsInstance(resp, dict)
     self.assertEqual(req.response.status_code, 200)
Пример #25
0
 def test_logout(self):
     req = DummyRequest()
     req.session['uid'] = self.testuser.id
     resp = views.account.logout(req)
     self.assertIsInstance(resp, httpexceptions.HTTPSeeOther)
     self.assertNotEqual(req.session.get('uid'), self.testuser.id)
Пример #26
0
 def test_unknown_profile(self):
     req = DummyRequest()
     req.session['uid'] = self.testuser.id
     req.GET['profile'] = 'nottestprofile'
     resp = views.account.config(req)
     self.assertEqual(resp.status_code, 404)
Пример #27
0
 def test_page_fail(self):
     req = DummyRequest()
     req.matchdict['page'] = 'does-not-exists'
     resp = views.page(req)
     self.assertIsInstance(resp, httpexceptions.HTTPNotFound)