Ignore redirects when polling for resources.
This commit is contained in:
Родитель
c953ad4c63
Коммит
8d300c73e8
|
@ -107,7 +107,10 @@ def try_get_resource(err, package, url, filename, resource_type="URL",
|
|||
# Some versions of requests don't support close().
|
||||
pass
|
||||
|
||||
if not data:
|
||||
final_status = request.status_code
|
||||
final_status -= final_status % 100
|
||||
|
||||
if not data and final_status != 300:
|
||||
generic_http_error()
|
||||
|
||||
return data
|
||||
|
|
|
@ -47,6 +47,7 @@ def safe(func):
|
|||
with patch("requests.get") as r_g:
|
||||
request = Mock()
|
||||
request.text = "foo bar"
|
||||
request.status_code = 200
|
||||
# The first bit is the return value. The second bit tells whatever
|
||||
# is requesting the data that there's no more data.
|
||||
request.raw.read.side_effect = [request.text, ""]
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
import json
|
||||
|
||||
from mock import patch
|
||||
|
||||
from appvalidator import validate_app, validate_packaged_app
|
||||
from helper import safe
|
||||
|
||||
|
|
|
@ -122,6 +122,7 @@ class TestDataOutput(TestCase):
|
|||
def test_too_big(self, r_g):
|
||||
big_response_object = Mock()
|
||||
big_response_object.raw.read.return_value = "x" * 100
|
||||
big_response_object.status_code = 200
|
||||
r_g.return_value = big_response_object
|
||||
|
||||
appbase.try_get_resource(self.err, None, "http://foo.bar/", "")
|
||||
|
@ -132,6 +133,7 @@ class TestDataOutput(TestCase):
|
|||
def test_just_right(self, r_g):
|
||||
normal_response_object = Mock()
|
||||
normal_response_object.raw.read.side_effect = ["x" * 100, ""]
|
||||
normal_response_object.status_code = 200
|
||||
r_g.return_value = normal_response_object
|
||||
|
||||
eq_(appbase.try_get_resource(self.err, None, "http://foo.bar/", ""),
|
||||
|
@ -143,12 +145,25 @@ class TestDataOutput(TestCase):
|
|||
def test_empty(self, r_g):
|
||||
empty_response = Mock()
|
||||
empty_response.raw.read.return_value = ""
|
||||
empty_response.status_code = 200
|
||||
r_g.return_value = empty_response
|
||||
|
||||
eq_(appbase.try_get_resource(
|
||||
self.err, None, "http://foo.bar/", ""), "")
|
||||
self.assert_failed(with_errors=True)
|
||||
|
||||
@patch("requests.get")
|
||||
@patch("appvalidator.constants.MAX_RESOURCE_SIZE", 100)
|
||||
def test_empty_redirect(self, r_g):
|
||||
empty_response = Mock()
|
||||
empty_response.raw.read.return_value = ""
|
||||
empty_response.status_code = 345
|
||||
r_g.return_value = empty_response
|
||||
|
||||
eq_(appbase.try_get_resource(
|
||||
self.err, None, "http://foo.bar/", ""), "")
|
||||
self.assert_silent()
|
||||
|
||||
|
||||
class TestResourcePolling(TestCase):
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче