Add object type filtering to iter_resources
This commit is contained in:
parent
63da39e005
commit
bfb3689456
16 changed files with 92 additions and 61 deletions
|
|
@ -102,22 +102,23 @@ class RadioFranceBackend(BaseBackend, ICapRadio, ICapCollection, ICapVideo):
|
|||
_RSS_RADIOS = ('francemusique', )
|
||||
_ANTENNA_RADIOS = ('fip', )
|
||||
|
||||
def iter_resources(self, split_path):
|
||||
if len(split_path) == 1 and split_path[0] == 'francebleu':
|
||||
for _id in sorted(self._RADIOS.iterkeys()):
|
||||
if _id.startswith('fb'):
|
||||
yield self.get_radio(_id)
|
||||
elif len(split_path) == 0:
|
||||
for _id in sorted(self._RADIOS.iterkeys()):
|
||||
if not _id.startswith('fb'):
|
||||
yield self.get_radio(_id)
|
||||
yield Collection('francebleu', 'France Bleu',
|
||||
children=self.iter_resources(['francebleu']))
|
||||
else:
|
||||
raise CollectionNotFound(split_path)
|
||||
def iter_resources(self, objs, split_path):
|
||||
if Radio in objs:
|
||||
if len(split_path) == 1 and split_path[0] == 'francebleu':
|
||||
for _id in sorted(self._RADIOS.iterkeys()):
|
||||
if _id.startswith('fb'):
|
||||
yield self.get_radio(_id)
|
||||
elif len(split_path) == 0:
|
||||
for _id in sorted(self._RADIOS.iterkeys()):
|
||||
if not _id.startswith('fb'):
|
||||
yield self.get_radio(_id)
|
||||
yield Collection('francebleu', 'France Bleu',
|
||||
children=self.iter_resources(objs, ['francebleu']))
|
||||
else:
|
||||
raise CollectionNotFound(split_path)
|
||||
|
||||
def iter_radios_search(self, pattern):
|
||||
for radio in self._flatten_resources(self.iter_resources([])):
|
||||
for radio in self._flatten_resources(self.iter_resources((Radio, ), [])):
|
||||
if pattern.lower() in radio.title.lower() or pattern.lower() in radio.description.lower():
|
||||
yield radio
|
||||
|
||||
|
|
|
|||
|
|
@ -19,14 +19,20 @@
|
|||
|
||||
|
||||
from weboob.tools.test import BackendTest
|
||||
from weboob.capabilities.video import BaseVideo
|
||||
from weboob.capabilities.radio import Radio
|
||||
|
||||
|
||||
class RadioFranceTest(BackendTest):
|
||||
BACKEND = 'radiofrance'
|
||||
|
||||
def test_get_radios(self):
|
||||
l = list(self.backend.iter_resources([]))
|
||||
self.assertTrue(len(l) > 0)
|
||||
l = list(self.backend.iter_resources(objs=[Radio], split_path=[]))
|
||||
self.assertTrue(0 < len(l) < 30)
|
||||
l = list(self.backend.iter_resources(objs=[Radio], split_path=['francebleu']))
|
||||
self.assertTrue(len(l) > 30)
|
||||
l = list(self.backend.iter_resources(objs=[BaseVideo], split_path=[]))
|
||||
self.assertEquals(len(l), 0)
|
||||
|
||||
def test_get_video(self):
|
||||
# this should be available up to 24/10/2014 15h00
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue