Ejemplo n.º 1
0
class TestRemove(unittest.TestCase):
    """Test case for the DownloadList remove method."""
    def setUp(self):
        self.mocks = [
            mock.Mock(object_id=0),
            mock.Mock(object_id=1),
            mock.Mock(object_id=2)
        ]
        self.dlist = DownloadList(self.mocks)

    def test_remove(self):
        self.assertTrue(self.dlist.remove(1))

        self.assertEqual(self.dlist._items_list, [0, 2])
        self.assertEqual(self.dlist._items_dict, {
            0: self.mocks[0],
            2: self.mocks[2]
        })

    def test_remove_not_exist(self):
        self.assertRaises(KeyError, self.dlist.remove, 3)

    def test_remove_active(self):
        self.mocks[1].stage = "Active"

        self.assertFalse(self.dlist.remove(1))
        self.assertEqual(self.dlist._items_list, [0, 1, 2])
        self.assertEqual(self.dlist._items_dict, {
            0: self.mocks[0],
            1: self.mocks[1],
            2: self.mocks[2]
        })
Ejemplo n.º 2
0
 def setUp(self):
     self.mocks = [
         mock.Mock(object_id=0),
         mock.Mock(object_id=1),
         mock.Mock(object_id=2)
     ]
     self.dlist = DownloadList(self.mocks)
Ejemplo n.º 3
0
    def test_insert(self):
        mock_ditem = mock.Mock(object_id=0)

        dlist = DownloadList()
        dlist.insert(mock_ditem)

        self.assertEqual(dlist._items_list, [0])
        self.assertEqual(dlist._items_dict, {0: mock_ditem})
Ejemplo n.º 4
0
    def test_insert(self):
        mock_ditem = mock.Mock(object_id=0)

        dlist = DownloadList()
        dlist.insert(mock_ditem)

        self.assertEqual(dlist._items_list, [0])
        self.assertEqual(dlist._items_dict, {0: mock_ditem})
Ejemplo n.º 5
0
class TestHasItem(unittest.TestCase):
    """Test case for the DownloadList has_item method."""
    def setUp(self):
        mock_ditem = mock.Mock(object_id=1337)
        self.dlist = DownloadList([mock_ditem])

    def test_has_item_true(self):
        self.assertTrue(self.dlist.has_item(1337))

    def test_has_item_false(self):
        self.assertFalse(self.dlist.has_item(1000))
Ejemplo n.º 6
0
class TestIndex(unittest.TestCase):
    """Test case for the DownloadList index method."""
    def setUp(self):
        self.mocks = [mock.Mock(object_id=i) for i in range(3)]
        self.dlist = DownloadList(self.mocks)

    def test_index(self):
        self.assertEqual(self.dlist.index(2), 2)

    def test_index_not_exist(self):
        self.assertEqual(self.dlist.index(3), -1)
Ejemplo n.º 7
0
class TestChangeStage(unittest.TestCase):
    """Test case for the DownloadList change_stage method."""
    def setUp(self):
        self.mocks = [mock.Mock(object_id=i, stage="Queued") for i in range(3)]
        self.dlist = DownloadList(self.mocks)

    def test_change_stage(self):
        self.dlist.change_stage(0, "Active")
        self.assertEqual(self.mocks[0].stage, "Active")

    def test_change_stage_id_not_exist(self):
        self.assertRaises(KeyError, self.dlist.change_stage, 3, "Active")
Ejemplo n.º 8
0
class TestIndex(unittest.TestCase):

    """Test case for the DownloadList index method."""

    def setUp(self):
        self.mocks = [mock.Mock(object_id=i) for i in range(3)]
        self.dlist = DownloadList(self.mocks)

    def test_index(self):
        self.assertEqual(self.dlist.index(2), 2)

    def test_index_not_exist(self):
        self.assertEqual(self.dlist.index(3), -1)
Ejemplo n.º 9
0
class TestHasItem(unittest.TestCase):

    """Test case for the DownloadList has_item method."""

    def setUp(self):
        mock_ditem = mock.Mock(object_id=1337)
        self.dlist = DownloadList([mock_ditem])

    def test_has_item_true(self):
        self.assertTrue(self.dlist.has_item(1337))

    def test_has_item_false(self):
        self.assertFalse(self.dlist.has_item(1000))
Ejemplo n.º 10
0
class TestChangeStage(unittest.TestCase):

    """Test case for the DownloadList change_stage method."""

    def setUp(self):
        self.mocks = [mock.Mock(object_id=i, stage="Queued") for i in range(3)]
        self.dlist = DownloadList(self.mocks)

    def test_change_stage(self):
        self.dlist.change_stage(0, "Active")
        self.assertEqual(self.mocks[0].stage, "Active")

    def test_change_stage_id_not_exist(self):
        self.assertRaises(KeyError, self.dlist.change_stage, 3, "Active")
