def test_component_get(self, ComponentHandler, resp_mock, request_mock): hand_get = ComponentHandler.return_value.get hand_get.return_value = fakes.FakeComponent() obj = component.ComponentController('test_id') obj.get() hand_get.assert_called_with('test_id') self.assertEqual(200, resp_mock.status)
def test_component_put_none(self, ComponentHandler, resp_mock, request_mock): request_mock.body = None request_mock.content_type = 'application/json' hand_put = ComponentHandler.return_value.put hand_put.return_value = fakes.FakeComponent() component.ComponentController('test_id').put() self.assertEqual(400, resp_mock.status)
def test_delete(self, mock_registry): db_obj = fakes.FakeComponent() mock_registry.Component.get_by_uuid.return_value = db_obj handler = component_handler.ComponentHandler(self.ctx) handler.delete('test_id') db_obj.destroy.assert_called_once_with(self.ctx) mock_registry.Component.get_by_uuid.assert_called_once_with( self.ctx, 'test_id')
def test_component_put_ok(self, ComponentHandler, resp_mock, request_mock): json_update = {'name': 'fee', 'user_id': 'me'} request_mock.body = json.dumps(json_update) request_mock.content_type = 'application/json' hand_update = ComponentHandler.return_value.update hand_update.return_value = fakes.FakeComponent() component.ComponentController('test_id').put() hand_update.assert_called_with('test_id', json_update) self.assertEqual(200, resp_mock.status)
def test_create(self, mock_registry): data = {'name': 'new_name', 'assembly_id': 'new_assembly_id'} db_obj = fakes.FakeComponent() mock_registry.Component.return_value = db_obj handler = component_handler.ComponentHandler(self.ctx) res = handler.create(data) db_obj.update.assert_called_once_with(data) db_obj.create.assert_called_once_with(self.ctx) self.assertEqual(res, db_obj)
def test_stacks_post_nodata(self, handler_mock, resp_mock, request_mock): request_mock.body = '' request_mock.content_type = 'application/json' handler_create = handler_mock.return_value.create handler_create.return_value = fakes.FakeComponent() ret_val = infrastructure.InfrastructureStacksController().post() self.assertEqual("Missing argument: \"data\"", str(ret_val['faultstring'])) self.assertEqual(400, resp_mock.status)
def test_update(self, mock_registry): data = {'user_id': 'new_user_id'} db_obj = fakes.FakeComponent() mock_registry.Component.get_by_uuid.return_value = db_obj handler = component_handler.ComponentHandler() res = handler.update('test_id', data) self.assertEqual(db_obj.user_id, res.user_id) db_obj.save.assert_called_once_with(None) mock_registry.Component.get_by_uuid.assert_called_once_with( None, 'test_id')
def test_operations_post_nodata(self, handler_mock, resp_mock, request_mock, mock_policy): mock_policy.return_value = True request_mock.body = '' request_mock.content_type = 'application/json' handler_create = handler_mock.return_value.create handler_create.return_value = fakes.FakeComponent() ret_val = operation.OperationsController().post() self.assertEqual("Missing argument: \"data\"", str(ret_val['faultstring'])) self.assertEqual(400, resp_mock.status)
def test_component_put_ok(self, ComponentHandler, resp_mock, request_mock, mock_policy): mock_policy.return_value = True json_update = {'name': 'update_foo', 'description': 'update_desc_component', 'user_id': 'user_id_test', 'project_id': 'project_id_test'} request_mock.body = json.dumps(json_update) request_mock.content_type = 'application/json' hand_update = ComponentHandler.return_value.update hand_update.return_value = fakes.FakeComponent() component.ComponentController('test_id').put() hand_update.assert_called_with('test_id', json_update) self.assertEqual(200, resp_mock.status)
def test_component_get(self, ComponentHandler, resp_mock, request_mock, mock_policy): mock_policy.return_value = True hand_get = ComponentHandler.return_value.get fake_component = fakes.FakeComponent() hand_get.return_value = fake_component obj = component.ComponentController('test_id') resp = obj.get() self.assertIsNotNone(resp) self.assertEqual(fake_component.name, resp['result'].name) self.assertEqual(fake_component.description, resp['result'].description) hand_get.assert_called_with('test_id') self.assertEqual(200, resp_mock.status)
def test_components_get_all(self, handler_mock, resp_mock, request_mock, mock_policy): mock_policy.return_value = True hand_get_all = handler_mock.return_value.get_all fake_component = fakes.FakeComponent() hand_get_all.return_value = [fake_component] obj = component.ComponentsController() resp = obj.get_all() hand_get_all.assert_called_with() self.assertIsNotNone(resp) self.assertEqual(fake_component.name, resp['result'][0].name) self.assertEqual(fake_component.description, resp['result'][0].description) self.assertEqual(200, resp_mock.status)
def test_components_post(self, handler_mock, resp_mock, request_mock, mock_policy): json_create = {'name': 'foo', 'description': 'test_desc_component', 'user_id': 'user_id_test', 'project_id': 'project_id_test'} mock_policy.return_value = True request_mock.body = json.dumps(json_create) request_mock.content_type = 'application/json' handler_create = handler_mock.return_value.create handler_create.return_value = fakes.FakeComponent() component.ComponentsController().post() handler_create.assert_called_with(json_create) self.assertEqual(201, resp_mock.status) handler_create.assert_called_once_with(json_create)