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.capabilities.paste import BasePaste, PasteNotFound
from weboob.tools.browser2 import HTMLPage, LoginBrowser, need_login, URL 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.filters import Attr, Base, CleanText, DateTime, Env, Filter, FilterError, RawText
from weboob.tools.browser2.page import method, RawPage from weboob.tools.browser2.page import method, RawPage
from weboob.tools.browser2.elements import ItemElement
from weboob.tools.exceptions import BrowserHTTPNotFound, BrowserIncorrectPassword, BrowserUnavailable from weboob.tools.exceptions import BrowserHTTPNotFound, BrowserIncorrectPassword, BrowserUnavailable
@ -95,6 +95,11 @@ class PostPage(BasePastebinPage):
form.submit() form.submit()
class WarningPage(BasePastebinPage):
def __init__(self, *args, **kwargs):
raise LimitExceeded()
class UserPage(BasePastebinPage): class UserPage(BasePastebinPage):
pass pass
@ -103,9 +108,14 @@ class BadAPIRequest(BrowserUnavailable):
pass pass
class LimitExceeded(BrowserUnavailable):
pass
class PastebinBrowser(LoginBrowser): class PastebinBrowser(LoginBrowser):
BASEURL = 'http://pastebin.com/' BASEURL = 'http://pastebin.com/'
warning = URL('warning\.php\?p=(?P<id>\d+)', WarningPage)
api = URL('api/api_post\.php', RawPage) api = URL('api/api_post\.php', RawPage)
apilogin = URL('api/api_login\.php', RawPage) apilogin = URL('api/api_login\.php', RawPage)
login = URL('login', LoginPage) login = URL('login', LoginPage)

View file

@ -17,10 +17,14 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with weboob. If not, see <http://www.gnu.org/licenses/>. # 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.base import NotLoaded
from weboob.capabilities.paste import PasteNotFound from weboob.capabilities.paste import PasteNotFound
from weboob.tools.test import BackendTest from weboob.tools.test import BackendTest
from .browser import LimitExceeded
class PastebinTest(BackendTest): class PastebinTest(BackendTest):
BACKEND = 'pastebin' BACKEND = 'pastebin'
@ -48,7 +52,10 @@ class PastebinTest(BackendTest):
# we cannot test public pastes, as the website sometimes forces them as private # 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 # 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) p = self.backend.new_paste(None, title=u'ouiboube', contents=u'Weboob Test', public=False)
try:
self.backend.post_paste(p, max_age=600) self.backend.post_paste(p, max_age=600)
except LimitExceeded:
raise SkipTest("Limit exceeded")
assert p.id assert p.id
assert not p.id.startswith('http://') assert not p.id.startswith('http://')
self.backend.fill_paste(p, ['title']) self.backend.fill_paste(p, ['title'])
@ -59,7 +66,10 @@ class PastebinTest(BackendTest):
def test_specialchars(self): def test_specialchars(self):
# post a paste and get the contents through the HTML response # 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) p1 = self.backend.new_paste(None, title=u'ouiboube', contents=u'Weboob <test>¿¡', public=False)
try:
self.backend.post_paste(p1, max_age=600) self.backend.post_paste(p1, max_age=600)
except LimitExceeded:
raise SkipTest("Limit exceeded")
assert p1.id assert p1.id
# not related to testing special chars, but check if the paste is # not related to testing special chars, but check if the paste is
# really private since test_post() tests the contrary # really private since test_post() tests the contrary