Ejemplo n.º 11
0
    def test_downloadmanager(self, mock_opt_manager, mock_mainframe, mock_worker):
        config_path = "/home/user/.config"
        dwl_list = DownloadList(
            [
                DownloadItem("url1", ["-v", "-F"]),
                DownloadItem("url2", ["-v", "-F"]),
                DownloadItem("url3", ["-v", "-F"]),
            ]
        )
        opt_manager = mock_opt_manager(config_path)
        opt_manager.options = {
            "youtubedl_path": config_path,
            "workers_number": 3,
            "disable_update": True,
        }
        parent = mock_mainframe(opt_manager)
        mock_worker.available.return_value = True
        # End thread for this test like daemon
        # TODO: Finished join the thread
        dwn_manager = DownloadManager(parent, dwl_list, opt_manager, daemon=True)

        self.assertTrue(dwn_manager._running)
        self.assertEqual(dwn_manager.name, "DownloadManager")
        self.assertEqual(len(dwn_manager._workers), 3)
        dwn_manager.stop_downloads()
        self.assertFalse(dwn_manager._running)
        self.assertTrue(dwn_manager._jobs_done())
Ejemplo n.º 12
0
class TestMoveUp(unittest.TestCase):
    """Test case for the DownloadList move_up method."""
    def setUp(self):
        mocks = [mock.Mock(object_id=i, stage="Queued") for i in range(3)]
        self.dlist = DownloadList(mocks)  # type: ignore

    def test_move_up(self):
        self.assertTrue(self.dlist.move_up(1))
        self.assertEqual(self.dlist._items_list, [1, 0, 2])

    def test_move_up_already_on_top(self):
        self.assertFalse(self.dlist.move_up(0))
        self.assertEqual(self.dlist._items_list, [0, 1, 2])

    def test_move_up_not_exist(self):
        self.assertRaises(ValueError, self.dlist.move_up, 666)
Ejemplo n.º 13
0
class TestMoveDown(unittest.TestCase):
    """Test case for the DownloadList move_down method."""
    def setUp(self):
        mocks = [mock.Mock(object_id=i, stage="Queued") for i in range(3)]
        self.dlist = DownloadList(mocks)

    def test_move_down(self):
        self.assertTrue(self.dlist.move_down(1))
        self.assertEqual(self.dlist._items_list, [0, 2, 1])

    def test_move_down_already_on_bottom(self):
        self.assertFalse(self.dlist.move_down(2))
        self.assertEqual(self.dlist._items_list, [0, 1, 2])

    def test_move_down_not_exist(self):
        self.assertRaises(ValueError, self.dlist.move_down, 666)
Ejemplo n.º 14
0
class TestMoveDown(unittest.TestCase):

    """Test case for the DownloadList move_down method."""

    def setUp(self):
        mocks = [mock.Mock(object_id=i, stage="Queued") for i in range(3)]
        self.dlist = DownloadList(mocks)

    def test_move_down(self):
        self.assertTrue(self.dlist.move_down(1))
        self.assertEqual(self.dlist._items_list, [0, 2, 1])

    def test_move_down_already_on_bottom(self):
        self.assertFalse(self.dlist.move_down(2))
        self.assertEqual(self.dlist._items_list, [0, 1, 2])

    def test_move_down_not_exist(self):
        self.assertRaises(ValueError, self.dlist.move_down, 666)
Ejemplo n.º 15
0
    def test_fetch_next(self):
        items_count = 3

        mocks = [mock.Mock(object_id=i, stage="Queued") for i in range(items_count)]

        dlist = DownloadList(mocks)

        for i in range(items_count):
            self.assertEqual(dlist.fetch_next(), mocks[i])
            mocks[i].stage = "Active"

        self.assertIsNone(dlist.fetch_next())

        for i in range(items_count):
            mocks[i].stage = "Completed"

        self.assertIsNone(dlist.fetch_next())

        mocks[1].stage = "Queued"  # Re-queue item
        self.assertEqual(dlist.fetch_next(), mocks[1])
Ejemplo n.º 16
0
class TestRemove(unittest.TestCase):

    """Test case for the DownloadList remove method."""

    def setUp(self):
        self.mocks = [mock.Mock(object_id=0), mock.Mock(object_id=1), mock.Mock(object_id=2)]
        self.dlist = DownloadList(self.mocks)

    def test_remove(self):
        self.assertTrue(self.dlist.remove(1))

        self.assertEqual(self.dlist._items_list, [0, 2])
        self.assertEqual(self.dlist._items_dict, {0: self.mocks[0], 2: self.mocks[2]})

    def test_remove_not_exist(self):
        self.assertRaises(KeyError, self.dlist.remove, 3)

    def test_remove_active(self):
        self.mocks[1].stage = "Active"

        self.assertFalse(self.dlist.remove(1))
        self.assertEqual(self.dlist._items_list, [0, 1, 2])
        self.assertEqual(self.dlist._items_dict, {0: self.mocks[0], 1: self.mocks[1], 2: self.mocks[2]})
