class TestWebSite(unittest.TestCase): def setUp(self): # TODO: arrange so we don't need to pass as many bogus strings self.__service = WebService( reactor=reactor, http_endpoint='tcp:0', ws_endpoint='tcp:0', root_cap='ROOT', read_only_dbs={}, writable_db=DatabaseModel(reactor, []), root_object=SiteStateStub(), flowgraph_for_debug=gr.top_block(), title='test title', note_dirty=_noop) self.__service.startService() self.url = self.__service.get_url() def tearDown(self): return self.__service.stopService() def test_app_redirect(self): url_without_slash = self.url[:-1] def callback((response, data)): self.assertEqual(response.code, http.MOVED_PERMANENTLY) self.assertEqual(self.url, urlparse.urljoin(url_without_slash, 'ONLYONE'.join(response.headers.getRawHeaders('Location')))) return testutil.http_get(reactor, url_without_slash).addCallback(callback) def test_index_page(self): def callback((response, data)): self.assertEqual(response.code, http.OK) self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['text/html']) self.assertIn('</html>', data) # complete self.assertIn('<title>test title</title>', data) # TODO: Probably not here, add an end-to-end test for page title _default_. return testutil.http_get(reactor, self.url).addCallback(callback) def test_resource_page(self): # TODO: This ought to be a separate test of block-resources def callback((response, data)): self.assertEqual(response.code, http.OK) self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['application/json']) description_json = json.loads(data) self.assertEqual(description_json, { u'kind': u'block', u'children': {}, }) return testutil.http_get(reactor, self.url + 'radio', accept='application/json').addCallback(callback) def test_flowgraph_page(self): # TODO: This ought to be a separate test of block-resources def callback((response, data)): self.assertEqual(response.code, http.OK) self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['image/png']) # TODO ... return testutil.http_get(reactor, self.url + 'flow-graph').addCallback(callback)
class TestWebSite(unittest.TestCase): def setUp(self): # TODO: arrange so we don't need to pass as many bogus strings self.__service = WebService( reactor=reactor, http_endpoint='tcp:0', ws_endpoint='tcp:0', root_cap='ROOT', read_only_dbs={}, writable_db=DatabaseModel(reactor, []), top=SiteStateStub(), title='test title', note_dirty=_noop) self.__service.startService() self.url = self.__service.get_url() def tearDown(self): return self.__service.stopService() def test_app_redirect(self): url_without_slash = self.url[:-1] def callback((response, data)): self.assertEqual(response.code, http.MOVED_PERMANENTLY) self.assertEqual(self.url, urlparse.urljoin(url_without_slash, 'ONLYONE'.join(response.headers.getRawHeaders('Location')))) return testutil.http_get(reactor, url_without_slash).addCallback(callback) def test_index_page(self): def callback((response, data)): self.assertEqual(response.code, http.OK) self.assertIn('</html>', data) # complete self.assertIn('<title>test title</title>', data) # TODO: Probably not here, add an end-to-end test for page title _default_. return testutil.http_get(reactor, self.url).addCallback(callback) def test_resource_page(self): # TODO: This ought to be a separate test of block-resources def callback((response, data)): self.assertEqual(response.code, http.OK) description_json = json.loads(data) self.assertEqual(description_json, { u'kind': u'block', u'children': {}, }) return testutil.http_get(reactor, self.url + 'radio', accept='application/json').addCallback(callback)
class TestSiteWithoutRootCap(TestWebSite): """Like TestWebSite but with root_cap set to None.""" def setUp(self): # TODO: arrange so we don't need to pass as many bogus strings self._service = WebService(reactor=reactor, http_endpoint='tcp:0', ws_endpoint='tcp:0', root_cap=None, read_only_dbs={}, writable_db=DatabaseModel(reactor, []), root_object=SiteStateStub(), flowgraph_for_debug=gr.top_block(), title='test title', note_dirty=_noop) self._service.startService() self.url = self._service.get_url() def test_expected_url(self): self.assertEqual('/', self._service.get_host_relative_url())
class TestSiteWithoutRootCap(TestWebSite): """Like TestWebSite but with root_cap set to None.""" def setUp(self): # TODO: arrange so we don't need to pass as many bogus strings self._service = WebService( reactor=reactor, http_endpoint='tcp:0', ws_endpoint='tcp:0', root_cap=None, read_only_dbs={}, writable_db=DatabaseModel(reactor, {}), root_object=SiteStateStub(), flowgraph_for_debug=gr.top_block(), title='test title', note_dirty=_noop) self._service.startService() self.url = self._service.get_url() def test_expected_url(self): self.assertEqual('/', self._service.get_host_relative_url())