From a93c57e61ff2047a5d8434d4e5af376f79e43b41 Mon Sep 17 00:00:00 2001 From: Emma Foley Date: Tue, 5 Sep 2017 12:48:45 +0000 Subject: [PATCH] common/test_sender: Update test for perform_request * Add test_perform_request_req_type_put * Updated test_perform_request_req_type_post * Now tests the default case Change-Id: Iff7bc4d4370c5517e481db15ae1318f2e4fd34a5 --- .../tests/common/test_sender.py | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/collectd_ceilometer/tests/common/test_sender.py b/collectd_ceilometer/tests/common/test_sender.py index cba4d21..a2a6001 100644 --- a/collectd_ceilometer/tests/common/test_sender.py +++ b/collectd_ceilometer/tests/common/test_sender.py @@ -49,19 +49,37 @@ class TestSender(unittest.TestCase): get.assert_called_with("my-url", params="some payload", headers=mock.ANY, timeout=mock.ANY) + @mock.patch.object(requests, 'post') + @mock.patch.object(requests, 'put') + def test_perform_request_req_type_put(self, put, post): + """Test the behaviour when performing a post request + + Set-up: None + Test: call _perform_request with req_type="put" + Expected behaviour: + * requests.put is called + * requests.post is not called (i.e. no fall back to default) + """ + self.sender._perform_request("my-url", "some payload", + "some headers", req_type="put") + + post.assert_not_called() + put.assert_called_with("my-url", data="some payload", + headers=mock.ANY, timeout=mock.ANY) + @mock.patch.object(requests, 'post') @mock.patch.object(requests, 'get') def test_perform_request_req_type_post(self, get, post): """Test the behaviour when performing a post request Set-up: None - Test: call _perform_request with req_type="post" + Test: call _perform_request with no req_type Expected behaviour: * requests.get is not called * requests.post is called with appropriate params """ self.sender._perform_request("my-url", "some payload", - "some headers", req_type="post") + "some headers") get.assert_not_called() post.assert_called_with("my-url", data="some payload",