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)
def test_index_response(self): response, data = yield 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&bar</a></li> '''), data)
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))
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)
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')
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': {}, })
def test_plugin_index(self): response, data = yield http_get( the_reactor, urljoin(self.url, defaultstr('/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)
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'))))
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'])
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'))))
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'])
def test_create(self): new_record = { u'type': u'channel', u'lowerFreq': 20e6, u'upperFreq': 20e6, } response, data = yield 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 http_get(reactor, self.__url('/')) j = json.loads(read_data) self.assertEqual(j[u'records'][u'3'], db.normalize_record(new_record))
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 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 http_get(reactor, self.__url('/')) j = json.loads(read_data) self.assertEqual(j[u'records'], modified)
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'])
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))
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')
def test_record_response(self): response, data = yield 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])