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_delete_ok(self, ComponentHandler, resp_mock, request_mock): hand_delete = ComponentHandler.return_value.delete hand_delete.return_value = None obj = component.ComponentController('test_id') obj.delete() hand_delete.assert_called_with('test_id') self.assertEqual(204, 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_component_delete_not_found(self, ComponentHandler, resp_mock, request_mock): hand_delete = ComponentHandler.return_value.delete hand_delete.side_effect = exception.NotFound(name='component', component_id='test_id') obj = component.ComponentController('test_id') obj.delete() hand_delete.assert_called_with('test_id') self.assertEqual(404, resp_mock.status)
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_component_get_not_found(self, ComponentHandler, resp_mock, request_mock): hand_get = ComponentHandler.return_value.get hand_get.side_effect = exception.NotFound(name='component', component_id='test_id') cont = component.ComponentController('test_id') cont.get() hand_get.assert_called_with('test_id') self.assertEqual(404, resp_mock.status)
def test_component_put_not_found(self, ComponentHandler, resp_mock, request_mock): json_update = {'user_id': 'foo', 'name': 'appy'} request_mock.body = json.dumps(json_update) request_mock.content_type = 'application/json' hand_update = ComponentHandler.return_value.update hand_update.side_effect = exception.NotFound(name='component', component_id='test_id') component.ComponentController('test_id').put() hand_update.assert_called_with('test_id', json_update) self.assertEqual(404, 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_component_delete(self, resp_mock, request_mock): obj = component.ComponentController('test_id') obj.delete() self.assertEqual(501, resp_mock.status)
def test_component_get(self, resp_mock, request_mock): obj = component.ComponentController('test_id') obj.get() self.assertEqual(200, resp_mock.status)