Ejemplo n.º 1
0
    def test_file_exists(self):
        def fake_call_method(module, method, *args, **kwargs):
            if method == 'SearchDatastore_Task':
                ds_browser = args[0]
                self.assertEqual('fake-browser', ds_browser)
                datastorePath = kwargs.get('datastorePath')
                self.assertEqual('fake-path', datastorePath)
                return 'fake_exists_task'
            elif method == 'get_dynamic_property':
                info = fake.DataObject()
                info.name = 'search_task'
                info.state = 'success'
                result = fake.DataObject()
                result.path = 'fake-path'
                matched = fake.DataObject()
                matched.path = 'fake-file'
                result.file = [matched]
                info.result = result
                return info
            # Should never get here
            self.fail()

        with mock.patch.object(self.session, '_call_method',
                               fake_call_method):
            file_exists = ds_util.file_exists(self.session,
                    'fake-browser', 'fake-path', 'fake-file')
            self.assertTrue(file_exists)
Ejemplo n.º 2
0
    def test_file_exists_fails(self):
        def fake_call_method(module, method, *args, **kwargs):
            if method == 'SearchDatastore_Task':
                return 'fake_exists_task'
            elif method == 'get_dynamic_property':
                info = fake.DataObject()
                info.name = 'search_task'
                info.state = 'error'
                error = fake.DataObject()
                error.localizedMessage = "Error message"
                error.fault = fake.FileNotFound()
                info.error = error
                return info
            # Should never get here
            self.fail()

        with mock.patch.object(self.session, '_call_method',
                               fake_call_method):
            file_exists = ds_util.file_exists(self.session,
                    'fake-browser', 'fake-path', 'fake-file')
            self.assertFalse(file_exists)
Ejemplo n.º 3
0
    def test_file_exists_fails(self):
        def fake_call_method(module, method, *args, **kwargs):
            if method == "SearchDatastore_Task":
                return "fake_exists_task"

            # Should never get here
            self.fail()

        def fake_wait_for_task(task_ref):
            if task_ref == "fake_exists_task":
                raise vexc.FileNotFoundException()

            # Should never get here
            self.fail()

        with contextlib.nested(
            mock.patch.object(self.session, "_call_method", fake_call_method),
            mock.patch.object(self.session, "_wait_for_task", fake_wait_for_task),
        ):
            ds_path = ds_util.DatastorePath("ds", "fake/path")
            file_exists = ds_util.file_exists(self.session, "fake-browser", ds_path, "fake-file")
            self.assertFalse(file_exists)
Ejemplo n.º 4
0
    def test_file_exists(self):
        def fake_call_method(module, method, *args, **kwargs):
            if method == 'SearchDatastore_Task':
                ds_browser = args[0]
                self.assertEqual('fake-browser', ds_browser)
                datastorePath = kwargs.get('datastorePath')
                self.assertEqual('[ds] fake/path', datastorePath)
                return 'fake_exists_task'

            # Should never get here
            self.fail()

        def fake_wait_for_task(task_ref):
            if task_ref == 'fake_exists_task':
                result_file = fake.DataObject()
                result_file.path = 'fake-file'

                result = fake.DataObject()
                result.file = [result_file]
                result.path = '[ds] fake/path'

                task_info = fake.DataObject()
                task_info.result = result

                return task_info

            # Should never get here
            self.fail()

        with contextlib.nested(
                mock.patch.object(self.session, '_call_method',
                                  fake_call_method),
                mock.patch.object(self.session, '_wait_for_task',
                                  fake_wait_for_task)):
            ds_path = ds_obj.DatastorePath('ds', 'fake/path')
            file_exists = ds_util.file_exists(self.session,
                    'fake-browser', ds_path, 'fake-file')
            self.assertTrue(file_exists)
Ejemplo n.º 5
0
    def test_file_exists_fails(self):
        def fake_call_method(module, method, *args, **kwargs):
            if method == 'SearchDatastore_Task':
                return 'fake_exists_task'

            # Should never get here
            self.fail()

        def fake_wait_for_task(task_ref):
            if task_ref == 'fake_exists_task':
                raise error_util.FileNotFoundException()

            # Should never get here
            self.fail()

        with contextlib.nested(
                mock.patch.object(self.session, '_call_method',
                                  fake_call_method),
                mock.patch.object(self.session, '_wait_for_task',
                                  fake_wait_for_task)):
            file_exists = ds_util.file_exists(self.session,
                    'fake-browser', 'fake-path', 'fake-file')
            self.assertFalse(file_exists)
Ejemplo n.º 6
0
    def test_file_exists(self):
        def fake_call_method(module, method, *args, **kwargs):
            if method == "SearchDatastore_Task":
                ds_browser = args[0]
                self.assertEqual("fake-browser", ds_browser)
                datastorePath = kwargs.get("datastorePath")
                self.assertEqual("[ds] fake/path", datastorePath)
                return "fake_exists_task"

            # Should never get here
            self.fail()

        def fake_wait_for_task(task_ref):
            if task_ref == "fake_exists_task":
                result_file = fake.DataObject()
                result_file.path = "fake-file"

                result = fake.DataObject()
                result.file = [result_file]
                result.path = "[ds] fake/path"

                task_info = fake.DataObject()
                task_info.result = result

                return task_info

            # Should never get here
            self.fail()

        with contextlib.nested(
            mock.patch.object(self.session, "_call_method", fake_call_method),
            mock.patch.object(self.session, "_wait_for_task", fake_wait_for_task),
        ):
            ds_path = ds_util.DatastorePath("ds", "fake/path")
            file_exists = ds_util.file_exists(self.session, "fake-browser", ds_path, "fake-file")
            self.assertTrue(file_exists)