mirror of
https://github.com/d0zingcat/RSSHub-python.git
synced 2026-05-14 15:09:23 +00:00
init project
This commit is contained in:
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
15
tests/base.py
Normal file
15
tests/base.py
Normal 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
7
tests/test_cli.py
Normal 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
30
tests/test_errors.py
Normal 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
8
tests/test_main.py
Normal 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)
|
||||
Reference in New Issue
Block a user