1
python webtest를 사용하여 요청에 쿠키를 전달하는 방법에 대해 혼란 스럽습니다.webtest.TestApp를 사용할 때 내 쿠키가 전송되지 않습니다.
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
내가 쿠키를보기 위해 핸들러 함수에서 오류를 제기하고
나는 다음과 같은 시험이있다. 쿠키의 내용은 webtest.TestApp
내의 cookiejar에 있지만 wsgi 요청을 할 때 전송되지 않는 것 같습니다. 쿠키를 전송하려면 어떻게해야합니까?
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!
당신은 testapp 응에 extra_environ을 통과 할 수 있습니다. – Greg
직접 답변을 제공해 주셔서 감사합니다. Stephen - 나는 똑같은 문제와 똑같은 해결책을 가지고있었습니다. 내가 알아낼 시간이 오래 걸렸을거야. – Jonas