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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)
def test_page(self): req = DummyRequest() req.matchdict['page'] = 'help' resp = views.page(req) self.assertIsInstance(resp, dict) self.assertIn('Installation guides:', resp['content'])
def test_home(self): req = DummyRequest() resp = views.home(req) self.assertIsInstance(resp, dict)
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)
def test_page(self): req = DummyRequest() req.matchdict['page'] = 'docs' resp = views.page(req) self.assertIsInstance(resp, dict) self.assertIn('Docs', resp['content'])
def test_page_fail(self): req = DummyRequest() req.matchdict['page'] = 'does-not-exists' resp = views.page(req) self.assertIsInstance(resp, httpexceptions.HTTPNotFound)
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)
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)
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)
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)