コード例 #1
0
ファイル: test_web.py プロジェクト: langxj/shinysdr
 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)
コード例 #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)
コード例 #3
0
ファイル: test_app.py プロジェクト: thejeshgn/shinysdr
 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)
コード例 #4
0
ファイル: test_app.py プロジェクト: tashby/shinysdr
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)
コード例 #5
0
ファイル: test_app.py プロジェクト: tashby/shinysdr
 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)
コード例 #6
0
ファイル: test_app.py プロジェクト: thefinn93/shinysdr
 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)
コード例 #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))
コード例 #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)
コード例 #9
0
ファイル: test_app.py プロジェクト: mikekiwa/shinysdr
 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)
コード例 #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)
コード例 #11
0
ファイル: test_web.py プロジェクト: timothylackhouse/shinysdr
 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)
コード例 #12
0
ファイル: test_db.py プロジェクト: thefinn93/shinysdr
 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)
コード例 #13
0
ファイル: test_app.py プロジェクト: thefinn93/shinysdr
 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)
コード例 #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)
コード例 #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)
コード例 #16
0
ファイル: test_app.py プロジェクト: thefinn93/shinysdr
 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)
コード例 #17
0
ファイル: test_app.py プロジェクト: misterdevil/shinysdr
    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)
コード例 #18
0
ファイル: test_app.py プロジェクト: thejeshgn/shinysdr
 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')
コード例 #19
0
ファイル: test_app.py プロジェクト: mikekiwa/shinysdr
 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': {},
     })
コード例 #20
0
ファイル: test_db.py プロジェクト: thefinn93/shinysdr
 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)
コード例 #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)
コード例 #22
0
ファイル: test_web.py プロジェクト: timothylackhouse/shinysdr
 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)
コード例 #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)
コード例 #24
0
ファイル: test_web.py プロジェクト: timothylackhouse/shinysdr
 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)
コード例 #25
0
ファイル: test_app.py プロジェクト: bitglue/shinysdr
 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)
コード例 #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)
コード例 #27
0
ファイル: test_app.py プロジェクト: mikekiwa/shinysdr
 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'))))
コード例 #28
0
ファイル: test_db.py プロジェクト: thefinn93/shinysdr
 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)
コード例 #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)
コード例 #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))
コード例 #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)
コード例 #32
0
ファイル: test_web.py プロジェクト: timothylackhouse/shinysdr
 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)
コード例 #33
0
ファイル: test_app.py プロジェクト: mikekiwa/shinysdr
 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'])
コード例 #34
0
ファイル: test_db.py プロジェクト: bitglue/shinysdr
 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)
コード例 #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))
コード例 #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])
コード例 #37
0
ファイル: test_app.py プロジェクト: thefinn93/shinysdr
 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)