Beispiel #1
0
    def test_get_bad_json(self, resp_mock):
        """Test treadmill.restclient.get bad JSON"""
        resp_mock.return_value.status_code = http.client.INTERNAL_SERVER_ERROR
        resp_mock.return_value.text = '{"bad json"'
        resp_mock.return_value.json.side_effect = sjs.JSONDecodeError(
            'Foo', '{"bad json"', 1
        )

        self.assertRaises(
            restclient.MaxRequestRetriesError,
            restclient.get, 'http://foo.com', '/', retries=1)
Beispiel #2
0
    def test_invoke_bad_content_type(self):
        """Tests the invoke behavior with a non-JSON response"""
        fake_response = mock.Mock()
        fake_response.json = mock.Mock(
            side_effect=scanner.JSONDecodeError('', '{}', 1))
        fake_response.status_code = 424
        fake_response.text = "Fake Response"
        self.mock_object(self.my_client, 'invoke_service',
                         mock.Mock(return_value=fake_response))

        self.assertRaises(es_exception.WebServiceException,
                          self.my_client._invoke, 'GET',
                          eseries_fake.FAKE_ENDPOINT_HTTP)