gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 19:23:47 25 4
gpt4 key购买 nike

自升级到 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com