Client base_url - #46
Conversation
lovelydinosaur
left a comment
There was a problem hiding this comment.
Thanks for this!
A few tweaks requested here, since we ought to use the URL class internally (since it'll correctly deal with stuff like internationalized URLs for us).
| class Client: | ||
| def __init__( | ||
| self, | ||
| base_url: str = None, |
There was a problem hiding this comment.
We'd want to use URLTypes here.
| ) | ||
| self.adapter = EnvironmentAdapter(dispatch=redirect_adapter) | ||
|
|
||
| self.base_url = base_url |
There was a problem hiding this comment.
Let's use the URL type. Eg. self.base_url = None if url is None else URL(base_url)
| ) -> Response: | ||
|
|
||
| if self.base_url is not None: | ||
| url = urljoin(self.base_url, url) |
There was a problem hiding this comment.
I think it'd be something like...
if self.base_url is not None:
url = URL(url, allow_relative=True).resolve_with(self.base_url)| response = await client.get(path) | ||
| assert response.status_code == 200 | ||
| assert response.text == "Hello, world!" | ||
| assert str(response.request.url) == "http://127.0.0.1:8000/hello/hummans/" |
There was a problem hiding this comment.
Let's just have a single example in the test case, and use http://127.0.0.1:8000/ as the base URL, and just do .get('/hello') or something like that.
(Also just use str(response.url) instead of str(response.request.url))
|
On reflection I think we should punt on this for now. |
ref #38