pastebin: Handle limit exceeded warning

And skip if found in tests
This commit is contained in:
Laurent Bachelier 2014-09-02 23:15:01 +02:00
commit b92b1227d2
2 changed files with 25 additions and 5 deletions

View file

@ -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<id>\d+)', WarningPage)
api = URL('api/api_post\.php', RawPage)
apilogin = URL('api/api_login\.php', RawPage)
login = URL('login', LoginPage)

View file

@ -17,10 +17,14 @@
# 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 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 <test>¿¡', 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