自升级到Google App Engine SDK 1.8.2版本以来,我们一直在与我们的Channel API相关单元测试中遇到问题。简单通道API相关测试1.8.2升级失败
这是皮包骨头。
我们有一个处理程序,它创建一个通道并返回通道ID以及通道标记。该处理程序看起来像:
import json
from uuid import uuid4
from google.appengine.api.channel import channel
import webapp2
class ChannelSubscriptionHandler(webapp2.RequestHandler):
def get(self):
self.response.headers['Context-Type'] = 'application/json'
channel_id = str(uuid4())
token = channel.create_channel(channel_id)
self.response.write(json.dumps({
'channel_id': channel_id,
'token': token
}))
app = webapp2.WSGIApplication([
('/channel_subscription/', ChannelSubscriptionHandler)
], debug=True)
没有什么疯狂的事情,只是创造一个通道,并返回详情。
然后我们有一个单元测试演习的处理程序代码,看起来像:
import json
from unittest import TestCase
from google.appengine.api.channel import channel
from google.appengine.ext.testbed import Testbed
from webtest import TestApp
import example_channel_api_handler
class ChannelSubscriptionHandlerTests(TestCase):
def setUp(self):
self.testbed = Testbed()
self.testbed.activate()
self.testbed.init_channel_stub()
self.channel_stub = self.testbed.get_stub('channel')
self.app = TestApp(example_channel_api_handler.app)
def test_can_get_channel_subscription(self):
response = self.app.get('/channel_subscription/', status=200)
data = json.loads(response.body)
token = data.get('token', None)
channel_id = data.get('channel_id', None)
self.assertIsNotNone(token)
self.assertIsNotNone(channel_id)
self.channel_stub.connect_channel(token)
channel.send_message(channel_id, 'Hello World')
self.assertEquals(['Hello World'], self.channel_stub.get_channel_messages(token))
就像我上面说的,直到GAE SDK上面的测试工作就像一个魅力的1.8.2版本。我扫描了最新版本的发行说明,并看到了一些与Channel API相关的内容,但它看起来并不适用于我遇到的问题。
另外,上面的代码并不是真的来自我正在处理的应用程序,但它复制了我已经描述过的问题。
最后,它看起来应用程序在生产中没有中断,就像这个问题围绕着Channel API的测试平台一样。
感谢您的阅读。
在Google App Engine SDK问题跟踪器上记录了一个问题:https://code.google.com/p/googleappengine/issues/detail?id=9757 – Tombatron