class TestSiteWithoutRootCap(TestWebSite): """Like TestWebSite but with the 'public' configuration.""" def setUp(self): # TODO: arrange so we don't need to pass as many bogus strings self._service = WebService( reactor=the_reactor, http_endpoint='tcp:0', ws_endpoint='tcp:0', root_cap=UNIQUE_PUBLIC_CAP, cap_table={UNIQUE_PUBLIC_CAP: SiteStateStub()}, title='test title') self._service.startService() self.url = str(self._service.get_url()) def test_expected_url(self): self.assertEqual(_make_cap_url(UNIQUE_PUBLIC_CAP), self._service.get_host_relative_url())
class TestSiteWithoutRootCap(TestWebSite): """Like TestWebSite but with the 'public' configuration.""" 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=UNIQUE_PUBLIC_CAP, read_only_dbs={}, writable_db=DatabaseModel(reactor, {}), cap_table={UNIQUE_PUBLIC_CAP: SiteStateStub()}, flowgraph_for_debug=gr.top_block(), title='test title') self._service.startService() self.url = str(self._service.get_url()) def test_expected_url(self): self.assertEqual('/' + UNIQUE_PUBLIC_CAP + '/', 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') self._service.startService() self.url = self._service.get_url() def test_expected_url(self): self.assertEqual('/', self._service.get_host_relative_url())
def setUp(self): # TODO: arrange so we don't need to pass as many bogus strings self._service = WebService( reactor=the_reactor, http_endpoint='tcp:0', ws_endpoint='tcp:0', root_cap=u'ROOT', cap_table={u'ROOT': SiteStateStub()}, title='test title') self._service.startService() self.url = str(self._service.get_url())
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=u'ROOT', read_only_dbs={}, writable_db=DatabaseModel(reactor, {}), cap_table={u'ROOT': SiteStateStub()}, flowgraph_for_debug=gr.top_block(), title='test title') self._service.startService() self.url = str(self._service.get_url())
def make_service(app): # TODO: Temporary glue while we refactor for multisession session = app.get_session() cap_table = CapTable(lambda bogus: bogus) if root_cap is None: cap_table.add(session, cap=UNIQUE_PUBLIC_CAP) root_cap_subst = UNIQUE_PUBLIC_CAP else: cap_table.add(session, cap=root_cap) root_cap_subst = root_cap from shinysdr.i.network.app import WebService return WebService( reactor=self.reactor, cap_table=cap_table.as_unenumerable_collection(), http_endpoint=http_endpoint, ws_endpoint=ws_endpoint, root_cap=root_cap_subst, title=title)
def make_service(app): # TODO: Temporary glue while we refactor for multisession session = app.get_session() cap_table = CapTable(lambda bogus: bogus) if root_cap is None: cap_table.add(session, cap=UNIQUE_PUBLIC_CAP) root_cap_subst = UNIQUE_PUBLIC_CAP else: cap_table.add(session, cap=root_cap) root_cap_subst = root_cap from shinysdr.i.network.app import WebService return WebService( reactor=self.reactor, cap_table=cap_table.as_unenumerable_collection(), flowgraph_for_debug=app.get_receive_flowgraph(), # TODO: Once we have the diagnostics or admin page however that turns out to work, this goes away read_only_dbs=self.databases._get_read_only_databases(), writable_db=self.databases._get_writable_database(), http_endpoint=http_endpoint, ws_endpoint=ws_endpoint, root_cap=root_cap_subst, title=title)
class TestWebSite(unittest.TestCase): # note: this test has a subclass 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') self._service.startService() self.url = self._service.get_url() def tearDown(self): return self._service.stopService() def test_expected_url(self): self.assertEqual('/ROOT/', self._service.get_host_relative_url()) def test_app_redirect(self): if 'ROOT' not in self.url: return # test does not apply 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_html(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'), ['text/html;charset=utf-8']) self.assertIn('</html>', data) return testutil.http_get(reactor, self.url + CAP_OBJECT_PATH_ELEMENT, accept='text/html').addCallback(callback) def test_resource_page_json(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 + CAP_OBJECT_PATH_ELEMENT, accept='application/json').addCallback(callback) def test_flowgraph_page(self): 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): # note: this test has a subclass 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=u'ROOT', read_only_dbs={}, writable_db=DatabaseModel(reactor, {}), cap_table={u'ROOT': SiteStateStub()}, flowgraph_for_debug=gr.top_block(), title='test title') self._service.startService() self.url = str(self._service.get_url()) def tearDown(self): return self._service.stopService() def test_expected_url(self): self.assertEqual('/ROOT/', self._service.get_host_relative_url()) def test_common_root(self): return assert_common(self, self.url) def test_common_client_example(self): return assert_common(self, urlparse.urljoin(self.url, '/client/main.js')) def test_common_object(self): return assert_common(self, urlparse.urljoin(self.url, CAP_OBJECT_PATH_ELEMENT)) def test_common_ephemeris(self): return assert_common(self, urlparse.urljoin(self.url, 'ephemeris')) def test_app_redirect(self): if 'ROOT' not in self.url: return # test does not apply 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_html(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'), ['text/html;charset=utf-8']) self.assertIn('</html>', data) return testutil.http_get(reactor, self.url + CAP_OBJECT_PATH_ELEMENT, accept='text/html').addCallback(callback) def test_resource_page_json(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 + CAP_OBJECT_PATH_ELEMENT, accept='application/json').addCallback(callback) def test_flowgraph_page(self): 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): # note: this test has a subclass def setUp(self): # TODO: arrange so we don't need to pass as many bogus strings self._service = WebService( reactor=the_reactor, http_endpoint='tcp:0', ws_endpoint='tcp:0', root_cap=u'ROOT', cap_table={u'ROOT': SiteStateStub()}, title='test title') self._service.startService() self.url = str(self._service.get_url()) def tearDown(self): return self._service.stopService() def test_expected_url(self): self.assertEqual('/ROOT/', self._service.get_host_relative_url()) def test_common_root(self): return testutil.assert_http_resource_properties(self, self.url) def test_common_client_example(self): return testutil.assert_http_resource_properties(self, urlparse.urljoin(self.url, '/client/main.js')) def test_common_object(self): return testutil.assert_http_resource_properties(self, urlparse.urljoin(self.url, CAP_OBJECT_PATH_ELEMENT)) def test_common_ephemeris(self): return testutil.assert_http_resource_properties(self, urlparse.urljoin(self.url, 'ephemeris')) @defer.inlineCallbacks def test_app_redirect(self): if 'ROOT' not in self.url: return # test does not apply url_without_slash = self.url[:-1] response, _data = yield testutil.http_get(the_reactor, url_without_slash) self.assertEqual(response.code, http.MOVED_PERMANENTLY) self.assertEqual(self.url, urlparse.urljoin(url_without_slash, 'ONLYONE'.join(response.headers.getRawHeaders('Location')))) @defer.inlineCallbacks def test_index_page(self): response, data = yield testutil.http_get(the_reactor, self.url) self.assertEqual(response.code, http.OK) self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['text/html;charset=utf-8']) self.assertIn(b'</html>', data) # complete self.assertIn(b'<title>test title</title>', data) # TODO: Probably not here, add an end-to-end test for page title _default_. @defer.inlineCallbacks def test_resource_page_html(self): # TODO: This ought to be a separate test of block-resources response, data = yield testutil.http_get(the_reactor, self.url + CAP_OBJECT_PATH_ELEMENT, accept='text/html') self.assertEqual(response.code, http.OK) self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['text/html;charset=utf-8']) self.assertIn(b'</html>', data) @defer.inlineCallbacks def test_resource_page_json(self): # TODO: This ought to be a separate test of block-resources response, data = yield testutil.http_get(the_reactor, self.url + CAP_OBJECT_PATH_ELEMENT, accept='application/json') 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': {}, }) @defer.inlineCallbacks def test_flowgraph_page(self): response, _data = yield testutil.http_get(the_reactor, self.url + b'flow-graph') self.assertEqual(response.code, http.OK) self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['image/png']) # TODO ... @defer.inlineCallbacks def test_manifest(self): response, data = yield testutil.http_get(the_reactor, urlparse.urljoin(self.url, b'/client/web-app-manifest.json')) self.assertEqual(response.code, http.OK) self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['application/manifest+json']) manifest = json.loads(data) self.assertEqual(manifest['name'], 'test title') @defer.inlineCallbacks def test_plugin_index(self): response, data = yield testutil.http_get(the_reactor, urlparse.urljoin(self.url, b'/client/plugin-index.json')) self.assertEqual(response.code, http.OK) self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['application/json']) index = json.loads(data) self.assertIn('css', index) self.assertIn('js', index) self.assertIn('modes', index)