Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ignore redirects when polling for resources.

  • Loading branch information...
commit 8d300c73e8267b0ecbd251021a8af422a8057c2e 1 parent c953ad4
@mattbasta authored
View
5 appvalidator/testcases/webappbase.py
@@ -107,7 +107,10 @@ def generic_http_error():
# 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
View
1  tests/helper.py
@@ -47,6 +47,7 @@ def wrap(test_icon, *args, **kwargs):
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, ""]
View
2  tests/test_validate.py
@@ -1,5 +1,7 @@
import json
+from mock import patch
+
from appvalidator import validate_app, validate_packaged_app
from helper import safe
View
15 tests/test_webapp_resources.py
@@ -122,6 +122,7 @@ def setUp(self):
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 @@ def test_too_big(self, r_g):
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 @@ def test_just_right(self, r_g):
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):
Please sign in to comment.
Something went wrong with that request. Please try again.