sts-sponsors team mailing list archive
-
sts-sponsors team
-
Mailing list archive
-
Message #08899
Re: [Merge] ~r00ta/maas:MAASENG-1785 into maas:sqlalchemy-spike
Nice job.
I found a minor nag inline while skimming but it makes sense for ack or bjorn to have another look.
Diff comments:
> diff --git a/src/maasserver/utils/tests/test_fast_client.py b/src/maasserver/utils/tests/test_fast_client.py
> new file mode 100644
> index 0000000..676c9f0
> --- /dev/null
> +++ b/src/maasserver/utils/tests/test_fast_client.py
> @@ -0,0 +1,75 @@
> +from os import environ
> +import unittest
> +from unittest.mock import patch
> +
> +from maasserver.utils.fast_client import MaasFastClient
> +
> +
> +class BaseFastClientTests:
> + def __init__(self):
> + self.client = None
> + self.encoded_socket_path = None
> +
> + def test_build_url(self):
> + url = self.client._build_url("/endpoint")
> + assert url == f"http+unix://{self.encoded_socket_path}/endpoint"
> +
> + @patch("requests_unixsocket.Session.get")
> + def test_get(self, mock_session_get):
> + self.client.get("/endpoint")
> + mock_session_get.assert_called_with(
> + f"http+unix://{self.encoded_socket_path}/endpoint"
> + )
> +
> + @patch("requests_unixsocket.Session.post")
> + def test_post(self, mock_session_post):
> + kwargs = {
> + "json": {"key": "value"},
> + }
> + self.client.post("/endpoint", **kwargs)
> + mock_session_post.assert_called_with(
> + f"http+unix://{self.encoded_socket_path}/endpoint", **kwargs
> + )
> +
> + @patch("requests_unixsocket.Session.put")
> + def test_put(self, mock_session_put):
> + kwargs = {
> + "json": {"key": "value"},
> + }
> + self.client.put("/endpoint", **kwargs)
> + mock_session_put.assert_called_with(
> + f"http+unix://{self.encoded_socket_path}/endpoint", **kwargs
> + )
> +
> + @patch("requests_unixsocket.Session.delete")
> + def test_delete(self, mock_session_delete):
> + self.client.delete("/endpoint")
> + mock_session_delete.assert_called_with(
> + f"http+unix://{self.encoded_socket_path}/endpoint"
> + )
> +
> +
> +class SnapMaasFastClientTests(unittest.TestCase, BaseFastClientTests):
> + @patch.dict(
> + environ,
> + {
> + "MAAS_FAST_HTTP_SOCKET_PATH": "/var/snap/maas/common/maasfast-http.sock"
> + },
> + clear=True,
> + )
> + def setUp(self):
> + self.encoded_socket_path = (
> + "%2Fvar%2Fsnap%2Fmaas%2Fcommon%2Fmaasfast-http.sock"
I think we're importing urllib anyways, so urllib.parse.quote('/var/snap/...', safe='') might be more readable
> + )
> + self.client = MaasFastClient()
> +
> +
> +class DebMaasFastClientTests(unittest.TestCase, BaseFastClientTests):
> + @patch.dict(environ, {}, clear=True)
> + @patch("provisioningserver.path.get_maas_data_path")
> + def setUp(self, mock_get_maas_data_path):
> + mock_get_maas_data_path.return_value = (
> + "/var/lib/maas/maasfast-http.sock"
> + )
> + self.encoded_socket_path = "%2Fvar%2Flib%2Fmaas%2Fmaasfast-http.sock"
> + self.client = MaasFastClient()
--
https://code.launchpad.net/~r00ta/maas/+git/maas/+merge/443950
Your team MAAS Committers is subscribed to branch maas:sqlalchemy-spike.
References