我有baseTestCase:BaseTestCase
import time
from flask_testing import TestCase
from authentek.app import main
from authentek.extensions import db
class BaseTestCase(TestCase):
""" Base Tests """
def get_timestamp(self):
return str(time.time()).replace('.', '_')
def create_app(self):
from authentek.internal import app
app.config.from_object('authentek.server.config.TestingConfig')
app = main(port=8080)
return app
def setUp(self):
db.create_all()
db.session.commit()
def tearDown(self):
db.session.remove()
db.drop_all()
错误:
/usr/local/lib/python3.7/site-packages/flask_testing/utils.py:131:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <authentek.tests.test_user_model.TestUserModel testMethod=test_encode_auth_token>
def _pre_setup(self):
self.app = self.create_app()
> self._orig_response_class = self.app.response_class
E AttributeError: 'NoneType' object has no attribute 'response_class'
/usr/local/lib/python3.7/site-packages/flask_testing/utils.py:146: AttributeError
测试用例
import unittest
from authentek.database.models import User
from authentek.extensions import db
from authentek.tests.base import BaseTestCase
class TestUserModel(BaseTestCase):
def test_encode_auth_token(self):
user = User(
email='test_{}@test.com'.format(self.get_timestamp()),
username='test_{}'.format(self.get_timestamp()),
password='test',
)
db.session.add(user)
db.session.commit()
auth_token = user.encode_auth_token(user.id)
self.assertTrue(isinstance(auth_token, str))
当我运行另一个测试用例时,它会挂起,直到我因键盘中断而退出
另一个测试用例是这个:
import json
import time
import unittest
from authentek.database.models import User, BlacklistToken
from authentek.extensions import db
from authentek.logger import log
from authentek.tests.base import BaseTestCase
class TestAuthBlueprint(BaseTestCase):
def test_non_registered_user_login(self):
""" Test for login of non-registered user """
with self.client:
response = self.register_user('joe_{}'.format(self.get_timestamp()),
'joe_{}@gmail.com'.format(self.get_timestamp()), '123456')
data = json.loads(response.data.decode())
self.assertEqual(data['status'], 'fail')
self.assertTrue(data['message'] == 'User does not exist.')
self.assertTrue(response.content_type == 'application/json')
self.assertEqual(response.status_code, 404)
很难理解错误的性质,因为似乎有一个self.client挂在这里,并且错误输出抱怨另一个测试,该测试将response_class作为app.response_class的属性错误。