summaryrefslogtreecommitdiff
path: root/tests/test_https.py
diff options
context:
space:
mode:
authorIonuț Arțăriși <iartarisi@suse.cz>2012-10-16 17:45:58 +0200
committerIonuț Arțăriși <iartarisi@suse.cz>2012-10-18 13:43:39 +0200
commitbec66e8c8650a0d433f1ed50bf3b104dd0c07f3e (patch)
tree5d83b29577679bb051aa2d00c33a5d0b8303b6ae /tests/test_https.py
parentfc4cbcae39ee094cef2c3cce4c96813eb9affcff (diff)
downloadpython-keystoneclient-bec66e8c8650a0d433f1ed50bf3b104dd0c07f3e.tar.gz
use mock context managers instead of decorators+functions
Change-Id: I761ee19169b39e47c4aa191b553965446432dba9
Diffstat (limited to 'tests/test_https.py')
-rw-r--r--tests/test_https.py26
1 files changed, 10 insertions, 16 deletions
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()