|
1 | 1 | import json |
| 2 | +from unittest import mock |
2 | 3 |
|
3 | 4 | from pylxd import exceptions, models |
4 | 5 | from pylxd.tests import testing |
@@ -166,3 +167,46 @@ def test_delete(self): |
166 | 167 | a_project = self.client.projects.all()[0] |
167 | 168 |
|
168 | 169 | 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