Skip to content

Commit 81165b5

Browse files
committed
pylxd/models/tests/test_project: Add async response handling test for project deletion
Signed-off-by: tugbataluy <tugba.taluy@canonical.com>
1 parent 7d9a8ae commit 81165b5

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

pylxd/models/tests/test_project.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
from unittest import mock
23

34
from pylxd import exceptions, models
45
from pylxd.tests import testing
@@ -166,3 +167,46 @@ def test_delete(self):
166167
a_project = self.client.projects.all()[0]
167168

168169
a_project.delete()
170+
171+
172+
class TestProjectAsync(testing.PyLXDTestCase):
173+
"""Tests for async operations in Project."""
174+
175+
def setUp(self):
176+
super().setUp()
177+
self.mock_wait = mock.patch.object(
178+
self.client.operations, "wait_for_operation"
179+
).start()
180+
self.addCleanup(mock.patch.stopall)
181+
182+
def _mock_async_delete(self, name="test-project"):
183+
self.add_rule(
184+
{
185+
"json": {
186+
"type": "async",
187+
"status_code": 202,
188+
"operation": "/1.0/operations/test-op",
189+
},
190+
"status_code": 202,
191+
"method": "DELETE",
192+
"url": rf"^http://pylxd.test/1.0/projects/{name}$",
193+
}
194+
)
195+
196+
def test_delete_async_with_wait(self):
197+
"""Async project delete with wait=True waits for the operation."""
198+
a_project = models.Project(self.client, name="test-project")
199+
self._mock_async_delete()
200+
201+
a_project.delete(wait=True)
202+
203+
self.mock_wait.assert_called_once_with("/1.0/operations/test-op")
204+
205+
def test_delete_async_without_wait(self):
206+
"""Async project delete with wait=False does not wait."""
207+
a_project = models.Project(self.client, name="test-project")
208+
self._mock_async_delete()
209+
210+
a_project.delete(wait=False)
211+
212+
self.mock_wait.assert_not_called()

0 commit comments

Comments
 (0)