Ejemplo n.º 17
0
    def test_fetch_next(self):
        items_count = 3

        mocks = [mock.Mock(object_id=i, stage="Queued") for i in range(items_count)]

        dlist = DownloadList(mocks)

        for i in range(items_count):
            self.assertEqual(dlist.fetch_next(), mocks[i])
            mocks[i].stage = "Active"

        self.assertIsNone(dlist.fetch_next())

        for i in range(items_count):
            mocks[i].stage = "Completed"

        self.assertIsNone(dlist.fetch_next())

        mocks[1].stage = "Queued"  # Re-queue item
        self.assertEqual(dlist.fetch_next(), mocks[1])
Ejemplo n.º 18
0
 def setUp(self):
     self.mocks = [mock.Mock(object_id=i) for i in range(3)]
     self.dlist = DownloadList(self.mocks)
Ejemplo n.º 19
0
 def test_init_empty(self):
     dlist = DownloadList()
     self.assertEqual(dlist._items_list, [])
     self.assertEqual(dlist._items_dict, {})
Ejemplo n.º 20
0
    def test_init(self):
        mocks = [mock.Mock(object_id=0), mock.Mock(object_id=1)]

        dlist = DownloadList(mocks)
        self.assertEqual(dlist._items_list, [0, 1])
        self.assertEqual(dlist._items_dict, {0: mocks[0], 1: mocks[1]})
Ejemplo n.º 21
0
 def setUp(self):
     mock_ditem = mock.Mock(object_id=1337)
     self.dlist = DownloadList([mock_ditem])
Ejemplo n.º 22
0
 def test_get_items_empty_list(self):
     dlist = DownloadList()
     self.assertEqual(dlist.get_items(), [])
Ejemplo n.º 23
0
 def setUp(self):
     mock_ditem = mock.Mock(object_id=1337)
     self.dlist = DownloadList([mock_ditem])
Ejemplo n.º 24
0
 def setUp(self):
     self.mocks = [mock.Mock(object_id=0), mock.Mock(object_id=1), mock.Mock(object_id=2)]
     self.dlist = DownloadList(self.mocks)
Ejemplo n.º 25
0
 def test_get_items_empty_list(self):
     dlist = DownloadList()
     self.assertEqual(dlist.get_items(), [])
Ejemplo n.º 26
0
 def test_get_length_empty_list(self):
     dlist = DownloadList()
     self.assertEqual(len(dlist), 0)
Ejemplo n.º 27
0
    def test_get_items(self):
        mocks = [mock.Mock() for _ in range(3)]
        dlist = DownloadList(mocks)

        self.assertEqual(dlist.get_items(), mocks)
Ejemplo n.º 28
0
 def test_get_item_not_exist(self):
     dlist = DownloadList()
     self.assertIsNone(dlist.get_item(0))
Ejemplo n.º 29
0
    def test_get_items(self):
        mocks = [mock.Mock() for _ in range(3)]
        dlist = DownloadList(mocks)

        self.assertEqual(dlist.get_items(), mocks)
Ejemplo n.º 30
0
 def test_fetch_next_empty_list(self):
     dlist = DownloadList()
     self.assertIsNone(dlist.fetch_next())
Ejemplo n.º 31
0
    def test_clear(self):
        dlist = DownloadList([mock.Mock() for _ in range(3)])

        self.assertEqual(len(dlist), 3)
        dlist.clear()
        self.assertEqual(len(dlist), 0)
Ejemplo n.º 32
0
 def setUp(self):
     mocks = [mock.Mock(object_id=i, stage="Queued") for i in range(3)]
     self.dlist = DownloadList(mocks)
Ejemplo n.º 33
0
    def test_get_item(self):
        mocks = [mock.Mock(object_id=i) for i in range(3)]
        dlist = DownloadList(mocks)

        self.assertEqual(dlist.get_item(0), mocks[0])
        self.assertEqual(dlist.get_item(2), mocks[2])
Ejemplo n.º 34
0
    def test_get_item(self):
        mocks = [mock.Mock(object_id=i) for i in range(3)]
        dlist = DownloadList(mocks)

        self.assertEqual(dlist.get_item(0), mocks[0])
        self.assertEqual(dlist.get_item(2), mocks[2])
Ejemplo n.º 35
0
 def setUp(self):
     self.mocks = [mock.Mock(object_id=i) for i in range(3)]
     self.dlist = DownloadList(self.mocks)
Ejemplo n.º 36
0
 def test_get_item_not_exist(self):
     dlist = DownloadList()
     self.assertRaises(KeyError, dlist.get_item, 0)
Ejemplo n.º 37
0
 def setUp(self):
     mocks = [mock.Mock(object_id=i, stage="Queued") for i in range(3)]
     self.dlist = DownloadList(mocks)
Ejemplo n.º 38
0
 def test_get_length(self):
     dlist = DownloadList([mock.Mock(), mock.Mock()])
     self.assertEqual(len(dlist), 2)
Ejemplo n.º 39
0
 def test_fetch_next_empty_list(self):
     dlist = DownloadList()
     self.assertIsNone(dlist.fetch_next())
Ejemplo n.º 40
0
    def test_clear(self):
        dlist = DownloadList([mock.Mock() for _ in range(3)])

        self.assertEqual(len(dlist), 3)
        dlist.clear()
        self.assertEqual(len(dlist), 0)