- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我对如何使用 python webtest 在请求中传递 cookie 感到困惑。
我有以下测试:
def test_commenting_and_voting(self):
https = {'wsgi.url_scheme': 'https'}
users = []
for user in USERS:
resp_post = self.testapp.post_json('/user', user)
users.append(resp_post.json.get('id'))
self.testapp.post_json('/login/%s' % users[0],
{'password' : USERS[0]['password']},
extra_environ=https)
print "testapp's view of the cookiejar"
print self.testapp.cookies
print "END"
resp_post = self.testapp.post_json('/comment', {'value': ""})
和以下处理程序:
class CommentHandler(webapp2.RequestHandler):
def get(self, id=None):
get_from_urlsafe(self, id)
@ndb.transactional
def post(self, id=None):
assert False, self.request.cookies
为了查看 cookie,我正在从处理程序函数中引发错误。看起来 cookie,虽然在事物的 webtest.TestApp
端的 cookiejar 中,但在发出 wsgi 请求时没有被传输。那么如何让 cookie 传输呢?
Using scent:
test_commenting_and_voting (test_models.test_Models) ...
testapp's view of the cookiejar
{'secret': '58bd5cfd36e6f805de645e00f8bea9d70ae5398ff0606b7fde829e6732394bb7', 'session': 'agx0ZXN0YmVkLXRlc3RyIgsSD1VzZXJFbnRpdHlHcm91cBgBDAsSB1Nlc3Npb24YCww'}
END
WARNING:root:suspended generator transaction(context.py:941) raised AssertionError(<RequestCookies (dict-like) with values {}>)
ERROR:root:<RequestCookies (dict-like) with values {}>
Traceback (most recent call last):
File "/home/stephen/bin/google_appengine/lib/webapp2-2.5.2/webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
... I removed some of the stacktrace here ....
File "/home/stephen/work/seocomments/src/python/main.py", line 127, in post
assert False, self.request.cookies
AssertionError: <RequestCookies (dict-like) with values {}>
----------------------------------------------------------------------
Ran 6 tests in 0.371s
FAILED (errors=1)
Failed - Back to work!
最佳答案
没关系。我没有看到 cookie 的原因是 cookie 被设置为安全 cookie,这意味着它们仅在使用安全连接时存在。我的测试使用的是不安全的连接。
要完成这项工作,请将请求更改为以下内容:
self.testapp.post_json('/comment',
{'value': ""},
extra_environ={'wsgi.url_scheme': 'https'})
关于python - 使用 webtest.TestApp 时未传输我的 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22620720/
(Windows 8.1) 这就是我构建 .exe 的方式: 到这里,https://github.com/libgdx/packr 下载 packr 和 .zip。我用“javac -sourcep
我是 Android 应用程序开发新手,我尝试编写我的第一个简单应用程序来尝试在 Activity 之间发送数据。代码已编译,我尝试在虚拟设备上启动它,但正如标题所示,它停止了。 这是 logcat
我在模拟器上执行了几个android testapps,但我真的很困惑如何在商用手机上运行testapp。如果任何站点中提到任何详细步骤,请发布链接..... 真的需要它。提前致谢。恭喜 Renas.
public class SomeHelper { ... private int static x; static { Map aMap = new Hash
我正在尝试在 Android (Samsung S4) 上部署我的 Qt5 应用程序。它编译得很好,但在部署时停止于: Starting debugger "QmlCppEngine" for ABI
我是第一次使用 OpenFrameworks(我对 C++ 也很陌生)。 我正在尝试使用 OFX 构建一个应用程序,并且我想将我的应用程序称为 testApp 以外的名称。我正在构建 openCVEx
我对如何使用 python webtest 在请求中传递 cookie 感到困惑。 我有以下测试: def test_commenting_and_voting(self): https =
我想玩 Angular2 - 一个非常简单的开始!我只是将一些代码从 angular.io 复制到我的文件中。在 LightTable(集成浏览器)中,此代码不起作用: Angula
我正在尝试为 ajax View 编写测试... View 的配置如下: @view_config(name='new', context='resource.Events', renderer='j
我收到错误: Invalid property 'redeemVoucherForm' of bean class [my.testapp.forms.RedeemVoucherForm]: Bean
这是我的 html 文件: // code.... 这是我的 Javascript 文件: (functio
我从我的 ofApp.cpp(又名 testApp.cpp)的实现开始: #include "ofApp.h" const ofColor bgColor(33, 33, 33); void ofAp
我正在尝试使用 java api 发送电子邮件。我的应用程序正在运行,没有自定义域,实际上它只是一个默认项目。未启用计费。我的应用名称是“testapp”。 我正在为发件人使用此电子邮件地址: adm
我正在 android 中开发一个库项目。我想将我的库上传到 JCenter。我已经创建了 bintray 帐户等并遵循了此处提到的所有步骤 http://inthecheesefactory.com
我今天开始探索 hazelcast,我从该网站下载了 hazelcast-2.0,并遵循其网站中提供的 ScreenCast。我进入 bin 目录并从命令提示符启动 run.bat 。 我收到Clas
我第一次尝试在我的开发环境中设置 south。我之前已经设置了几个模型。 South 安装完成后,我按照 south 的文档转换我现有的应用程序。 但是,我得到了以下回溯。有什么想法吗? 谢谢。 ./
因为我最近开始使用 revel 框架来构建 go web 应用程序。我创建了一个测试应用程序 (orpat),将其编译为“revel build orpat prod”并更改了 conf PORT->
每次我尝试在 Xcode 7 beta 4 中安装 watchOS 2 应用程序时,我都会在 iOS 上收到 AlertView 弹出错误: Cannot Install Watch App Test
我正在尝试按照此 link 在 Angular 6 中创建一个通用应用程序完成链接中提到的步骤后,我尝试构建我的通用应用程序,但它显示以下错误。 Project 'testapp' could not
我正在开发一个 android 库项目。我想将我的库上传到 JCenter。我已经创建了 bintray 帐户等并遵循了所有提到的步骤 here . 我在我的应用程序模块和库模块中做了以下更改。 应用
我是一名优秀的程序员,十分优秀!