Esempio n. 1
0
 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)
Esempio n. 2
0
 def test_index_response(self):
     response, data = yield testutil.http_get(reactor, self.__url('/'))
     self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['text/html;charset=utf-8'])
     # TODO: Actually parse/check-that-parses the document
     self.assertSubstring(textwrap.dedent('''\
         <li><a href="foo%26bar/">foo&amp;bar</a></li>
     '''), data)
Esempio n. 3
0
 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)
Esempio n. 4
0
def assert_common(self, url):
    """Common properties all HTTP resources should have."""
    def callback((response, data)):
        # If this fails, we probably made a mistake
        self.assertNotEqual(response.code, http.NOT_FOUND)
        
        self.assertEqual(
            [';'.join([
                "default-src 'self' 'unsafe-inline'",
                "connect-src 'self' ws://*:* wss://*:*",
                "img-src 'self' data: blob:",
                "object-src 'none'",
                "base-uri 'self'",
                "block-all-mixed-content",
            ])],
            response.headers.getRawHeaders('Content-Security-Policy'))
        self.assertEqual(['no-referrer'], response.headers.getRawHeaders('Referrer-Policy'))
        self.assertEqual(['nosniff'], response.headers.getRawHeaders('X-Content-Type-Options'))
        
        content_type = response.headers.getRawHeaders('Content-Type')
        if data.startswith('{'):
            self.assertEqual(['application/json'], content_type)
        elif data.startswith('<'):
            self.assertEqual(['text/html'], content_type)
        else:
            raise Exception('Don\'t know what content type to expect', data[0], content_type)
    
    return testutil.http_get(reactor, self.url).addCallback(callback)
Esempio n. 5
0
 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)
Esempio n. 6
0
 def test_manifest(self):
     def callback((response, data)):
         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')
     return testutil.http_get(the_reactor, urlparse.urljoin(self.url, b'/client/web-app-manifest.json')).addCallback(callback)
Esempio n. 7
0
 def test_leaf_cell_put(self):
     yield http_request(the_reactor, self.__url('/leaf_cell'),
         method='PUT',
         body='[3, 4, 5]')
     
     response, data = yield http_get(the_reactor, self.__url('/leaf_cell'))
     self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['application/json'])
     self.assertEqual([3, 4, 5], json.loads(data))
Esempio n. 8
0
 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)
Esempio n. 9
0
 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)
Esempio n. 10
0
    def test_leaf_cell_get(self):
        def callback((response, data)):
            self.assertEqual(response.headers.getRawHeaders('Content-Type'),
                             ['application/json'])
            self.assertEqual([1, 2, 3], json.loads(data))

        return http_get(the_reactor,
                        self.__url('/leaf_cell')).addCallback(callback)
Esempio n. 11
0
 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)
Esempio n. 12
0
 def test_index_response(self):
     def callback((response, data)):
         self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['text/html'])
         # TODO: Actually parse/check-that-parses the document
         self.assertSubstring(textwrap.dedent('''\
             <li><a href="foo%26bar/">foo&amp;bar</a></li>
         '''), data)
     return testutil.http_get(reactor, self.__url('/')).addCallback(callback)
Esempio n. 13
0
 def test_plugin_index(self):
     def callback((response, data)):
         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)
     return testutil.http_get(the_reactor, urlparse.urljoin(self.url, b'/client/plugin-index.json')).addCallback(callback)
Esempio n. 14
0
        def put_callback(_):
            def get_callback((response, data)):
                self.assertEqual(
                    response.headers.getRawHeaders('Content-Type'),
                    ['application/json'])
                self.assertEqual([3, 4, 5], json.loads(data))

            return http_get(the_reactor,
                            self.__url('/leaf_cell')).addCallback(get_callback)
Esempio n. 15
0
    def test_record_response(self):
        def callback((response, data)):
            self.assertEqual(response.headers.getRawHeaders('Content-Type'),
                             ['application/json'])
            j = json.loads(data)
            self.assertEqual(j, self.test_records[1])

        return testutil.http_get(reactor,
                                 self.__url('/1')).addCallback(callback)
Esempio n. 16
0
 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(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_.
     
     return testutil.http_get(the_reactor, self.url).addCallback(callback)
Esempio n. 17
0
    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)
Esempio n. 18
0
 def test_manifest(self):
     response, data = yield testutil.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')
Esempio n. 19
0
 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': {},
     })
