def _assert_add_pod_puts_json_in_request_body(pod_json): rpc_client = mock.create_autospec(marathon.RpcClient) client = marathon.Client(rpc_client) client.add_pod(pod_json) rpc_client.http_req.assert_called_with(http.post, 'v2/pods', json=pod_json)
def _assert_pod_feature_supported_raises_exception(head_fn, exception): rpc_client = marathon.RpcClient('http://base/url', timeout=22) marathon_client = marathon.Client(rpc_client) head_fn.side_effect = exception with pytest.raises(exception.__class__) as exception_info: marathon_client.pod_feature_supported() assert exception_info.value == exception
def test_pod_feature_supported_gets_404_response(head_fn): mock_response = mock.create_autospec(requests.Response) mock_response.status_code = 404 head_fn.side_effect = DCOSHTTPException(mock_response) rpc_client = marathon.RpcClient('http://base/url', timeout=24) marathon_client = marathon.Client(rpc_client) assert not marathon_client.pod_feature_supported() head_fn.assert_called_with('http://base/url/v2/pods', timeout=24)
def invoke_test_case(status_code): mock_response = mock.create_autospec(requests.Response) mock_response.status_code = status_code head_fn.return_value = mock_response rpc_client = marathon.RpcClient('http://base/url', timeout=42) marathon_client = marathon.Client(rpc_client) is_supported = marathon_client.pod_feature_supported() head_fn.assert_called_with('http://base/url/v2/pods', timeout=42) return is_supported
def test_case(head_fn, status_code): request = requests.Request(method='ANY', url='http://arbitrary/url') mock_response = mock.create_autospec(requests.Response) mock_response.status_code = status_code mock_response.reason = 'Arbitrary Reason' mock_response.request = request mock_response.json.side_effect = ValueError('empty body') head_fn.side_effect = DCOSHTTPException(mock_response) rpc_client = marathon.RpcClient('http://does/not/matter') marathon_client = marathon.Client(rpc_client) with pytest.raises(DCOSException) as exception_info: marathon_client.pod_feature_supported() message = marathon.RpcClient.response_error_message( status_code, reason='Arbitrary Reason', request_method='ANY', request_url='http://arbitrary/url', json_body=None) assert str(exception_info.value).endswith(message)
def get_marathon_client(): """Gets a marathon client""" return marathon.Client(get_marathon_uri())
def _create_fixtures(): rpc_client = mock.create_autospec(marathon.RpcClient) marathon_client = marathon.Client(rpc_client) return marathon_client, rpc_client
def marathon_client(marathon_url=None): if marathon_url is not None: return marathon.Client('http://' + marathon_url) else: return marathon.create_client()
def marathon_client(self): if self.client is None: self._init_client() marathon_url = self.client.marathon_url() return marathon.Client(marathon_url)