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): """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')"