Esempio n. 20
0
 def proceed((response, data)):
     if response.code >= 300:
         print data
     self.assertEqual(response.code, http.NO_CONTENT)
     
     def check((read_response, read_data)):
         j = json.loads(read_data)
         self.assertEqual(j[u'records'], modified)
     
     return testutil.http_get(reactor, self.__url('/')).addCallback(check)
Esempio n. 21
0
 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)
Esempio n. 22
0
 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)
Esempio n. 23
0
 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)
Esempio n. 24
0
 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)
Esempio n. 25
0
 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)
Esempio n. 26
0
        def proceed((response, data)):
            if response.code >= 300:
                print data
            self.assertEqual(response.code, http.NO_CONTENT)

            def check((read_response, read_data)):
                j = json.loads(read_data)
                self.assertEqual(j[u'records'], modified)

            return testutil.http_get(reactor,
                                     self.__url('/')).addCallback(check)
Esempio n. 27
0
 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'))))
Esempio n. 28
0
 def proceed((response, data)):
     if response.code >= 300:
         print data
     self.assertEqual(response.code, http.CREATED)
     url = 'ONLYONE'.join(response.headers.getRawHeaders('Location'))
     self.assertEqual(url, self.__url('/3'))  # URL of new entry
     
     def check((read_response, read_data)):
         j = json.loads(read_data)
         self.assertEqual(j[u'records'][u'3'], db.normalize_record(new_record))
     
     return testutil.http_get(reactor, self.__url('/')).addCallback(check)
Esempio n. 29
0
        def proceed((response, data)):
            if response.code >= 300:
                print data
            self.assertEqual(response.code, http.CREATED)
            url = 'ONLYONE'.join(response.headers.getRawHeaders('Location'))
            self.assertEqual(url, self.__url('/3'))  # URL of new entry

            def check((read_response, read_data)):
                j = json.loads(read_data)
                self.assertEqual(j[u'records'][u'3'],
                                 db.normalize_record(new_record))

            return testutil.http_get(reactor,
                                     self.__url('/')).addCallback(check)
Esempio n. 30
0
    def test_create(self):
        new_record = {
            u'type': u'channel',
            u'lowerFreq': 20e6,
            u'upperFreq': 20e6,
        }

        response, data = yield testutil.http_post_json(reactor, self.__url('/'), {
            'new': new_record
        })
        if response.code >= 300:
            print(data)
        self.assertEqual(response.code, http.CREATED)
        url = 'ONLYONE'.join(response.headers.getRawHeaders('Location'))
        self.assertEqual(url, self.__url('/3'))  # URL of new entry
        
        _read_response, read_data = yield testutil.http_get(reactor, self.__url('/'))
        j = json.loads(read_data)
        self.assertEqual(j[u'records'][u'3'], db.normalize_record(new_record))
Esempio n. 31
0
    def test_update_good(self):
        new_data = {
            u'type': u'channel',
            u'lowerFreq': 20e6,
            u'upperFreq': 20e6,
            u'label': u'modified',
        }
        index = u'1'
        modified = dict(self.response_json[u'records'])
        modified[index] = db.normalize_record(new_data)

        response, data = yield testutil.http_post_json(reactor, self.__url('/' + str(index)), {
            'old': self.response_json[u'records'][index],
            'new': new_data
        })
        if response.code >= 300:
            print(data)
        self.assertEqual(response.code, http.NO_CONTENT)
        
        _read_response, read_data = yield testutil.http_get(reactor, self.__url('/'))
        j = json.loads(read_data)
        self.assertEqual(j[u'records'], modified)
Esempio n. 32
0
 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)
         # ...
     return testutil.http_get(reactor, self.url + 'flow-graph').addCallback(callback)
Esempio n. 33
0
 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'])
Esempio n. 34
0
 def test_record_response(self):
     def callback((response, data)):
         self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['application/json'])
         j = json.loads(data)
         self.assertEqual(j, self.test_records[1])
     return testutil.http_get(reactor, self.__url('/1')).addCallback(callback)
Esempio n. 35
0
 def test_leaf_cell_get(self):
     response, data = yield http_get(the_reactor, self.__url('/leaf_cell'))
     self.assertEqual(response.headers.getRawHeaders('Content-Type'), ['application/json'])
     self.assertEqual([1, 2, 3], json.loads(data))
Esempio n. 36
0
 def test_record_response(self):
     response, data = yield testutil.http_get(reactor, self.__url('/1'))
     self.assertEqual(response.headers.getRawHeaders('Content-Type'),
                      ['application/json'])
     j = json.loads(data)
     self.assertEqual(j, self.test_records[1])
Esempio n. 37
0
 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(the_reactor, self.url + b'flow-graph').addCallback(callback)