paste* backends: Use the check_url decorator

This commit is contained in:
Laurent Bachelier 2011-04-21 22:21:17 +02:00
commit c1c9b39e9d
4 changed files with 15 additions and 2 deletions

View file

@ -23,7 +23,7 @@ import re
from weboob.tools.browser import BaseBrowser, BrowserUnavailable, BrowserHTTPNotFound
from weboob.capabilities.paste import PasteNotFound
from weboob.tools.browser.decorators import id2url
from weboob.tools.browser.decorators import id2url, check_url
from .pages import PastePage, CaptchaPage, PostPage
from .paste import PastealaconPaste
@ -43,6 +43,7 @@ class PastealaconBrowser(BaseBrowser):
BaseBrowser.__init__(self, *args, **kwargs)
@id2url(PastealaconPaste.id2url)
@check_url(PASTE_URL)
def get_paste(self, url):
_id = re.match('^%s$' % self.PASTE_URL, url).groupdict()['id']
return PastealaconPaste(_id)

View file

@ -71,3 +71,10 @@ class PastealaconTest(BackendTest):
# raw method
p = self.backend.get_paste(_id)
self.assertRaises(PasteNotFound, self.backend.fillobj, p, ['contents'])
def test_checkurl(self):
# call with an URL we can't handle with this backend
assert self.backend.get_paste('http://pastebin.com/nJG9ZFG8') is None
# same even with correct domain (IDs are numeric)
assert self.backend.get_paste('http://pastealacon.com/nJG9ZFG8') is None
assert self.backend.get_paste('nJG9ZFG8') is None

View file

@ -19,7 +19,7 @@
from weboob.tools.browser import BaseBrowser, BrowserHTTPNotFound
from weboob.tools.browser.decorators import id2url
from weboob.tools.browser.decorators import id2url, check_url
from weboob.capabilities.paste import PasteNotFound
@ -54,6 +54,7 @@ class PastebinBrowser(BaseBrowser):
raise PasteNotFound()
@id2url(PastebinPaste.id2url)
@check_url(PASTE_URL)
def get_paste(self, url):
_id = re.match('^%s$' % self.PASTE_URL, url).groupdict()['id']
return PastebinPaste(_id)

View file

@ -69,3 +69,7 @@ class PastebinTest(BackendTest):
# raw method
p = self.backend.get_paste(_id)
self.assertRaises(PasteNotFound, self.backend.fillobj, p, ['contents'])
def test_checkurl(self):
# call with an URL we can't handle with this backend
assert self.backend.get_paste('http://pastealacon.com/1') is None