Esempio n. 1
0
 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:3333',
                                root_cap=u'ROOT',
                                cap_table={u'ROOT': SiteStateStub()},
                                title='test title')
     self._service.startService()
     self.url = defaultstr(self._service.get_url())
Esempio n. 2
0
 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())
Esempio n. 3
0
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:3333',
            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())
Esempio n. 4
0
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:3333',
            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())
Esempio n. 5
0
 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:3333',
         root_cap=u'ROOT',
         cap_table={u'ROOT': SiteStateStub()},
         title='test title')
     self._service.startService()
     self.url = defaultstr(self._service.get_url())
Esempio n. 6
0
        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.webapp 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)
Esempio n. 7
0
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:3333',
                                   root_cap=u'ROOT',
                                   cap_table={u'ROOT': SiteStateStub()},
                                   title='test title')
        self._service.startService()
        self.url = defaultstr(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_http_resource_properties(self, self.url)

    def test_common_client_example(self):
        return assert_http_resource_properties(
            self, urljoin(self.url, '/client/main.js'))

    def test_common_object(self):
        return assert_http_resource_properties(
            self, urljoin(self.url, CAP_OBJECT_PATH_ELEMENT))

    def test_common_ephemeris(self):
        return assert_http_resource_properties(self,
                                               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 http_get(the_reactor, url_without_slash)
        self.assertEqual(response.code, http.MOVED_PERMANENTLY)
        self.assertEqual(
            self.url,
            urljoin(url_without_slash, 'ONLYONE'.join(
                response.headers.getRawHeaders('Location'))))

    @defer.inlineCallbacks
    def test_index_page(self):
        response, data = yield 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 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 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 http_get(the_reactor,
                                         self.url + defaultstr('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 http_get(
            the_reactor,
            urljoin(self.url, defaultstr('/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_client_configuration(self):
        response, data = yield http_get(
            the_reactor,
            urljoin(self.url, defaultstr('/client/client-configuration')))
        self.assertEqual(response.code, http.OK)
        self.assertEqual(response.headers.getRawHeaders('Content-Type'),
                         ['application/json'])
        configuration = json.loads(data)
        plugin_index = configuration['plugins']
        self.assertIn('css', plugin_index)
        self.assertIn('js', plugin_index)
        self.assertIn('modes', plugin_index)
        self.assertEqual(
            'ws://localhost:3333/shared_test_objects/' +
            CAP_OBJECT_PATH_ELEMENT, configuration['shared_test_objects_url'])
Esempio n. 8
0
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:3333',
            root_cap=u'ROOT',
            cap_table={u'ROOT': SiteStateStub()},
            title='test title')
        self._service.startService()
        self.url = defaultstr(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_http_resource_properties(self, self.url)
    
    def test_common_client_example(self):
        return assert_http_resource_properties(self, urljoin(self.url, '/client/main.js'))
    
    def test_common_object(self):
        return assert_http_resource_properties(self, urljoin(self.url, CAP_OBJECT_PATH_ELEMENT))
    
    def test_common_ephemeris(self):
        return assert_http_resource_properties(self, 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 http_get(the_reactor, url_without_slash)
        self.assertEqual(response.code, http.MOVED_PERMANENTLY)
        self.assertEqual(self.url,
            urljoin(url_without_slash,
                'ONLYONE'.join(response.headers.getRawHeaders('Location'))))
    
    @defer.inlineCallbacks
    def test_index_page(self):
        response, data = yield 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 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 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 http_get(the_reactor, self.url + defaultstr('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 http_get(the_reactor, urljoin(self.url, defaultstr('/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_client_configuration(self):
        response, data = yield http_get(the_reactor, urljoin(self.url, defaultstr('/client/client-configuration')))
        self.assertEqual(response.code, http.OK)
        self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['application/json'])
        configuration = json.loads(data)
        plugin_index = configuration['plugins']
        self.assertIn('css', plugin_index)
        self.assertIn('js', plugin_index)
        self.assertIn('modes', plugin_index)
        self.assertEqual(
            'ws://localhost:3333/shared_test_objects/' + CAP_OBJECT_PATH_ELEMENT,
            configuration['shared_test_objects_url'])