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):
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):
def get_torrent(self, id):
def get_torrent_file(self, id):
# -*- coding: utf-8 -*-
from weboob.capabilities.torrent import CapTorrent
from import Module
from .browser import BTDiggBrowser
__all__ = ['BTDiggModule']
class BTDiggModule(Module, CapTorrent):
NAME = 'btdigg'
MAINTAINER = u'Matthieu Rakotojaona'
EMAIL = ''
VERSION = '1.2'
DESCRIPTION = 'The BitTorrent DHT search engine.'
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):
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
from 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):
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 - 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):
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 - 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 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.size
assert torrent.magnet
self.assertEquals(40, len(
def test_get_random_torrentfile(self):
torrent = choice(list(self.backend.iter_torrents('ubuntu linux')))
full_torrent = self.backend.get_torrent(
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 == u'Ubuntu Linux Toolbox - 1000+ Commands for Ubuntu and Debian Power Users'
assert len(torrent.files) == 3
assert torrent.size == float(7004487.68)
dt =
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
# 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 <>.
from 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(
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():
if backends_without_tests:
print('Modules without tests: %s' % backends_without_tests)
if backends_without_icons:
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