add a test script
This commit is contained in:
parent
dcecf61f46
commit
ddcf9ffb0e
5 changed files with 52 additions and 19 deletions
|
|
@ -19,7 +19,7 @@
|
|||
|
||||
from __future__ import with_statement
|
||||
|
||||
from weboob.capabilities.bill import ICapBill, SubscriptionNotFound, BillNotFound
|
||||
from weboob.capabilities.bill import ICapBill, SubscriptionNotFound, BillNotFound, Subscription, Bill
|
||||
from weboob.tools.backend import BaseBackend, BackendConfig
|
||||
from weboob.tools.value import ValueBackendPassword
|
||||
|
||||
|
|
@ -77,9 +77,11 @@ class FreeMobileBackend(BaseBackend, ICapBill):
|
|||
raise BillNotFound()
|
||||
|
||||
def iter_bills(self, subscription):
|
||||
if not isinstance(subscription, Subscription):
|
||||
subscription = self.get_subscription(subscription)
|
||||
|
||||
with self.browser:
|
||||
sub = self.get_subscription(subscription)
|
||||
for bill in self.browser.iter_bills(sub.id):
|
||||
for bill in self.browser.iter_bills(subscription.id):
|
||||
yield bill
|
||||
|
||||
# The subscription is actually useless, but maybe for the futur...
|
||||
|
|
@ -88,6 +90,9 @@ class FreeMobileBackend(BaseBackend, ICapBill):
|
|||
for detail in self.browser.get_details():
|
||||
yield detail
|
||||
|
||||
def download_bill(self, id):
|
||||
def download_bill(self, bill):
|
||||
if not isinstance(bill, Bill):
|
||||
bill = self.get_bill(bill)
|
||||
|
||||
with self.browser:
|
||||
return self.browser.download_bill(id)
|
||||
return self.browser.readurl(bill._url)
|
||||
|
|
|
|||
|
|
@ -99,9 +99,3 @@ class Freemobile(BaseBrowser):
|
|||
for a in l:
|
||||
if a.id == id:
|
||||
return a
|
||||
|
||||
def download_bill(self, id):
|
||||
assert isinstance(id, basestring)
|
||||
bill = self.get_bill(id)
|
||||
|
||||
return self.readurl(bill._url)
|
||||
|
|
|
|||
|
|
@ -82,23 +82,23 @@ class DetailsPage(BasePage):
|
|||
for div in divs:
|
||||
detail = Detail()
|
||||
|
||||
detail.label = div.find('div[@class="titreDetail"]/p').text_content()
|
||||
detail.label = unicode(div.find('div[@class="titreDetail"]/p').text_content())
|
||||
if inter:
|
||||
detail.label = detail.label + " (international)"
|
||||
detail.infos = div.find('div[@class="consoDetail"]/p').text_content().lstrip()
|
||||
detail.label = detail.label + u" (international)"
|
||||
detail.infos = unicode(div.find('div[@class="consoDetail"]/p').text_content().lstrip())
|
||||
detail.price = convert_price(div)
|
||||
|
||||
self.details.append(detail)
|
||||
|
||||
def parse_voice(self, div, string, inter=False):
|
||||
voice = Detail()
|
||||
voice.label = div.find('div[@class="titreDetail"]/p').text_content()
|
||||
voice.label = unicode(div.find('div[@class="titreDetail"]/p').text_content())
|
||||
if inter:
|
||||
voice.label = voice.label + " (international)"
|
||||
voice.price = convert_price(div)
|
||||
voice1 = div.xpath('div[@class="consoDetail"]/p/span')[0].text
|
||||
voice2 = div.xpath('div[@class="consoDetail"]/p/span')[1].text
|
||||
voice.infos = string % (voice1, voice2)
|
||||
voice.infos = unicode(string) % (voice1, voice2)
|
||||
|
||||
return voice
|
||||
|
||||
|
|
|
|||
|
|
@ -31,11 +31,11 @@ class HomePage(BasePage):
|
|||
def get_list(self):
|
||||
l = []
|
||||
divabo = self.document.xpath('//div[@class="idAbonne pointer"]')[0]
|
||||
owner = divabo.xpath('p')[0].text.replace(' - ', '')
|
||||
phone = divabo.xpath('p/span')[0].text
|
||||
owner = unicode(divabo.xpath('p')[0].text.replace(' - ', ''))
|
||||
phone = unicode(divabo.xpath('p/span')[0].text)
|
||||
self.browser.logger.debug('Found ' + owner + ' has subscriber')
|
||||
self.browser.logger.debug('Found ' + phone + ' has phone number')
|
||||
phoneplan = self.document.xpath('//div[@class="forfaitChoisi"]')[0].text.lstrip().rstrip()
|
||||
phoneplan = unicode(self.document.xpath('//div[@class="forfaitChoisi"]')[0].text.lstrip().rstrip())
|
||||
self.browser.logger.debug('Found ' + phoneplan + ' has subscription type')
|
||||
|
||||
subscription = Subscription(phone)
|
||||
|
|
|
|||
34
modules/freemobile/test.py
Normal file
34
modules/freemobile/test.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright(C) 2012 Romain Bignon
|
||||
#
|
||||
# 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
|
||||
|
||||
|
||||
__all__ = ['FreeMobileTest']
|
||||
|
||||
|
||||
class FreeMobileTest(BackendTest):
|
||||
BACKEND = 'freemobile'
|
||||
|
||||
def test_freemobile(self):
|
||||
for subscription in self.backend.iter_subscription():
|
||||
list(self.backend.iter_history(subscription.id))
|
||||
for bill in self.backend.iter_bills(subscription.id):
|
||||
self.backend.download_bill(bill.id)
|
||||
Loading…
Add table
Add a link
Reference in a new issue