Exemplo n.º 1
0
    def test_tpb_pagination(self, mock_get):
        mock_response = Mock()
        mock_response.text = self.tpb_response
        mock_get.return_value = mock_response

        api = PirateBayApi()
        torrents, page_num = api.search("Dexter")
        mock_get.assert_called_with('https://thepiratebay.org/search/Dexter/0/7/0')
        torrents, page_num = api.search("Dexter", page=4)
        mock_get.assert_called_with('https://thepiratebay.org/search/Dexter/3/7/0')
Exemplo n.º 2
0
 def test_tpb_one_page_result(self, mock_get):
     mock_response = Mock()
     mock_response.text = self.tpb_one_page_response
     mock_get.return_value = mock_response
     api = PirateBayApi()
     torrents, num_pages = api.search("big buck bunny")
     self.assertEqual(len(torrents), 22, "22 torrents are found on this page")
     self.assertEqual(num_pages, 1, "There is one page with results")
     expected_first_torrent_name = "Big Buck Bunny (Peach): 720p Stereo OGG Theora version"
     self.assertEqual(torrents[0].name, expected_first_torrent_name, "First Torrent object in list matches expected Torrent object")
     self.assertEqual(torrents[0].size, u"187.78 MiB", "incorrect file size")
Exemplo n.º 3
0
    def test_tpb_search(self, mock_get):
        mock_response = Mock()
        mock_response.text = self.tpb_response
        mock_get.return_value = mock_response

        api = PirateBayApi()
        torrents, num_pages = api.search("Dexter")
        self.assertEqual(len(torrents), 30, "30 torrents are found on the first page")
        self.assertEqual(num_pages, 34, "There are 34 pages of results")
        self.assertIsInstance(torrents[0], Torrent, "PirateBayApi.search returns a list of Torrent objects")
        expected_first_torrent_name = "Dexter S08E12 HDTV x264-EVOLVE[ettv]"
        self.assertEqual(torrents[0].name, expected_first_torrent_name, "First Torrent object in list matches expected Torrent object")
Exemplo n.º 4
0
 def test_add_protocol_when_needed(self):
     api = PirateBayApi("sometpbproxy.com")
     self.assertTrue(
         api.base_url.startswith("http://"),
         "Api object adds missing protocol during construction")