diff --git a/appvalidator/testcases/webappbase.py b/appvalidator/testcases/webappbase.py index 7b16014..deea735 100644 --- a/appvalidator/testcases/webappbase.py +++ b/appvalidator/testcases/webappbase.py @@ -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 diff --git a/tests/helper.py b/tests/helper.py index 5b0eb3c..7e287f1 100644 --- a/tests/helper.py +++ b/tests/helper.py @@ -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, ""] diff --git a/tests/test_validate.py b/tests/test_validate.py index 5ddf12a..27f4ad0 100644 --- a/tests/test_validate.py +++ b/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 diff --git a/tests/test_webapp_resources.py b/tests/test_webapp_resources.py index 274c3e5..552b06a 100644 --- a/tests/test_webapp_resources.py +++ b/tests/test_webapp_resources.py @@ -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):