From: Tatiana Al-Chueyr Date: Mon, 21 Jul 2014 22:28:41 +0000 (-0700) Subject: Refactor: simplify patch test according to @bdarnell recommendations at #1090 X-Git-Tag: v4.1.0b1~123^2~4 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca7ae5fd004cadd5947970c7a56de69af5eec25e;p=thirdparty%2Ftornado.git Refactor: simplify patch test according to @bdarnell recommendations at #1090 --- diff --git a/tornado/test/curl_httpclient_test.py b/tornado/test/curl_httpclient_test.py index 5330ca387..28a37f35b 100644 --- a/tornado/test/curl_httpclient_test.py +++ b/tornado/test/curl_httpclient_test.py @@ -1,6 +1,5 @@ from __future__ import absolute_import, division, print_function, with_statement -import json from hashlib import md5 from tornado.escape import utf8 @@ -126,32 +125,12 @@ class CurlHTTPClientTestCase(AsyncHTTPTestCase): class ContactListHandler(RequestHandler): - contact_list = { - "someone": { - "telephone": "1-800-247-9792", - "email": "some@email.com" - }, - "another": { - "telephone": "1-104-132-7713", - "email": "other@email.com" - } - } - - def get(self, contact_name): - data = self.contact_list.get(contact_name) - self.write(data) - def patch(self, contact_name): """ Patch implementation according to RFC-6902 http://tools.ietf.org/html/rfc6902 """ - patch_data = json.loads(self.request.body) - for patch_item in patch_data: - if patch_item["op"] == "replace": - attribute = patch_item["path"] - value = patch_item["value"] - self.contact_list[contact_name][attribute] = value + self.write(self.request.body) @unittest.skipIf(pycurl is None, "pycurl module not present") @@ -176,32 +155,8 @@ class NonStandardMethodCurlHTTPClientTestCase(AsyncHTTPTestCase): self.http_client.fetch(request, self.stop, method=None) return self.wait() - def test_get(self): - response = self.fetch("/someone", method='GET') - self.assertEqual(response.code, 200) - computed_body = json.loads(response.body) - expected_body = { - "telephone": "1-800-247-9792", - "email": "some@email.com" - } - self.assertEqual(computed_body, expected_body) - def test_patch_with_payload(self): - patch_list = [ - { - "op": "replace", - "path": "telephone", - "value": "55-21-99756-1934" - } - ] - body = json.dumps(patch_list) - response_patch = self.fetch("/someone", method='PATCH', body=body) - self.assertEqual(response_patch.code, 200) - - response_get = self.fetch("/someone", method="GET") - computed_body = json.loads(response_get.body) - expected_body = { - "telephone": "55-21-99756-1934", - "email": "some@email.com" - } - self.assertEqual(computed_body, expected_body) + body = "some patch data" + response = self.fetch("/someone", method='PATCH', body=body) + self.assertEqual(response.code, 200) + self.assertEqual(response.body, body)