Test more markup rendered by DownloadStatusElement

This commit is contained in:
Sajith Sasidharan 2020-07-07 21:56:35 -04:00
parent 0db56f99cf
commit d6ea30b935

View File

@ -1,3 +1,4 @@
# Tests for code in allmydata.web.status
from bs4 import BeautifulSoup
from twisted.web.template import flattenString
@ -19,11 +20,13 @@ from ..common import TrialTestCase
@implementer(IDownloadResults)
class FakeDownloadResults(object):
file_size = 0
servers_used = 0
server_problems = {"s-1": "unknown problem"}
servermap = dict()
timings = dict()
def __init__(self, file_size):
self.file_size = file_size
self.servers_used = ["s-1", "s-2", "s-3"]
self.server_problems = {"s-1": "unknown problem"}
self.servermap = {"s-1": [1,2,3], "s-2": [2,3,4], "s-3": [0,1,3]}
self.timings = { "fetch_per_server": {"s-1": [1,2,3], "s-2": [2], "s-3": [3]}}
@implementer(IDownloadStatus)
@ -62,10 +65,10 @@ class FakeDownloadStatus(object):
return 0
def get_results(self):
return FakeDownloadResults()
return FakeDownloadResults(self.size)
class StatusTests(TrialTestCase):
# Tests for code in allmydata.web.status.DownloadStatusElement
class DownloadStatusElementTests(TrialTestCase):
def _render_download_status_element(self):
elem = DownloadStatusElement(FakeDownloadStatus("si-1", 123))
@ -76,7 +79,23 @@ class StatusTests(TrialTestCase):
result = self._render_download_status_element()
soup = BeautifulSoup(result, 'html5lib')
assert_soup_has_text(self, soup, u'Tahoe-LAFS - File Download Status')
assert_soup_has_text(self, soup, u"Tahoe-LAFS - File Download Status")
assert_soup_has_favicon(self, soup)
assert_soup_has_tag_with_content(self, soup, u'li', u'[omwtc]: unknown problem')
assert_soup_has_tag_with_content(self, soup, u"li", u"File Size: 123 bytes")
assert_soup_has_tag_with_content(self, soup, u"li", u"Progress: 0.0%")
assert_soup_has_tag_with_content(self, soup, u"li", u"Servers Used: [omwtc], [omwte], [omwtg]")
assert_soup_has_tag_with_content(self, soup, u"li", u"Server Problems:")
assert_soup_has_tag_with_content(self, soup, u"li", u"[omwtc]: unknown problem")
assert_soup_has_tag_with_content(self, soup, u"li", u"Servermap:")
assert_soup_has_tag_with_content(self, soup, u"li", u"[omwtc] has shares: #1,#2,#3")
assert_soup_has_tag_with_content(self, soup, u"li", u"[omwte] has shares: #2,#3,#4")
assert_soup_has_tag_with_content(self, soup, u"li", u"[omwtg] has shares: #0,#1,#3")
assert_soup_has_tag_with_content(self, soup, u"li", u"Per-Server Segment Fetch Response Times:")
assert_soup_has_tag_with_content(self, soup, u"li", u"[omwtc]: 1.00s, 2.00s, 3.00s")
assert_soup_has_tag_with_content(self, soup, u"li", u"[omwte]: 2.00s")
assert_soup_has_tag_with_content(self, soup, u"li", u"[omwtg]: 3.00s")