Skip to content
Snippets Groups Projects
Commit 594fed92 authored by Vincent Texier's avatar Vincent Texier
Browse files

[fix] fix bug in API.reverse_url

Cover with tests
parent 169b0265
No related branches found
No related tags found
2 merge requests!119Release 0.61.0,!90Add GraphQL GVA API support
...@@ -232,11 +232,14 @@ class API: ...@@ -232,11 +232,14 @@ class API:
api_path=self.connection_handler.path, api_path=self.connection_handler.path,
) )
else: else:
url = "{scheme}://{server}:{port}/".format( url = "{scheme}://{server}:{port}".format(
scheme=scheme, server=server, port=port scheme=scheme, server=server, port=port
) )
return url + path if len(path.strip()) > 0:
return f"{url}/{path}"
return url
async def requests_get(self, path: str, **kwargs: Any) -> ClientResponse: async def requests_get(self, path: str, **kwargs: Any) -> ClientResponse:
""" """
......
...@@ -21,7 +21,7 @@ import unittest ...@@ -21,7 +21,7 @@ import unittest
import aiohttp import aiohttp
from duniterpy.api.client import API, parse_error from duniterpy.api.client import API, parse_error
from duniterpy.api.endpoint import BMAEndpoint from duniterpy.api.endpoint import BMAEndpoint, SecuredBMAEndpoint, GVAEndpoint
class TestBmaApi(unittest.TestCase): class TestBmaApi(unittest.TestCase):
...@@ -53,6 +53,42 @@ class TestBmaApi(unittest.TestCase): ...@@ -53,6 +53,42 @@ class TestBmaApi(unittest.TestCase):
self.loop.run_until_complete(go()) self.loop.run_until_complete(go())
def test_reverse_url_complete_bmas(self):
async def go():
endpoint = SecuredBMAEndpoint(
"test.com",
"124.2.2.1",
"2001:0db8:0000:85a3:0000:0000:ac1f:8001 ",
9092,
"api_path",
)
session = aiohttp.ClientSession()
api = API(endpoint.conn_handler(session))
self.assertEqual(
api.reverse_url("http", "/test/url"),
"http://test.com:9092/api_path/test/url",
)
await session.close()
self.loop.run_until_complete(go())
def test_reverse_url_complete_gva(self):
async def go():
endpoint = GVAEndpoint(
"S",
"test.com",
"124.2.2.1",
"2001:0db8:0000:85a3:0000:0000:ac1f:8001 ",
9092,
"gva",
)
session = aiohttp.ClientSession()
api = API(endpoint.conn_handler(session))
self.assertEqual(api.reverse_url("https", ""), "https://test.com:9092/gva")
await session.close()
self.loop.run_until_complete(go())
def test_reverse_url_only_ipv4(self): def test_reverse_url_only_ipv4(self):
async def go(): async def go():
endpoint = BMAEndpoint("", "124.2.2.1", "", 9092) endpoint = BMAEndpoint("", "124.2.2.1", "", 9092)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment