From b92b1227d2ca859ad5ef46f9855797b6497af1c5 Mon Sep 17 00:00:00 2001 From: Laurent Bachelier Date: Tue, 2 Sep 2014 23:15:01 +0200 Subject: [PATCH] pastebin: Handle limit exceeded warning And skip if found in tests --- modules/pastebin/browser.py | 16 +++++++++++++--- modules/pastebin/test.py | 14 ++++++++++++-- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/modules/pastebin/browser.py b/modules/pastebin/browser.py index da97b8f4..31bae401 100644 --- a/modules/pastebin/browser.py +++ b/modules/pastebin/browser.py @@ -22,9 +22,9 @@ import re from weboob.capabilities.paste import BasePaste, PasteNotFound from weboob.tools.browser2 import HTMLPage, LoginBrowser, need_login, URL +from weboob.tools.browser2.elements import ItemElement from weboob.tools.browser2.filters import Attr, Base, CleanText, DateTime, Env, Filter, FilterError, RawText from weboob.tools.browser2.page import method, RawPage -from weboob.tools.browser2.elements import ItemElement from weboob.tools.exceptions import BrowserHTTPNotFound, BrowserIncorrectPassword, BrowserUnavailable @@ -76,8 +76,8 @@ class PastePage(BasePastebinPage): obj_title = Base(Env('header')) & CleanText('.//div[@class="paste_box_line1"]//h1') obj_contents = RawText('//textarea[@id="paste_code"]') obj_public = Base(Env('header')) \ - & Attr('.//div[@class="paste_box_line1"]//img', 'title') \ - & CleanVisibility() + & Attr('.//div[@class="paste_box_line1"]//img', 'title') \ + & CleanVisibility() obj__date = Base(Env('header')) & Attr('.//div[@class="paste_box_line2"]/span[1]', 'title') & DateTime() @@ -95,6 +95,11 @@ class PostPage(BasePastebinPage): form.submit() +class WarningPage(BasePastebinPage): + def __init__(self, *args, **kwargs): + raise LimitExceeded() + + class UserPage(BasePastebinPage): pass @@ -103,9 +108,14 @@ class BadAPIRequest(BrowserUnavailable): pass +class LimitExceeded(BrowserUnavailable): + pass + + class PastebinBrowser(LoginBrowser): BASEURL = 'http://pastebin.com/' + warning = URL('warning\.php\?p=(?P\d+)', WarningPage) api = URL('api/api_post\.php', RawPage) apilogin = URL('api/api_login\.php', RawPage) login = URL('login', LoginPage) diff --git a/modules/pastebin/test.py b/modules/pastebin/test.py index 8cb075d0..76d1f743 100644 --- a/modules/pastebin/test.py +++ b/modules/pastebin/test.py @@ -17,10 +17,14 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . +from nose.plugins.skip import SkipTest + from weboob.capabilities.base import NotLoaded from weboob.capabilities.paste import PasteNotFound from weboob.tools.test import BackendTest +from .browser import LimitExceeded + class PastebinTest(BackendTest): BACKEND = 'pastebin' @@ -48,7 +52,10 @@ class PastebinTest(BackendTest): # we cannot test public pastes, as the website sometimes forces them as private # there seems to be a very low post per day limit, even when logged in p = self.backend.new_paste(None, title=u'ouiboube', contents=u'Weboob Test', public=False) - self.backend.post_paste(p, max_age=600) + try: + self.backend.post_paste(p, max_age=600) + except LimitExceeded: + raise SkipTest("Limit exceeded") assert p.id assert not p.id.startswith('http://') self.backend.fill_paste(p, ['title']) @@ -59,7 +66,10 @@ class PastebinTest(BackendTest): def test_specialchars(self): # post a paste and get the contents through the HTML response p1 = self.backend.new_paste(None, title=u'ouiboube', contents=u'Weboob ¿¡', public=False) - self.backend.post_paste(p1, max_age=600) + try: + self.backend.post_paste(p1, max_age=600) + except LimitExceeded: + raise SkipTest("Limit exceeded") assert p1.id # not related to testing special chars, but check if the paste is # really private since test_post() tests the contrary