This commit is contained in:
meejah 2019-12-22 18:38:22 -07:00
parent d5ef65d326
commit c489c61404
2 changed files with 21 additions and 14 deletions

View File

@ -18,6 +18,21 @@ def assert_soup_has_favicon(testcase, soup):
any(t[u'href'] == u'/icon.png' for t in links), soup)
def assert_soup_has_tag_with_attributes(testcase, soup, tag_name, attrs):
"""
Using a ``TestCase`` object ``testcase``, assert that the passed
in ``BeatufulSoup`` object ``soup`` contains a tag ``tag_name``
(unicode) which has all the attributes in ``attrs`` (dict).
"""
tags = soup.find_all(tag_name)
for tag in tags:
if all(tag.attrs[k] == v for k, v in attrs.items()):
return # we found every attr in this tag; done
testcase.fail(
"No <{}> tags contain attributes: {}".format(tag_name, attrs)
)
def assert_soup_has_text(testcase, soup, text):
"""
Using a ``TestCase`` object ``testcase``, assert that the passed in

View File

@ -54,6 +54,7 @@ from ..common import (
from .common import (
assert_soup_has_favicon,
assert_soup_has_text,
assert_soup_has_tag_with_attributes,
)
from allmydata.interfaces import IMutableFileNode, SDMF_VERSION, MDMF_VERSION
from allmydata.mutable import servermap, publish, retrieve
@ -4185,22 +4186,13 @@ class Web(WebMixin, WebErrorMixin, testutil.StallMixin, testutil.ReallyEqualMixi
)
soup = BeautifulSoup(data, 'html5lib')
assert_soup_has_favicon(self, soup)
inputs = soup.find_all(u"input")
want = [
assert_soup_has_tag_with_attributes(
self, soup, u"input",
{u"name": u"when_done", u"value": u".", u"type": u"hidden"},
)
assert_soup_has_tag_with_attributes(
self, soup, u"input",
{u"readonly": u"true", u"name": u"from_name", u"value": u"bar.txt", u"type": u"text"},
]
found = []
for inp in inputs:
print(inp)
print(dir(inp))
print(inp.attrs)
if inp.attrs in want:
found.append(inp.attrs)
self.assertEqual(
len(found),
len(want),
"Wanted <input> tags: {} but only found: {}".format(want, found),
)
def log(self, res, msg):