init project

This commit is contained in:
alphardex
2019-01-16 22:45:05 +08:00
commit d9f4136fa4
32 changed files with 1044 additions and 0 deletions

0
tests/__init__.py Normal file
View File

15
tests/base.py Normal file
View File

@@ -0,0 +1,15 @@
import unittest
from flask import url_for
from rsshub import create_app
class BaseTestCase(unittest.TestCase):
def setUp(self):
app = create_app('testing')
self.context = app.test_request_context()
self.context.push()
self.client = app.test_client()
self.runner = app.test_cli_runner()
def tearDown(self):
self.context.pop()

7
tests/test_cli.py Normal file
View File

@@ -0,0 +1,7 @@
from tests.base import BaseTestCase
class CLITestCase(BaseTestCase):
def test_ptshell(self):
result = self.runner.invoke(args=['ptshell'])
self.assertNotIn('ptpython not installed! Use the default shell instead.', result.output)

30
tests/test_errors.py Normal file
View File

@@ -0,0 +1,30 @@
from flask import current_app, abort
from tests.base import BaseTestCase
class ErrorsTestCase(BaseTestCase):
def test_400(self):
@current_app.route('/400')
def bad_request():
abort(400)
response = self.client.get('/400')
data = response.get_data(as_text=True)
self.assertIn('400 Bad Request', data)
self.assertEqual(response.status_code, 400)
def test_404(self):
response = self.client.get('/nothing')
data = response.get_data(as_text=True)
self.assertIn('404 Not Found', data)
self.assertEqual(response.status_code, 404)
def test_500(self):
@current_app.route('/500')
def internal_server_error_for_test():
abort(500)
response = self.client.get('/500')
data = response.get_data(as_text=True)
self.assertIn('服务器出错', data)
self.assertEqual(response.status_code, 500)

8
tests/test_main.py Normal file
View File

@@ -0,0 +1,8 @@
from flask import url_for
from tests.base import BaseTestCase
class MainTestCase(BaseTestCase):
def test_index(self):
response = self.client.get(url_for('main.index'))
self.assertEqual(response.status_code, 200)