2016-08-03 20:46:12 -04:00
|
|
|
|
2019-08-14 19:45:16 +01:00
|
|
|
import re
|
|
|
|
|
2016-08-03 20:46:12 -04:00
|
|
|
unknown_rwcap = u"lafs://from_the_future_rw_\u263A".encode('utf-8')
|
|
|
|
unknown_rocap = u"ro.lafs://readonly_from_the_future_ro_\u263A".encode('utf-8')
|
|
|
|
unknown_immcap = u"imm.lafs://immutable_from_the_future_imm_\u263A".encode('utf-8')
|
|
|
|
|
|
|
|
FAVICON_MARKUP = '<link href="/icon.png" rel="shortcut icon" />'
|
2019-08-14 19:45:16 +01:00
|
|
|
|
2019-08-16 16:51:57 +01:00
|
|
|
|
2019-08-14 19:45:16 +01:00
|
|
|
def assert_soup_has_favicon(testcase, soup):
|
2019-08-16 17:36:48 +01:00
|
|
|
"""
|
|
|
|
Using a ``TestCase`` object ``testcase``, assert that the passed in
|
|
|
|
``BeautifulSoup`` object ``soup`` contains the tahoe favicon link.
|
|
|
|
"""
|
2019-08-16 16:51:57 +01:00
|
|
|
links = soup.find_all(u'link', rel=u'shortcut icon')
|
2019-08-14 19:45:16 +01:00
|
|
|
testcase.assert_(
|
2019-08-16 16:51:57 +01:00
|
|
|
any(t[u'href'] == u'/icon.png' for t in links), soup)
|
|
|
|
|
2019-08-14 19:45:16 +01:00
|
|
|
|
2019-12-22 18:38:22 -07:00
|
|
|
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)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2019-08-14 19:45:16 +01:00
|
|
|
def assert_soup_has_text(testcase, soup, text):
|
2019-08-16 17:36:48 +01:00
|
|
|
"""
|
|
|
|
Using a ``TestCase`` object ``testcase``, assert that the passed in
|
|
|
|
``BeautifulSoup`` object ``soup`` contains the passed in ``text`` anywhere
|
|
|
|
as a text node.
|
|
|
|
"""
|
2019-08-14 19:45:16 +01:00
|
|
|
testcase.assert_(
|
|
|
|
soup.find_all(string=re.compile(re.escape(text))),
|
|
|
|
soup)
|