def test_service_action_creates_params(self, params_mock): resource = mock.Mock() resource.meta = ResourceMeta('test', client=mock.Mock()) action = ServiceAction(self.action) action(resource, foo=1) assert params_mock.called
def test_service_action_creates_params(self, params_mock): resource = mock.Mock() resource.meta = ResourceMeta('test', client=mock.Mock()) action = ServiceAction(self.action) action(resource, foo=1) self.assertTrue(params_mock.called, 'Parameters for operation not created')
def test_service_action_calls_operation(self, params_mock): resource = mock.Mock() resource.meta = ResourceMeta('test', client=mock.Mock()) operation = resource.meta.client.get_frobs operation.return_value = 'response' action = ServiceAction(self.action) response = action(resource, foo=1) operation.assert_called_with(foo=1, bar='baz') assert response == 'response'
def test_service_action_calls_operation(self, params_mock): resource = mock.Mock() resource.meta = ResourceMeta('test', client=mock.Mock()) operation = resource.meta.client.get_frobs operation.return_value = 'response' action = ServiceAction(self.action) response = action(resource, foo=1) operation.assert_called_with(foo=1, bar='baz') self.assertEqual(response, 'response', 'Unexpected low-level response data returned')
def test_service_action_calls_raw_handler(self, handler_mock, params_mock): resource = mock.Mock() resource.meta = ResourceMeta('test', client=mock.Mock()) operation = resource.meta.client.get_frobs operation.return_value = 'response' action = ServiceAction(self.action) handler_mock.return_value.return_value = 'response' action(resource) handler_mock.assert_called_with(None) handler_mock.return_value.assert_called_with(resource, {}, 'response')
def test_service_action_call_positional_argument(self): def _api_call(*args, **kwargs): if args: raise TypeError("%s() only accepts keyword arguments." % 'get_frobs') resource = mock.Mock() resource.meta = ResourceMeta('test', client=mock.Mock()) resource.meta.client.get_frobs = _api_call action = ServiceAction(self.action) with pytest.raises(TypeError): action(resource, 'item1')
def test_service_action_calls_resource_handler(self, handler_mock, params_mock): self.action_def['resource'] = { 'type': 'Frob', 'path': 'Container' } resource = mock.Mock() resource.meta = ResourceMeta('test', client=mock.Mock()) operation = resource.meta.client.get_frobs operation.return_value = 'response' factory = mock.Mock() resource_defs = {} service_model = mock.Mock() action_model = self.action service_context = ServiceContext( service_name='test', service_model=service_model, resource_json_definitions=resource_defs, service_waiter_model=None ) action = ServiceAction( action_model=action_model, factory=factory, service_context=service_context ) handler_mock.return_value.return_value = 'response' action(resource) handler_mock.assert_called_with( search_path='Container', factory=factory, resource_model=action_model.resource, service_context=service_context, operation_name='GetFrobs' )