diff --git a/common.py b/common.py index 8a9c30a..bc8ff6c 100644 --- a/common.py +++ b/common.py @@ -93,7 +93,8 @@ DOMAINS = (PRIMARY_DOMAIN,) + OTHER_DOMAINS def not_5xx(resp): - return isinstance(resp, tuple) and resp[1] // 100 != 5 + return (isinstance(resp, tuple) and len(resp) > 1 and util.is_int(resp[1]) and + resp[1] // 100 != 5) def requests_get(url, **kwargs): diff --git a/tests/test_models.py b/tests/test_models.py index b977729..14f42c4 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -1,5 +1,6 @@ # coding=utf-8 """Unit tests for models.py.""" +from app import app from models import MagicKey, Response from . import testutil @@ -52,9 +53,10 @@ class ResponseTest(testutil.TestCase): self.assertEqual('abc__1 xyz__Z', resp.key.id()) def test_proxy_url(self): - resp = Response.get_or_create('abc', 'xyz') - self.assertIsNone(resp.proxy_url(self.handler)) + with app.test_request_context('/'): + resp = Response.get_or_create('abc', 'xyz') + self.assertIsNone(resp.proxy_url()) - resp.source_as2 = 'as2' - self.assertEqual('http://localhost/render?source=abc&target=xyz', - resp.proxy_url(self.handler)) + resp.source_as2 = 'as2' + self.assertEqual('http://localhost/render?source=abc&target=xyz', + resp.proxy_url()) diff --git a/tests/test_webfinger.py b/tests/test_webfinger.py index 56e5a6a..7787dc1 100644 --- a/tests/test_webfinger.py +++ b/tests/test_webfinger.py @@ -94,8 +94,7 @@ class WebfingerTest(testutil.TestCase): def test_host_meta_handler_xrds(self): got = client.get('/.well-known/host-meta.xrds') self.assertEqual(200, got.status_code) - self.assertEqual('application/xrds+xml; charset=utf-8', - got.headers['Content-Type']) + self.assertEqual('application/xrds+xml', got.headers['Content-Type']) body = got.get_data(as_text=True) self.assertTrue(body.startswith('', view_func=User.as_view('user')) app.add_url_rule('/.well-known/webfinger', view_func=Webfinger.as_view('webfinger')) +app.add_url_rule('/.well-known/host-meta', view_func=HostMeta.as_view('hostmeta')) +app.add_url_rule('/.well-known/host-meta.json', view_func=HostMeta.as_view('hostmeta-json'))