def post(self, data): """Create a new stack.""" handler = infrastructure_handler.InfrastructureStackHandler( pecan.request.security_context) return infrastructure.InfrastructureStack.from_db_model( handler.create(data.as_dict(objects.registry.InfrastructureStack)), pecan.request.host_url)
def test_get_all(self, mock_registry): mock_registry.StackList.get_all.return_value = {} handler = infra.InfrastructureStackHandler(self.ctx) res = handler.get_all() self.assertIsNotNone(res) mock_registry.InfrastructureStackList.get_all.assert_called_once_with( self.ctx)
def test_create(self, mock_get, mock_clients, mock_registry): data = {'user_id': 'new_user_id', 'image_id': 'new_image_id'} db_obj = fakes.FakeInfrastructureStack() fake_template = json.dumps({'description': 'test'}) mock_get.return_value = fake_template parameters = {'image': 'new_image_id'} mock_registry.InfrastructureStack.return_value = db_obj mock_create = mock_clients.return_value.heat.return_value.stacks.create mock_create.return_value = { "stack": { "id": "fake_id", "links": [{ "href": "http://fake.ref", "rel": "self" }] } } mock_queue = mock_clients.return_value.marconi.return_value.queue handler = infra.InfrastructureStackHandler(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(db_obj, res) mock_create.assert_called_once_with(stack_name='infra', template=fake_template, parameters=parameters) mock_queue.assert_called_once_with(db_obj.uuid)
def test_get(self, mock_registry): mock_registry.InfrastructureStack.get_by_uuid.return_value = {} handler = infra.InfrastructureStackHandler(self.ctx) res = handler.get('test_id') self.assertIsNotNone(res) mock_registry.InfrastructureStack.get_by_uuid.assert_called_once_with( self.ctx, 'test_id')
def get(self): """Return this stack.""" handler = infrastructure_handler.InfrastructureStackHandler( pecan.request.security_context) host_url = pecan.request.application_url.rstrip('/') return infrastructure.InfrastructureStack.from_db_model( handler.get(self._id), host_url)
def get_all(self): """Return all stacks, based on the query provided.""" handler = infrastructure_handler.InfrastructureStackHandler( pecan.request.security_context) return [ infrastructure.InfrastructureStack.from_db_model( assm, pecan.request.host_url) for assm in handler.get_all() ]
def put(self, data): """Modify this stack.""" handler = infrastructure_handler.InfrastructureStackHandler( pecan.request.security_context) res = handler.update( self._id, data.as_dict(objects.registry.InfrastructureStack)) return infrastructure.InfrastructureStack.from_db_model( res, pecan.request.host_url)
def test_delete(self, mock_registry): db_obj = fakes.FakeInfrastructureStack() mock_registry.InfrastructureStack.get_by_uuid.return_value = db_obj handler = infra.InfrastructureStackHandler(self.ctx) handler.delete('test_id') db_obj.destroy.assert_called_once_with(self.ctx) mock_registry.InfrastructureStack.get_by_uuid.assert_called_once_with( self.ctx, 'test_id')
def test_update(self, mock_reg): data = { 'user_id': 'new_user_id', 'image_id': 'new_image_id', 'heat_stack_id': 'new_stack_id' } handler = infra.InfrastructureStackHandler(self.ctx) handler.update('test_id', data) mock_reg.InfrastructureStack.update_and_save.assert_called_once_with( self.ctx, 'test_id', data)
def test_update(self, mock_registry): data = { 'user_id': 'new_user_id', 'image_id': 'new_image_id', 'heat_stack_id': 'new_stack_id' } db_obj = fakes.FakeInfrastructureStack() mock_registry.InfrastructureStack.get_by_uuid.return_value = db_obj handler = infra.InfrastructureStackHandler(self.ctx) res = handler.update('test_id', data) self.assertEqual(db_obj.user_id, res.user_id) db_obj.save.assert_called_once_with(self.ctx) db_obj.update.assert_called_once_with(data) mock_registry.InfrastructureStack.get_by_uuid.assert_called_once_with( self.ctx, 'test_id')
def delete(self): """Delete this stack.""" handler = infrastructure_handler.InfrastructureStackHandler( pecan.request.security_context) return handler.delete(self._id)
def get(self): """Return this stack.""" handler = infrastructure_handler.InfrastructureStackHandler( pecan.request.security_context) return infrastructure.InfrastructureStack.from_db_model( handler.get(self._id), pecan.request.host_url)
def test_create_marconi_queue(self, mock_clients, mock_registry): queue_name = 'test' mock_queue = mock_clients.return_value.marconi.return_value.queue handler = infra.InfrastructureStackHandler(self.ctx) handler._create_marconi_queue(queue_name) mock_queue.assert_called_once_with(queue_name)