browser2: Handle server issues of postbin.org
And move tests outside.
This commit is contained in:
parent
72cbc5bd8b
commit
60d1d03c1c
3 changed files with 96 additions and 44 deletions
|
|
@ -17,6 +17,8 @@
|
|||
# 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 __future__ import absolute_import
|
||||
|
||||
import requests
|
||||
from requests.status_codes import codes
|
||||
|
||||
|
|
@ -203,47 +205,3 @@ class Browser(object):
|
|||
kwargs.setdefault('headers', {}).setdefault('Content-Length', '0')
|
||||
kwargs.setdefault('timeout', self.TIMEOUT)
|
||||
return self.session.request(*args, **kwargs)
|
||||
|
||||
|
||||
def test_base():
|
||||
b = Browser()
|
||||
r = b.location('http://httpbin.org/headers')
|
||||
assert isinstance(r.text, unicode)
|
||||
assert 'Firefox' in r.text
|
||||
assert 'python' not in r.text
|
||||
assert 'identity' not in r.text
|
||||
assert b.url == 'http://httpbin.org/headers'
|
||||
|
||||
|
||||
def test_redirects():
|
||||
b = Browser()
|
||||
b.location('http://httpbin.org/redirect/1')
|
||||
assert b.url == 'http://httpbin.org/get'
|
||||
|
||||
|
||||
def test_brokenpost():
|
||||
"""
|
||||
Tests _fix_redirect()
|
||||
"""
|
||||
b = Browser()
|
||||
# postbin is picky with empty posts. that's good!
|
||||
r = b.location('http://www.postbin.org/', {})
|
||||
# ensures empty data (but not None) does a POST
|
||||
assert r.request.method == 'POST'
|
||||
# ensure we were redirected after submitting a post
|
||||
assert len(r.url) >= len('http://www.postbin.org/')
|
||||
# send a POST with data
|
||||
b.location(r.url, {'hello': 'world'})
|
||||
r = b.location(r.url + '/feed')
|
||||
assert 'hello' in r.text
|
||||
assert 'world' in r.text
|
||||
|
||||
|
||||
def test_weboob():
|
||||
class BooBrowser(Browser):
|
||||
PROFILE = Weboob('0.0')
|
||||
|
||||
b = BooBrowser()
|
||||
r = b.location('http://httpbin.org/headers')
|
||||
assert 'weboob/0.0' in r.text
|
||||
assert 'identity' in r.text
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue