我已经使用Python 语言的Falcon 框架开发了一个应用程序。我开发了一些 API,现在我想执行单元测试,所以我使用了 unittest 包,但是我无法测试我的 API,因为它未能通过 unittest。为了测试,我参考了这个文档 ,我试图模拟 get 方法,但它询问我的论点。此外,我无法执行任何放置或后测试。这是我执行单元测试的代码
主文件
from app.api.v1 import scheduler
self.add_route('/v1/schedulers', scheduler.SchedulerCollection())
调度程序.py
类 SchedulerCollection(BaseResource):
def __init__(self):
db = redis_db.RedisStorageEngine()
self.r = db.connection()
"""
Handle for endpoint: /v1/schedulers
"""
# @falcon.before(validate_scheduler_create) def on_post(self, req, res):
#some code here
#@falcon.before(auth_required)
def on_get(self, req, res):
#some code here
scheduler_test.py
import sys, os
import unittest
import json
from falcon import testing
from app.api.v1 import scheduler
class SchedulerTestCase(testing.TestCase):
def setUp(self):
super(SchedulerTestCase, self).setUp()
self.app = scheduler.SchedulerCollection.on_get
class TestMyApp(SchedulerTestCase):
def test_get_schedulers(self):
doc = {u'message': u'Hello world!'}
result = self.simulate_get('/v1/schedulers')
result = self.simulate_get('/v1/schedulers')
self.assertEqual(result.json, doc)
if __name__ == '__main__':
unittest.main()
运行测试后,我收到此错误
Traceback (most recent call last):
File "tests/scheduler_test.py", line 17, in setUp
self.app = scheduler.SchedulerCollection().on_get(self.api_class)
TypeError: on_get() takes exactly 3 arguments (2 given)
我不知道我在哪里做错了
任何帮助将不胜感激
谢谢