使用GAE Test Bed将允许您存根任务队列。
如果您从FunctionalTestCase
or继承TaskQueueTestCase
,您将获得诸如get_tasks
and之类的方法assertTasksInQueue
。
您实际上也可以运行这些任务。如何做到这一点取决于您是使用任务还是延迟。
对于延期,我有一些这样的代码:
from google.appengine.ext import deferred
import base64
# gets the most recent task -- since the task queue is reset between tests,
# this is usually what you want
def get_task(self):
for task in self.get_task_queue_stub().GetTasks('default'):
return task
# decode and execute the deferred method
def run_deferred(task):
deferred.run(base64.b64decode(task['body']))
运行任务是类似的,但是在您获取任务之后,您使用 WebTest(GAE 测试床建立在其之上)作为 POST 请求提交到任务的 URL 及其参数。