From bec66e8c8650a0d433f1ed50bf3b104dd0c07f3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ionu=C8=9B=20Ar=C8=9B=C4=83ri=C8=99i?= Date: Tue, 16 Oct 2012 17:45:58 +0200 Subject: use mock context managers instead of decorators+functions Change-Id: I761ee19169b39e47c4aa191b553965446432dba9 --- tests/test_https.py | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) (limited to 'tests/test_https.py') diff --git a/tests/test_https.py b/tests/test_https.py index 4d433c6..a812bca 100644 --- a/tests/test_https.py +++ b/tests/test_https.py @@ -29,24 +29,20 @@ class ClientTest(utils.TestCase): def test_get(self): cl = get_authed_client() - @mock.patch.object(httplib2.Http, "request", MOCK_REQUEST) - @mock.patch('time.time', mock.Mock(return_value=1234)) - def test_get_call(): - resp, body = cl.get("/hi") - headers = {"X-Auth-Token": "token", - "User-Agent": cl.USER_AGENT} - MOCK_REQUEST.assert_called_with("https://127.0.0.1:5000/hi", - "GET", headers=headers) - # Automatic JSON parsing - self.assertEqual(body, {"hi": "there"}) - - test_get_call() + with mock.patch.object(httplib2.Http, "request", MOCK_REQUEST): + with mock.patch('time.time', mock.Mock(return_value=1234)): + resp, body = cl.get("/hi") + headers = {"X-Auth-Token": "token", + "User-Agent": cl.USER_AGENT} + MOCK_REQUEST.assert_called_with("https://127.0.0.1:5000/hi", + "GET", headers=headers) + # Automatic JSON parsing + self.assertEqual(body, {"hi": "there"}) def test_post(self): cl = get_authed_client() - @mock.patch.object(httplib2.Http, "request", MOCK_REQUEST) - def test_post_call(): + with mock.patch.object(httplib2.Http, "request", MOCK_REQUEST): cl.post("/hi", body=[1, 2, 3]) headers = { "X-Auth-Token": "token", @@ -56,5 +52,3 @@ class ClientTest(utils.TestCase): MOCK_REQUEST.assert_called_with("https://127.0.0.1:5000/hi", "POST", headers=headers, body='[1, 2, 3]') - - test_post_call() -- cgit v1.2.1