Пример #1
0
class LiveOSSourceTestCase(unittest.TestCase):
    def setUp(self):
        self.module = LiveOSSourceModule()

    def set_up_with_tasks_test(self):
        """Test Live OS Source set up call."""
        task_classes = [SetUpLiveOSSourceTask]

        # 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 Live OS 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])
Пример #2
0
class LiveOSSourceTestCase(unittest.TestCase):
    def setUp(self):
        self.module = LiveOSSourceModule()

    def test_network_required(self):
        """Test the property network_required."""
        self.assertEqual(self.module.network_required, False)

    def test_required_space(self):
        """Test the required_space property."""
        self.assertEqual(self.module.required_space, 0)

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

        ismount_mock.reset_mock()
        ismount_mock.return_value = True

        self.assertEqual(SourceState.READY, self.module.get_state())

        ismount_mock.assert_called_once_with(self.module.mount_point)

    def test_set_up_with_tasks(self):
        """Test Live OS Source set up call."""
        task_classes = [SetUpLiveOSSourceTask]

        # 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 test_tear_down_with_tasks(self):
        """Test Live OS 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 test_repr(self):
        self.module.set_image_path("/some/path")
        self.assertEqual(repr(self.module),
                         "Source(type='LIVE_OS_IMAGE', image='/some/path')")
class LiveOSSourceTestCase(unittest.TestCase):
    def setUp(self):
        self.live_os_source_module = LiveOSSourceModule()

    def type_test(self):
        """Test Live OS source module has a correct type."""
        self.assertEqual(SourceType.LIVE_OS_IMAGE,
                         self.live_os_source_module.type)

    def set_up_with_tasks_test(self):
        """Test Live OS Source set up call."""
        task_classes = [SetUpLiveOSSourceTask]

        # task will not be public so it won't be published
        tasks = self.live_os_source_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 Live OS Source ready state for tear down."""
        task_classes = [TearDownLiveOSSourceTask]

        # task will not be public so it won't be published
        tasks = self.live_os_source_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])

    @patch("os.path.ismount")
    def ready_state_test(self, ismount):
        """Test Live OS Source ready state for set up."""
        ismount.return_value = False
        self.assertFalse(self.live_os_source_module.is_ready())

        ismount.reset_mock()
        ismount.return_value = True

        self.assertTrue(self.live_os_source_module.is_ready())

        ismount.assert_called_once_with(INSTALL_TREE)
class LiveOSSourceTestCase(unittest.TestCase):
    """Test the Live OS source."""
    def setUp(self):
        self.module = LiveOSSourceModule()

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

    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 the source state."""
        ismount_mock.return_value = False
        assert SourceState.UNREADY == self.module.get_state()

        ismount_mock.reset_mock()
        ismount_mock.return_value = True

        assert SourceState.READY == self.module.get_state()
        ismount_mock.assert_called_once_with(self.module.mount_point)

    def test_set_up_with_tasks(self):
        """Test the set up tasks."""
        tasks = self.module.set_up_with_tasks()
        assert len(tasks) == 1
        assert isinstance(tasks[0], SetUpLiveOSSourceTask)

    def test_tear_down_with_tasks(self):
        """Test the tear down tasks."""
        tasks = self.module.tear_down_with_tasks()
        assert len(tasks) == 1
        assert isinstance(tasks[0], TearDownMountTask)

    def test_repr(self):
        """Test the string representation."""
        self.module.set_image_path("/some/path")
        assert repr(
            self.module) == "Source(type='LIVE_OS_IMAGE', image='/some/path')"