Unify mock project responses.
@@ -177,43 +177,34 @@ class TestClient(unittest.TestCase):
def test_authenticate_with_project(self):
"""A client is authenticated with a project."""
response = mock.MagicMock(status_code=200)
- response.json.return_value = {
+ response.json.side_effect = [
+ {
"metadata": {
"auth": "untrusted",
"api_extensions": ["projects"],
}
- }
- self.get.return_value = response
-
- certs = (
- os.path.join(os.path.dirname(__file__), "lxd.crt"),
- os.path.join(os.path.dirname(__file__), "lxd.key"),
- )
- an_client = client.Client("https://lxd", cert=certs, project="test-proj")
-
- get_count = []
-
- def _get(*args, **kwargs):
- if len(get_count) == 0:
- get_count.append(None)
- return {
+ },
+ {
"metadata": {
"type": "client",
"fingerprint": "eaf55b72fc23aa516d709271df9b0116064bf8cfa009cf34c67c33ad32c2320c",
}
- }
- else:
- return {
+ },
+ {
"metadata": {
"auth": "trusted",
"environment": {"project": "test-proj"},
}
- }
-
- response = mock.MagicMock(status_code=200)
- response.json.side_effect = _get
+ },
+ ]
self.get.return_value = response
+ certs = (
+ os.path.join(os.path.dirname(__file__), "lxd.crt"),
+ os.path.join(os.path.dirname(__file__), "lxd.key"),
+ )
+ an_client = client.Client("https://lxd", cert=certs, project="test-proj")
+
an_client.authenticate("test-password")
self.assertTrue(an_client.trusted)
