class ParsingTestCase(RemoteTestCase): def setUp(self): self.torrents = Search(self.url, 'tpb afk') def test_items(self): self.assertEqual(len(list(self.torrents.items())), 30) self.assertEqual(len(list(iter(self.torrents))), 30) def test_creation_dates(self): """ Make sure torrents aren't lazily created. """ alpha = time.time() # Create torrents torrents = self.torrents.items() time.sleep(1) # If they were lazily evaluated, they would be created now diff = next(torrents)._created[1] - alpha self.assertTrue(diff > 1) def test_torrent_rows(self): request = urlopen(str(self.torrents.url)) document = html.parse(request) rows = self.torrents._get_torrent_rows(document.getroot()) self.assertEqual(len(rows), 30) def test_torrent_build(self): for torrent in self.torrents.items(): if torrent.title == 'TPB.AFK.2013.720p.h264-SimonKlose' and\ torrent.user == 'SimonKlose': self.assertEqual(torrent.user_status, 'VIP') self.assertTrue(torrent.comments >= 313) self.assertEqual(torrent.has_cover, 'Yes') break
class ParsingTestCase(RemoteTestCase): def setUp(self): self.torrents = Search(self.url, 'tpb afk') def test_items(self): self.assertEqual(len(list(self.torrents.items())), 30) self.assertEqual(len(list(iter(self.torrents))), 30) def test_creation_dates(self): """ Make sure torrents aren't lazily created. """ alpha = time.time() # Create torrents torrents = self.torrents.items() time.sleep(1) # If they were lazily evaluated, they would be created now diff = next(torrents)._created[1] - alpha self.assertTrue(diff > 1) def test_torrent_rows(self): request = urlopen(str(self.torrents.url)) document = html.parse(request) rows = self.torrents._get_torrent_rows(document.getroot()) self.assertEqual(len(rows), 30) def test_torrent_build(self): pass
def search(self, query, page=0, order=7, category=0, multipage=False): """ Searches TPB for query and returns a list of paginated Torrents capable of changing query, categories and orders. """ search = Search(self.base_url, query, page, order, category) if multipage: search.multipage() return search
def test_search(self): kwargs = {'query': 'tpb afk', 'page': 5, 'order': 9, 'category': 100} a_search = self.tpb.search(**kwargs) b_search = Search(self.url, **kwargs) self.assertTrue(isinstance(a_search, Search)) self.assertTrue(isinstance(b_search, Search)) self.assertEqual(str(a_search.url), str(b_search.url))
class ParsingTestCase(RemoteTestCase): def setUp(self): self.torrents = Search(self.url, 'breaking bad') def test_items(self): self.assertEqual(len(list(self.torrents.items())), 30) self.assertEqual(len(list(iter(self.torrents))), 30) def test_torrent_rows(self): request = urlopen(str(self.torrents.url)) content = request.read() page = BeautifulSoup(content) rows = self.torrents._get_torrent_rows(page) self.assertEqual(len(rows), 30) def test_torrent_build(self): pass
class SearchTestCase(RemoteTestCase): def setUp(self): self.torrents = Search(self.url, 'breaking bad') def test_url(self): self.assertEqual(str(self.torrents.url), self.url + '/search/breaking%20bad/0/7/0') self.torrents.query('something').page(1).next().previous() self.torrents.order(9).category(100) self.assertEqual(self.torrents.query(), 'something') self.assertEqual(self.torrents.page(), 1) self.assertEqual(self.torrents.order(), 9) self.assertEqual(self.torrents.category(), 100) self.assertEqual(str(self.torrents.url), self.url + '/search/something/1/9/100')
class TorrentTestCase(RemoteTestCase): def setUp(self): self.torrents = Search(self.url, 'tpb afk') def assertEqualDatetimes(self, *datetimes): datetimes = [d.replace(microsecond=0) for d in datetimes] return self.assertEqual(*datetimes) def test_created_timestamp_parse(self): for torrent in self.torrents.items(): torrent.created torrent._created = ('1 sec ago', time.time()) self.assertEqualDatetimes( torrent.created, datetime.now() - timedelta(seconds=1)) torrent._created = ('1 min ago', time.time()) self.assertEqualDatetimes( torrent.created, datetime.now() - timedelta(minutes=1)) torrent._created = ('1 hour ago', time.time()) self.assertEqualDatetimes( torrent.created, datetime.now() - timedelta(hours=1)) torrent._created = ('Today', time.time()) self.assertEqual(torrent.created.date(), datetime.now().date()) torrent._created = ('Y-day', time.time()) self.assertEqual(torrent.created.date(), (datetime.now() - timedelta(days=1)).date()) torrent._created = ('1 sec ago', time.time() - 60 * 60 * 24) self.assertEqualDatetimes(torrent.created, datetime.now() - timedelta(days=1, seconds=1)) def test_info(self): for torrent in self.torrents.items(): self.assertNotEqual('', torrent.info.strip()) def test_files(self): for torrent in self.torrents.items(): self.assertTrue(len(torrent.files) > 0)
class TorrentTestCase(RemoteTestCase): def setUp(self): self.torrents = Search(self.url, 'breaking bad') def assertEqualDatetimes(self, *datetimes): datetimes = [ d.replace(microsecond=0) for d in datetimes ] return self.assertEqual(*datetimes) def test_created_timestamp_parse(self): for torrent in self.torrents.items(): torrent.created torrent._created = '1 sec ago' self.assertEqualDatetimes(torrent.created, datetime.now() - timedelta(seconds=1)) torrent._created = '1 min ago' self.assertEqualDatetimes(torrent.created, datetime.now() - timedelta(minutes=1)) torrent._created = '1 hour ago' self.assertEqualDatetimes(torrent.created, datetime.now() - timedelta(hours=1)) torrent._created = 'Today' self.assertEqual(torrent.created.date(), datetime.now().date())
class SearchTestCase(RemoteTestCase): def setUp(self): self.torrents = Search(self.url, 'breaking bad') def test_url(self): self.assertEqual(str(self.torrents.url), self.url + '/search/breaking%20bad/0/7/0') self.torrents.query('something').page(1).next().previous() self.torrents.order(9).category(100) self.assertEqual(self.torrents.query(), 'something') self.assertEqual(self.torrents.page(), 1) self.assertEqual(self.torrents.order(), 9) self.assertEqual(self.torrents.category(), 100) self.assertEqual(str(self.torrents.url), self.url + '/search/something/1/9/100') def test_torrents(self): for item in self.torrents: self.assertEqual(unicode, type(item.title)) self.assertEqual(unicode, type(item.user)) self.assertTrue(hasattr(item, 'url')) # ensure the URL points to the /torrent/ html page self.assertTrue(item.url.path().startswith('/torrent/'))
class SearchTestCase(RemoteTestCase): def setUp(self): self.torrents = Search(self.url, 'tpb afk') def test_url(self): self.assertEqual(str(self.torrents.url), self.url + '/search/tpb%20afk/0/7/0') self.torrents.query('something').page(1).next().previous() self.torrents.order(9).category(100) self.assertEqual(self.torrents.query(), 'something') self.assertEqual(self.torrents.page(), 1) self.assertEqual(self.torrents.order(), 9) self.assertEqual(self.torrents.category(), 100) self.assertEqual(str(self.torrents.url), self.url + '/search/something/1/9/100') def test_torrents(self): for item in self.torrents: self.assertEqual(unicode, type(item.title)) self.assertEqual(unicode, type(item.user)) self.assertTrue(hasattr(item, 'url')) # ensure the URL points to the /torrent/ html page self.assertTrue(item.url.path().startswith('/torrent/'))
def setUp(self): self.torrents = Search(self.url, 'breaking bad')
def setUp(self): self.torrents = Search(self.url, 'tpb afk')