GAE: unit testing taskqueue with testbed

后端 未结 4 1733
醉梦人生
醉梦人生 2020-12-24 14:36

I\'m using testbed to unit test my google app engine app, and my app uses a taskqueue.

When I submit a task to a taskqueue during a unit test, it appears that the ta

4条回答
  •  悲&欢浪女
    2020-12-24 14:48

    Another (cleaner) option to achieve this is to use the task queue stub within the testbed. To do this you first have to initialize the task queue stub by adding the following to your setUp() method:

    self.testbed = init_testbed()
    self.testbed.init_taskqueue_stub()
    

    The tasks scheduler can be accessed using the following code:

    taskq = self.testbed.get_stub(testbed.TASKQUEUE_SERVICE_NAME)
    

    The interface for working with the queue stub is as follows:

    GetQueues() #returns a list of dictionaries with information about the available queues
    
    #returns a list of dictionaries with information about the tasks in a given queue
    GetTasks(queue_name)
    
    DeleteTask(queue_name, task_name) #removes the task task_name from the given queue
    
    FlushQueue(queue_name) #removes all the tasks from the queue
    
    #returns tasks filtered by name & url pointed to by the task from the given queues
    get_filtered_tasks(url, name, queue_names)
    
    StartBackgroundExecution() #Executes the queued tasks
    
    Shutdown() #Requests the task scheduler to shutdown.
    

    Also, as this uses App Engine SDK own facilities - it works just fine with the deferred library.

提交回复
热议问题