示例#1
0
 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)
示例#2
0
 def test_stack_put_none(self, StackHandler, resp_mock, request_mock):
     request_mock.body = None
     request_mock.content_type = 'application/json'
     hand_put = StackHandler.return_value.put
     hand_put.return_value = fakes.FakeInfrastructureStack()
     infrastructure.InfrastructureStackController('test_id').put()
     self.assertEqual(400, resp_mock.status)
示例#3
0
 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')
示例#4
0
 def test_stack_put_ok(self, StackHandler, resp_mock, request_mock):
     json_update = {'name': 'foo'}
     request_mock.body = json.dumps(json_update)
     request_mock.content_type = 'application/json'
     hand_update = StackHandler.return_value.update
     hand_update.return_value = fakes.FakeInfrastructureStack()
     infrastructure.InfrastructureStackController('test_id').put()
     hand_update.assert_called_with('test_id', json_update)
     self.assertEqual(200, resp_mock.status)
示例#5
0
 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')
示例#6
0
 def test_stacks_post(self, handler_mock, resp_mock, request_mock):
     json_create = {
         'name': 'foo',
         'description': 'test_desc_stack',
         'user_id': 'user_id_test',
         'project_id': 'project_id_test'
     }
     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.FakeInfrastructureStack()
     infrastructure.InfrastructureStacksController().post()
     handler_create.assert_called_with(json_create)
     self.assertEqual(201, resp_mock.status)
     handler_create.assert_called_once_with(json_create)
示例#7
0
 def test_stacks_get_all(self, handler_mock, resp_mock, request_mock):
     hand_get_all = handler_mock.return_value.get_all
     fake_stack = fakes.FakeInfrastructureStack()
     hand_get_all.return_value = [fake_stack]
     obj = infrastructure.InfrastructureStacksController()
     resp = obj.get_all()
     self.assertIsNotNone(resp)
     self.assertEqual(fake_stack.name, resp['result'][0].name)
     self.assertEqual(fake_stack.image_id, resp['result'][0].image_id)
     self.assertEqual(fake_stack.heat_stack_id,
                      resp['result'][0].heat_stack_id)
     self.assertEqual(fake_stack.description, resp['result'][0].description)
     self.assertEqual(fake_stack.project_id, resp['result'][0].project_id)
     self.assertEqual(fake_stack.uuid, resp['result'][0].uuid)
     self.assertEqual(200, resp_mock.status)
示例#8
0
 def test_stack_get(self, StackHandler, resp_mock, request_mock):
     hand_get = StackHandler.return_value.get
     fake_stack = fakes.FakeInfrastructureStack()
     hand_get.return_value = fake_stack
     cont = infrastructure.InfrastructureStackController('test_id')
     resp = cont.get()
     self.assertIsNotNone(resp)
     self.assertEqual(fake_stack.name, resp['result'].name)
     self.assertEqual(fake_stack.image_id, resp['result'].image_id)
     self.assertEqual(fake_stack.heat_stack_id,
                      resp['result'].heat_stack_id)
     self.assertEqual(fake_stack.description, resp['result'].description)
     self.assertEqual(fake_stack.project_id, resp['result'].project_id)
     self.assertEqual(fake_stack.uuid, resp['result'].uuid)
     hand_get.assert_called_with('test_id')
     self.assertEqual(200, resp_mock.status)