Commit 35408601 authored by Phyks (Lucas Verney)'s avatar Phyks (Lucas Verney) Committed by Florent Fourcot

Work on Weboob linting

* Sort alphabetically modules in weboob linting script
* Remove btdigg module, as btdigg website is dead.
* Add icons for all modules with a missing icon.
* Add some unittests for LDLC.
parent 434c0f15
from .module import BTDiggModule
__all__ = ['BTDiggModule']
# -*- coding: utf-8 -*-
from weboob.browser import PagesBrowser, URL
from .pages.index import IndexPage
from .pages.torrents import TorrentsPage, TorrentPage
__all__ = ['BTDiggBrowser']
class BTDiggBrowser(PagesBrowser):
BASEURL = 'https://btdigg.org'
index_page = URL('/$', IndexPage)
torrents_page = URL('/search\?.*q=(?P<query>.+)', TorrentsPage)
torrent_page = URL('/search\?.*info_hash=(?P<hash>.+)', TorrentPage)
def home(self):
return self.index_page.go()
def iter_torrents(self, pattern):
self.torrents_page.go(query=pattern)
return self.page.iter_torrents()
def get_torrent(self, id):
self.torrent_page.go(hash=id)
return self.page.get_torrent()
def get_torrent_file(self, id):
self.torrent_page.go(hash=id)
return self.page.get_torrent_file()
# -*- coding: utf-8 -*-
from weboob.capabilities.torrent import CapTorrent
from weboob.tools.backend import Module
from .browser import BTDiggBrowser
__all__ = ['BTDiggModule']
class BTDiggModule(Module, CapTorrent):
NAME = 'btdigg'
MAINTAINER = u'Matthieu Rakotojaona'
EMAIL = 'matthieu.rakotojaona@gmail.com'
VERSION = '1.2'
DESCRIPTION = 'The BitTorrent DHT search engine.'
LICENSE = 'CC0'
BROWSER = BTDiggBrowser
def create_default_browser(self):
return self.create_browser()
def get_torrent(self, id):
return self.browser.get_torrent(id)
def get_torrent_file(self, id):
return self.browser.get_torrent_file(id)
def iter_torrents(self, pattern):
return self.browser.iter_torrents(pattern.replace(' ', '+'))
# -*- coding: utf-8 -*-
from weboob.browser.pages import HTMLPage
class IndexPage(HTMLPage):
pass
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
from weboob.tools.misc import get_bytes_size
from weboob.browser.pages import HTMLPage
from weboob.browser.elements import ItemElement, ListElement, method
from weboob.capabilities.torrent import Torrent, MagnetOnly
from weboob.browser.filters.standard import CleanText, Regexp
class TorrentsPage(HTMLPage):
@method
class iter_torrents(ListElement):
item_xpath = '//div[@id="search_res"]/table/tr'
class item(ItemElement):
klass = Torrent
obj_id = Regexp(CleanText('./td/table/tr/td[@class="torrent_name"]/a/@href'),
r'info_hash=([0-9a-f]+)', '\\1')
obj_name = CleanText('./td/table/tr/td[@class="torrent_name"]')
obj_magnet = CleanText('./td/table/tr/td[@class="ttth"]/a/@href')
def obj_date(self):
valueago, valueunit, _ = CleanText('./td/table/tr/td[5]/span[@class="attr_val"]')(self).split()
delta = timedelta(**{valueunit: float(valueago)})
return datetime.now() - delta
def obj_size(self):
value, unit = CleanText('./td/table/tr/td[2]/span[@class="attr_val"]')(self).split()
return get_bytes_size(float(value), unit)
class TorrentPage(HTMLPage):
@method
class get_torrent(ItemElement):
klass = Torrent
ROOT = '//table[@class="torrent_info_tbl"]'
obj_id = Regexp(CleanText(ROOT + '/tr[3]/td[2]/a/@href'), r'urn:btih:([0-9a-f]+)', '\\1')
obj_name = CleanText(ROOT + '/tr[4]/td[2]')
obj_magnet = CleanText(ROOT + '/tr[3]/td[2]/a/@href')
def obj_files(self):
return [_.text for _ in self.xpath(self.ROOT + '/tr[position() > 15]/td[2]')]
def obj_date(self):
valueago, valueunit, _ = CleanText(self.ROOT + '/tr[7]/td[2]')(self).split()
delta = timedelta(**{valueunit: float(valueago)})
return datetime.now() - delta
def obj_size(self):
value, unit = CleanText(self.ROOT + '/tr[6]/td[2]')(self).split()
return get_bytes_size(float(value), unit)
def get_torrent_file(self):
raise MagnetOnly(self.get_torrent().magnet)
# -*- coding: utf-8 -*-
from weboob.tools.test import BackendTest
from weboob.capabilities.torrent import MagnetOnly
from random import choice
class BTDiggTest(BackendTest):
MODULE = 'btdigg'
def test_iter_torrents(self):
# try something popular so we sometimes get a magnet-only torrent
l = list(self.backend.iter_torrents('ubuntu linux'))
self.assertTrue(len(l) == 10)
for torrent in l:
assert torrent.name
assert torrent.size
assert torrent.magnet
assert torrent.date
self.assertEquals(40, len(torrent.id))
def test_get_random_torrentfile(self):
torrent = choice(list(self.backend.iter_torrents('ubuntu linux')))
full_torrent = self.backend.get_torrent(torrent.id)
try:
self.backend.get_torrent_file(torrent.id)
except MagnetOnly as e:
assert e.magnet.startswith("magnet:")
assert e.magnet == full_torrent.magnet
def test_get_special_torrent(self):
torrent = self.backend.get_torrent("abd1d2648c97958789d62f6a6a1f5d33f4eff5be")
assert torrent.name == u'Ubuntu Linux Toolbox - 1000+ Commands for Ubuntu and Debian Power Users'
assert len(torrent.files) == 3
assert torrent.size == float(7004487.68)
dt = torrent.date
assert dt.year == 2013
assert dt.month == 12
# -*- coding: utf-8 -*-
# Copyright(C) 2013-2014 Florent Fourcot
#
# This file is part of weboob.
#
# weboob is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# weboob is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
from weboob.tools.test import BackendTest
class LdlcTest(BackendTest):
MODULE = 'ldlc'
def test_downloadbills(self):
"""
Iter all bills and try to download it.
"""
for subscription in self.backend.iter_subscription():
for bill in self.backend.iter_documents(subscription.id):
self.backend.download_document(bill.id)
def test_list(self):
"""
Test listing of subscriptions.
"""
subscriptions = list(self.backend.iter_subscription())
self.assertTrue(len(subscriptions) > 0, msg="Account listing failed")
......@@ -24,8 +24,10 @@ for name, backend in weboob.modules_loader.loaded.iteritems():
backends_without_icons.append(name)
if backends_without_tests:
backends_without_tests.sort()
print('Modules without tests: %s' % backends_without_tests)
if backends_without_icons:
backends_without_icons.sort()
print('Modules without icons: %s' % backends_without_icons)
if backends_without_tests or backends_without_icons:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment