Flask API测试返回404以获取有效端点

时间:2020-03-09 18:09:00

标签: http-status-code-404 endpoint flask-restful system-testing flask-testing

// base class 
class BaseTest(TestCase):

    # setup DB
    @classmethod
    def setUpClass(cls):
        app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'
        app.config['DEBUG'] = False
        with app.app_context():
            # initialize DB
            db.init_app(app)

    # create DB
    def setUp(self):
        with app.app_context():
            db.create_all()
        self.app = app.test_client
        self.app_context = app.app_context
class TestPantry(BaseTest):
    def test_create_pantry(self):
        with self.app() as endpoint:
            with self.app_context():
                response = endpoint.post('/pantry/Liquids')

                self.assertEqual(response.status_code, 200) # returns 404

上述端点在通过邮递员进行测试时有效,但在系统测试中,所有端点均返回404。

0 个答案:

没有答案