Ejemplo n.º 1
0
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())
Ejemplo n.º 2
0
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())
Ejemplo n.º 3
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=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_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(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)
Ejemplo n.º 4
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=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_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(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)