class NFSSourceTearDownTestCase(unittest.TestCase):
    def setUp(self):
        self.source_module = NFSSourceModule()

    def test_tear_down_task_order(self):
        """NFS source tear down task order."""
        tasks = self.source_module.tear_down_with_tasks()
        assert len(tasks) == 2
        assert isinstance(tasks[0], TearDownMountTask)
        assert isinstance(tasks[1], TearDownMountTask)
        name_suffixes = ["-iso", "-device"]
        for task, fragment in zip(tasks, name_suffixes):
            assert task._target_mount.endswith(fragment)
class NFSSourceTestCase(unittest.TestCase):
    def setUp(self):
        self.module = NFSSourceModule()

    def type_test(self):
        """Test NFS source module has a correct type."""
        self.assertEqual(SourceType.NFS, self.module.type)

    def set_up_with_tasks_test(self):
        """Test NFS Source set up call."""
        task_classes = [SetUpNFSSourceTask]

        # task will not be public so it won't be published
        tasks = self.module.set_up_with_tasks()

        # Check the number of the tasks
        task_number = len(task_classes)
        self.assertEqual(task_number, len(tasks))

        for i in range(task_number):
            self.assertIsInstance(tasks[i], task_classes[i])

    def tear_down_with_tasks_test(self):
        """Test NFS Source ready state for tear down."""
        task_classes = [TearDownMountTask]

        # task will not be public so it won't be published
        tasks = self.module.tear_down_with_tasks()

        # check the number of tasks
        task_number = len(task_classes)
        self.assertEqual(task_number, len(tasks))

        for i in range(task_number):
            self.assertIsInstance(tasks[i], task_classes[i])

    def url_property_test(self):
        """Test NFS source URL property is correctly set."""
        self.module.set_url(nfs_url)
        self.assertEqual(nfs_url, self.module.url)
class NFSSourceTestCase(unittest.TestCase):
    def setUp(self):
        self.module = NFSSourceModule()

    def test_type(self):
        """Test NFS source module has a correct type."""
        assert SourceType.NFS == self.module.type

    def test_network_required(self):
        """Test the property network_required."""
        assert self.module.network_required is True

    def test_required_space(self):
        """Test the required_space property."""
        assert self.module.required_space == 0

    @patch("os.path.ismount")
    def test_get_state(self, ismount_mock):
        """Test NFS source state."""
        ismount_mock.return_value = False
        assert SourceState.UNREADY == self.module.get_state()

        ismount_mock.reset_mock()
        ismount_mock.return_value = True

        task = self.module.set_up_with_tasks()[0]
        task.get_result = Mock(return_value="/my/path")
        task.succeeded_signal.emit()
        assert SourceState.READY == self.module.get_state()

        ismount_mock.assert_called_once_with(self.module._device_mount)

    def test_set_up_with_tasks(self):
        """Test NFS Source set up call."""
        task_classes = [SetUpNFSSourceTask]

        # task will not be public so it won't be published
        tasks = self.module.set_up_with_tasks()

        # Check the number of the tasks
        task_number = len(task_classes)
        assert task_number == len(tasks)

        for i in range(task_number):
            assert isinstance(tasks[i], task_classes[i])

    def test_tear_down_with_tasks(self):
        """Test NFS Source ready state for tear down."""
        task_classes = [TearDownMountTask, TearDownMountTask]

        # task will not be public so it won't be published
        tasks = self.module.tear_down_with_tasks()

        # check the number of tasks
        task_number = len(task_classes)
        assert task_number == len(tasks)

        for i in range(task_number):
            assert isinstance(tasks[i], task_classes[i])

    def test_url_property(self):
        """Test NFS source URL property is correctly set."""
        self.module.set_url(NFS_URL)
        assert NFS_URL == self.module.url

    def test_repr(self):
        self.module.set_url(NFS_URL)
        assert repr(self.module
                    ) == "Source(type='NFS', url='nfs:example.com:/some/path')"
Exemple #4
0
class NFSSourceTestCase(unittest.TestCase):
    def setUp(self):
        self.module = NFSSourceModule()

    def type_test(self):
        """Test NFS source module has a correct type."""
        self.assertEqual(SourceType.NFS, self.module.type)

    def network_required_test(self):
        """Test the property network_required."""
        self.assertEqual(self.module.network_required, True)

    @patch("os.path.ismount")
    def get_state_test(self, ismount_mock):
        """Test NFS source state."""
        ismount_mock.return_value = False
        self.assertEqual(SourceState.UNREADY, self.module.get_state())

        ismount_mock.reset_mock()
        ismount_mock.return_value = True

        task = self.module.set_up_with_tasks()[0]
        task.get_result = Mock(return_value="/my/path")
        task.succeeded_signal.emit()
        self.assertEqual(SourceState.READY, self.module.get_state())

        ismount_mock.assert_called_once_with(self.module._device_mount)

    def set_up_with_tasks_test(self):
        """Test NFS Source set up call."""
        task_classes = [SetUpNFSSourceTask]

        # task will not be public so it won't be published
        tasks = self.module.set_up_with_tasks()

        # Check the number of the tasks
        task_number = len(task_classes)
        self.assertEqual(task_number, len(tasks))

        for i in range(task_number):
            self.assertIsInstance(tasks[i], task_classes[i])

    def tear_down_with_tasks_test(self):
        """Test NFS Source ready state for tear down."""
        task_classes = [TearDownMountTask, TearDownMountTask]

        # task will not be public so it won't be published
        tasks = self.module.tear_down_with_tasks()

        # check the number of tasks
        task_number = len(task_classes)
        self.assertEqual(task_number, len(tasks))

        for i in range(task_number):
            self.assertIsInstance(tasks[i], task_classes[i])

    def url_property_test(self):
        """Test NFS source URL property is correctly set."""
        self.module.set_url(nfs_url)
        self.assertEqual(nfs_url, self.module.url)

    def repr_test(self):
        self.module.set_url(nfs_url)
        self.assertEqual(
            repr(self.module),
            "Source(type='NFS', url='nfs:example.com:/some/path')")