Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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'])
Example #17
0
 def test_home(self):
     req = DummyRequest()
     resp = views.home(req)
     self.assertIsInstance(resp, dict)
Example #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)
Example #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'])
Example #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'])
Example #21
0
 def test_page_fail(self):
     req = DummyRequest()
     req.matchdict['page'] = 'does-not-exists'
     resp = views.page(req)
     self.assertIsInstance(resp, httpexceptions.HTTPNotFound)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #27
0
 def test_page_fail(self):
     req = DummyRequest()
     req.matchdict['page'] = 'does-not-exists'
     resp = views.page(req)
     self.assertIsInstance(resp, httpexceptions.HTTPNotFound)