python - 简单 channel API 相关测试因 1.8.2 升级而失败

标签 python google-app-engine channel-api

自升级到 Google App Engine SDK 版本 1.8.2 以来,我们的 Channel API 相关单元测试之一一直存在问题。

这是瘦子。

我们有一个处理程序可以创建一个 channel 并返回 channel ID 和 channel token 。该处理程序看起来像:

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)

没有什么疯狂的事情发生,只是创建一个 channel 并返回细节。

然后我们对处理程序代码进行单元测试,如下所示:

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 相关的内容,但它看起来并不适用于我遇到的问题。

此外,上面的代码并不是真正来 self 正在处理的应用程序,但它复制了我所描述的问题。

最后,应用程序似乎并没有在生产中出现问题,这个问题似乎围绕着 Channel API 的测试平台。

感谢阅读。

最佳答案

我将此作为问题记录在 Google App Engine SDK 问题跟踪器上。

原始评论中提到了我记录的问题。

该问题已被接受,并计划在 Google App Engine SDK 的下一个 (1.8.3) 版本中修复。

感谢阅读。

关于python - 简单 channel API 相关测试因 1.8.2 升级而失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17888536/

相关文章:

google-app-engine - Eclipse 不生成谷歌云端点客户端库

javascript - channel API - 生产中的 token 无效,可在开发服务器上使用

java - 寻找 AngularJS 客户端的 App Engine Channel Api Java 替代解决方案

python - 如何使用 python 中的第二个键对对列表进行排序?

python - 在 Python 中将列表从文本拆分为 nGram

python - 启动 map 作业时遇到错误

python - AppEngine Transaction 是否需要执行 get 和 put 操作才能发挥作用?

google-app-engine - GAE channel API 重新连接

python - 如何有效地合并这两个数据集?

python - OpenCV中这个 'inverse map'函数有什么不准确之处?