def test_call_stream_pass(self, m): """Ensure that successful HTTP streaming response codes pass.""" with mock.patch.object(Client, 'get_credentials', return_value=True): c = Client(("http://mydomain.com", "http://mystreamingdomain.com"), "my_account", "my_token") c.session = requests.Session() for status_code in [200, 201, 202, 301, 302]: m.get(requests_mock.ANY, status_code=status_code) c._Client__call_stream(uri="http://example.com", params={"test": "test"}, method="get") m.post(requests_mock.ANY, status_code=status_code) c._Client__call_stream(uri="http://example.com", params={"test": "test"}, method="post")
def test_call_stream_fail(self, m): """Ensure that failure HTTP streaming response codes fail.""" with mock.patch.object(Client, 'get_credentials', return_value=True): c = Client(("http://mydomain.com", "http://mystreamingdomain.com"), "my_account", "my_token") c.session = requests.Session() status_codes = [400, 401, 403, 404, 500] caught = 0 for status_code in status_codes: m.get(requests_mock.ANY, text=json.dumps({'message': 'test'}), status_code=400) try: c._Client__call_stream(uri="http://example.com", params={"test": "test"}, method="get") except BadRequest: caught += 1 self.assertEqual(len(status_codes), caught)