mirror of
https://github.com/GNS3/gns3-server.git
synced 2026-11-03 05:51:15 +02:00
19 files changed
+72
-97
No files matched your search
@@ -85,26 +85,16 @@ class Query:
|
||||
- example if True the session is included inside documentation
|
||||
- raw do not JSON encode the query
|
||||
"""
|
||||
return self._loop.run_until_complete(asyncio.async(self._async_fetch(method, path, body=body, **kwargs)))
|
||||
|
||||
@asyncio.coroutine
|
||||
def _async_fetch(self, method, path, body=None, **kwargs):
|
||||
if body is not None and not kwargs.get("raw", False):
|
||||
body = json.dumps(body)
|
||||
|
||||
@asyncio.coroutine
|
||||
def go_request(future):
|
||||
response = yield from aiohttp.request(method, self.get_url(path), data=body)
|
||||
future.set_result(response)
|
||||
future = asyncio.Future()
|
||||
asyncio.async(go_request(future))
|
||||
self._loop.run_until_complete(future)
|
||||
response = future.result()
|
||||
|
||||
@asyncio.coroutine
|
||||
def go_read(future, response):
|
||||
response = yield from response.read()
|
||||
future.set_result(response)
|
||||
future = asyncio.Future()
|
||||
asyncio.async(go_read(future, response))
|
||||
self._loop.run_until_complete(future)
|
||||
response.body = future.result()
|
||||
connector = aiohttp.TCPConnector()
|
||||
response = yield from aiohttp.request(method, self.get_url(path), data=body, loop=self._loop, connector=connector)
|
||||
response.body = yield from response.read()
|
||||
x_route = response.headers.get('X-Route', None)
|
||||
if x_route is not None:
|
||||
response.route = x_route.replace("/v{}".format(self._api_version), "")
|
||||
|
||||
@@ -129,19 +129,18 @@ def test_load_project(http_controller, project, config):
|
||||
assert response.json["project_id"] == project.id
|
||||
|
||||
|
||||
def test_notification(http_controller, project, controller, loop):
|
||||
def test_notification(http_controller, project, controller, loop, async_run):
|
||||
@asyncio.coroutine
|
||||
def go(future):
|
||||
response = yield from aiohttp.request("GET", http_controller.get_url("/projects/{project_id}/notifications".format(project_id=project.id)))
|
||||
def go():
|
||||
connector = aiohttp.TCPConnector()
|
||||
response = yield from aiohttp.request("GET", http_controller.get_url("/projects/{project_id}/notifications".format(project_id=project.id)), connector=connector)
|
||||
response.body = yield from response.content.read(200)
|
||||
controller.notification.emit("node.created", {"a": "b"})
|
||||
response.body += yield from response.content.read(50)
|
||||
response.body += yield from response.content.readany()
|
||||
response.close()
|
||||
future.set_result(response)
|
||||
return response
|
||||
|
||||
future = asyncio.Future()
|
||||
asyncio.async(go(future))
|
||||
response = loop.run_until_complete(future)
|
||||
response = async_run(asyncio.async(go()))
|
||||
assert response.status == 200
|
||||
assert b'"action": "ping"' in response.body
|
||||
assert b'"cpu_usage_percent"' in response.body
|
||||
|
||||
@@ -35,7 +35,6 @@ def test_symbols(http_controller):
|
||||
def test_get(http_controller):
|
||||
response = http_controller.get('/symbols/' + urllib.parse.quote(':/symbols/firewall.svg') + '/raw')
|
||||
assert response.status == 200
|
||||
assert response.headers['CONTENT-LENGTH'] == '9381'
|
||||
assert response.headers['CONTENT-TYPE'] == 'image/svg+xml'
|
||||
assert '</svg>' in response.html
|
||||
|
||||
|
||||
Reference in new issue
Block a user