Ich baue Unit-Tests für diese webapp2 Handler (für GAE gebaut)Anfrage Problem, wenn Komponententests webapp2 mit mock und Patch
class PushNotificationHandler(webapp2.RequestHandler):
def post(self):
UserNotification.parse_from_queue(self.request)
return
app = webapp2.WSGIApplication([
(r'/push/notification', PushNotificationHandler),
], debug=True)
Ein Test ist
@patch.object(UserNotification, 'parse_from_queue')
def test_post_webapp(self, p_parse_from_queue):
response = webtest.TestApp(app).post('/push/notification')
eq_(response.status_int, 200)
p_parse_from_queue.assert_called_once_with(response.request)
Die HTTP-Antwort ist OK, aber die mock Behauptung fehlschlägt:
Expected call: parse_from_queue(<TestRequest at 0x105a89850 POST http://localhost/push/notification>)
Actual call: parse_from_queue(<Request at 0x105a89950 POST http://localhost/push/notification>)
ich kann nicht verstehen, warum die Anforderung nicht die richtige ist (sieht aus wie eine tiefe Kopie). Ist mit dem Komponententest etwas nicht in Ordnung, oder ist das so, wie webapp2
Anfragen bearbeiten. Im zweiten Fall ist es eine Möglichkeit, es zu testen, ohne dass ein separater Test zu schaffen PushNotificationHandler.post()
Dank