def test_get_all_capsules_all_tenants(self, mock_container_get_by_uuid, mock_capsule_list, mock_container_show): test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_container_get_by_uuid.return_value = test_container_obj test_capsule = utils.get_test_capsule() test_capsule_obj = objects.Capsule(self.context, **test_capsule) mock_capsule_list.return_value = [test_capsule_obj] mock_container_show.return_value = test_container_obj response = self.app.get('/capsules/?all_tenants=1') mock_capsule_list.assert_called_once_with(mock.ANY, 1000, None, 'id', 'asc', filters=None) context = mock_capsule_list.call_args[0][0] self.assertIs(True, context.all_tenants) self.assertEqual(200, response.status_int) actual_capsules = response.json['capsules'] self.assertEqual(1, len(actual_capsules)) self.assertEqual(test_capsule['uuid'], actual_capsules[0].get('uuid'))
def test_delete_capsule_by_uuid_all_projects(self, mock_capsule_save, mock_container_get_by_uuid, mock_capsule_get_by_uuid, mock_capsule_delete, mock_policy): mock_policy.return_value = True test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_container_get_by_uuid.return_value = test_container_obj test_capsule = utils.get_test_capsule() test_capsule_obj = objects.Capsule(self.context, **test_capsule) mock_capsule_get_by_uuid.return_value = test_capsule_obj mock_capsule_save.return_value = True mock_capsule_delete.return_value = True capsule_uuid = test_capsule.get('uuid') response = self.app.delete( '/capsules/%s/?all_projects=1' % capsule_uuid) self.assertTrue(mock_capsule_delete.called) self.assertEqual(204, response.status_int) context = mock_capsule_save.call_args[0][0] self.assertIs(True, context.all_projects)
def test_get_one_by_uuid(self, mock_container_get_by_uuid, mock_capsule_get_by_uuid, mock_container_show): test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_container_get_by_uuid.return_value = test_container_obj mock_container_show.return_value = test_container_obj test_capsule = utils.get_test_capsule() test_capsule_obj = objects.Capsule(self.context, **test_capsule) mock_capsule_get_by_uuid.return_value = test_capsule_obj response = self.get('/capsules/%s/' % test_capsule['uuid']) context = mock_capsule_get_by_uuid.call_args[0][0] self.assertIs(False, context.all_tenants) self.assertEqual(200, response.status_int) self.assertEqual(test_capsule['uuid'], response.json['uuid'])
def test_delete_capsule_by_name(self, mock_capsule_save, mock_container_get_by_name, mock_capsule_get_by_uuid, mock_capsule_delete): test_container = utils.get_test_container() test_container_obj = objects.Container(self.context, **test_container) mock_container_get_by_name.return_value = test_container_obj test_capsule = utils.get_test_capsule() test_capsule_obj = objects.Capsule(self.context, **test_capsule) mock_capsule_get_by_uuid.return_value = test_capsule_obj mock_capsule_save.return_value = True mock_capsule_delete.return_value = True capsule_name = test_capsule.get('meta_name') response = self.app.delete('/capsules/%s/' % capsule_name) self.assertTrue(mock_capsule_delete.called) self.assertEqual(204, response.status_int) context = mock_capsule_save.call_args[0][0] self.assertIs(False, context.all_tenants)
def setUp(self): super(TestCapsuleObject, self).setUp() self.fake_capsule = utils.get_test_capsule()