Esempio n. 1
0
class TestNfsBrokerDeleteFiles(TestCase):
    def setUp(self):
        django.setup()

        self.broker = NfsBroker()
        self.broker.load_configuration({
            'type': NfsBroker().broker_type,
            'nfs_path': 'host:/path'
        })

    @patch('storage.brokers.nfs_broker.os.path.exists')
    @patch('storage.brokers.nfs_broker.os.remove')
    def test_successfully(self, mock_remove, mock_exists):
        """Tests calling NfsBroker.delete_files() successfully"""
        def new_exists(path):
            return True

        mock_exists.side_effect = new_exists

        volume_path = os.path.join('the', 'volume', 'path')
        file_path_1 = os.path.join('my_dir', 'my_file.txt')
        file_path_2 = os.path.join('my_dir', 'my_file.json')
        full_path_file_1 = os.path.join(volume_path, file_path_1)
        full_path_file_2 = os.path.join(volume_path, file_path_2)

        file_1 = storage_test_utils.create_file(file_path=file_path_1)
        file_2 = storage_test_utils.create_file(file_path=file_path_2)

        # Call method to test
        self.broker.delete_files(volume_path, [file_1, file_2])

        # Check results
        two_calls = [call(full_path_file_1), call(full_path_file_2)]
        mock_remove.assert_has_calls(two_calls)

        self.assertTrue(file_1.is_deleted)
        self.assertIsNotNone(file_1.deleted)
        self.assertTrue(file_2.is_deleted)
        self.assertIsNotNone(file_2.deleted)
Esempio n. 2
0
class TestNfsBrokerDeleteFiles(TestCase):

    def setUp(self):
        django.setup()

        self.broker = NfsBroker()
        self.broker.load_configuration({'type': NfsBroker().broker_type, 'nfs_path': 'host:/path'})

    @patch('storage.brokers.nfs_broker.os.path.exists')
    @patch('storage.brokers.nfs_broker.os.remove')
    def test_successfully(self, mock_remove, mock_exists):
        """Tests calling NfsBroker.delete_files() successfully"""

        def new_exists(path):
            return True
        mock_exists.side_effect = new_exists

        volume_path = os.path.join('the', 'volume', 'path')
        file_path_1 = os.path.join('my_dir', 'my_file.txt')
        file_path_2 = os.path.join('my_dir', 'my_file.json')
        full_path_file_1 = os.path.join(volume_path, file_path_1)
        full_path_file_2 = os.path.join(volume_path, file_path_2)

        file_1 = storage_test_utils.create_file(file_path=file_path_1)
        file_2 = storage_test_utils.create_file(file_path=file_path_2)

        # Call method to test
        self.broker.delete_files(volume_path, [file_1, file_2])

        # Check results
        two_calls = [call(full_path_file_1), call(full_path_file_2)]
        mock_remove.assert_has_calls(two_calls)

        self.assertTrue(file_1.is_deleted)
        self.assertIsNotNone(file_1.deleted)
        self.assertTrue(file_2.is_deleted)
        self.assertIsNotNone(file_2.deleted)
Esempio n. 3
0
    def test_successfully(self, mock_remove, mock_umount, mock_mount, mock_exists):
        '''Tests calling NfsBroker.delete_files() successfully'''

        def new_exists(path):
            return True
        mock_exists.side_effect = new_exists

        mount = 'host:/dir'
        work_dir = os.path.join('the', 'work', 'dir')
        file_1 = os.path.join('my_dir', 'my_file.txt')
        file_2 = os.path.join('my_dir', 'my_file.json')
        full_path_file_1 = os.path.join(work_dir, file_1)
        full_path_file_2 = os.path.join(work_dir, file_2)

        # Call method to test
        broker = NfsBroker()
        broker.load_config({'type': NfsBroker.broker_type, 'mount': mount})
        broker.delete_files(work_dir, [file_1, file_2])

        # Check results
        mock_mount.assert_called_once_with(mount, work_dir, False)
        two_calls = [call(full_path_file_1), call(full_path_file_2)]
        mock_remove.assert_has_calls(two_calls)
        mock_umount.assert_called_once_with(work_dir)