def test_list(self, mock_list_objects): def list_objects(): yield 1 yield 2 mock_list_objects.side_effect = list_objects objects = swift.Objects(self.creds_manager).list() self.assertEqual(1, next(objects)) self.assertEqual(2, next(objects)) self.assertRaises(StopIteration, next, objects)
def test_check_prerequisite(self): objects_manager = swift.Objects(self.creds_manager) with mock.patch.object(objects_manager, 'list_images_by_owner') as m: m.return_value = [] self.cloud.list_volume_backups.return_value = ["foo"] self.assertEqual(False, objects_manager.check_prerequisite()) self.cloud.list_volume_backups.return_value = [] self.assertEqual(True, objects_manager.check_prerequisite()) m.return_value = ["bar"] self.assertEqual(False, objects_manager.check_prerequisite())
def test_delete(self): objects = [ { 'name': 'toto', 'container_name': 'foo' }, { 'name': 'tata foo', 'container_name': 'baz bar' }, { 'name': 'titi#1', 'container_name': 'bar#2' }, { 'name': 'hihi♫', 'container_name': 'bar♫' }, ] for obj in objects: self.assertIsNone(swift.Objects(self.creds_manager).delete(obj)) self.cloud.delete_object.assert_called_with( obj['container_name'], obj['name'])
def test_to_string(self): obj = mock.MagicMock() self.assertIn("Object '", swift.Objects(self.creds_manager).to_str(obj))
def test_delete(self): obj = mock.MagicMock() self.assertIsNone(swift.Objects(self.creds_manager).delete(obj)) self.cloud.delete_object.assert_called_once_with( obj['container_name'], obj['name'])
def test_disable(self): obj = {'name': 'toto', 'container_name': 'foo'} with self.assertLogs(level='WARNING'): swift.Objects(self.creds_manager).disable(obj)