Remove the client Mock object

It wasn't used by anything so that was easy.  Clean up the test as long as
we're here.
This commit is contained in:
Jean-Paul Calderone 2020-12-15 18:30:12 -05:00
parent c45290c55f
commit 2b1ea5c604
2 changed files with 31 additions and 12 deletions

View File

@ -25,7 +25,8 @@ def assert_soup_has_tag_with_attributes(testcase, soup, tag_name, attrs):
tags = soup.find_all(tag_name) tags = soup.find_all(tag_name)
for tag in tags: for tag in tags:
if all(v in tag.attrs.get(k, []) for k, v in attrs.items()): if all(v in tag.attrs.get(k, []) for k, v in attrs.items()):
return # we found every attr in this tag; done # we found every attr in this tag; done
return tag
testcase.fail( testcase.fail(
u"No <{}> tags contain attributes: {}".format(tag_name, attrs) u"No <{}> tags contain attributes: {}".format(tag_name, attrs)
) )

View File

@ -1,7 +1,13 @@
from mock import Mock
import time import time
from urllib import (
quote,
)
from bs4 import (
BeautifulSoup,
)
from twisted.trial import unittest from twisted.trial import unittest
from twisted.web.template import Tag from twisted.web.template import Tag
from twisted.web.test.requesthelper import DummyRequest from twisted.web.test.requesthelper import DummyRequest
@ -16,6 +22,9 @@ from ...util.connection_status import ConnectionStatus
from allmydata.web.root import URIHandler from allmydata.web.root import URIHandler
from allmydata.client import _Client from allmydata.client import _Client
from .common import (
assert_soup_has_tag_with_attributes,
)
from ..common_web import ( from ..common_web import (
render, render,
) )
@ -30,28 +39,37 @@ class RenderSlashUri(unittest.TestCase):
""" """
def setUp(self): def setUp(self):
self.client = Mock() self.client = object()
self.res = URIHandler(self.client) self.res = URIHandler(self.client)
def test_valid(self): def test_valid_query_redirect(self):
""" """
A valid capbility does not result in error A syntactically valid capability given in the ``uri`` query argument
results in a redirect.
""" """
query_args = {b"uri": [ cap = (
b"URI:CHK:nt2xxmrccp7sursd6yh2thhcky:" b"URI:CHK:nt2xxmrccp7sursd6yh2thhcky:"
b"mukesarwdjxiyqsjinbfiiro6q7kgmmekocxfjcngh23oxwyxtzq:2:5:5874882" b"mukesarwdjxiyqsjinbfiiro6q7kgmmekocxfjcngh23oxwyxtzq:2:5:5874882"
]} )
query_args = {b"uri": [cap]}
response_body = self.successResultOf( response_body = self.successResultOf(
render(self.res, query_args), render(self.res, query_args),
) )
self.assertNotEqual( soup = BeautifulSoup(response_body, 'html5lib')
response_body, tag = assert_soup_has_tag_with_attributes(
"Invalid capability", self,
soup,
u"meta",
{u"http-equiv": "refresh"},
)
self.assertIn(
quote(cap, safe=""),
tag.attrs.get(u"content"),
) )
def test_invalid(self): def test_invalid(self):
""" """
A (trivially) invalid capbility is an error A syntactically invalid capbility results in an error.
""" """
query_args = {b"uri": [b"not a capability"]} query_args = {b"uri": [b"not a capability"]}
response_body = self.successResultOf( response_body = self.successResultOf(