|
32 | 32 | from couchbase.management.collections import (CollectionSpec, |
33 | 33 | CreateCollectionSettings, |
34 | 34 | UpdateCollectionSettings) |
| 35 | +from couchbase.management.options import CreateCollectionOptions, DropCollectionOptions |
35 | 36 |
|
36 | 37 | from ._test_utils import TestEnvironment |
37 | 38 |
|
@@ -174,6 +175,83 @@ async def test_create_collection(self, cb_env): |
174 | 175 | await cb_env.test_bucket_cm.create_collection("_default", self.TEST_COLLECTION) |
175 | 176 | assert await cb_env.get_collection("_default", self.TEST_COLLECTION) is not None |
176 | 177 |
|
| 178 | + @pytest.mark.usefixtures("cleanup_collection") |
| 179 | + @pytest.mark.asyncio |
| 180 | + async def test_create_collection_kwargs(self, cb_env): |
| 181 | + # all-keyword form |
| 182 | + await cb_env.test_bucket_cm.create_collection(scope_name="_default", |
| 183 | + collection_name=self.TEST_COLLECTION) |
| 184 | + assert await cb_env.get_collection("_default", self.TEST_COLLECTION) is not None |
| 185 | + |
| 186 | + @pytest.mark.usefixtures("cleanup_collection") |
| 187 | + @pytest.mark.asyncio |
| 188 | + async def test_create_collection_mixed_kwargs(self, cb_env): |
| 189 | + # positional scope_name, keyword collection_name |
| 190 | + await cb_env.test_bucket_cm.create_collection("_default", |
| 191 | + collection_name=self.TEST_COLLECTION) |
| 192 | + assert await cb_env.get_collection("_default", self.TEST_COLLECTION) is not None |
| 193 | + |
| 194 | + @pytest.mark.usefixtures("cleanup_collection") |
| 195 | + @pytest.mark.asyncio |
| 196 | + async def test_create_collection_settings_kwarg(self, cb_env): |
| 197 | + if cb_env.is_mock_server: |
| 198 | + pytest.skip("CAVES doesn't support collection expiry.") |
| 199 | + # positional names with settings passed as a keyword |
| 200 | + settings = CreateCollectionSettings(max_expiry=timedelta(seconds=2)) |
| 201 | + await cb_env.test_bucket_cm.create_collection("_default", |
| 202 | + self.TEST_COLLECTION, |
| 203 | + settings=settings) |
| 204 | + coll_spec = await cb_env.get_collection("_default", self.TEST_COLLECTION) |
| 205 | + assert coll_spec is not None |
| 206 | + assert coll_spec.max_expiry == timedelta(seconds=2) |
| 207 | + |
| 208 | + @pytest.mark.usefixtures("cleanup_collection") |
| 209 | + @pytest.mark.asyncio |
| 210 | + async def test_create_collection_with_options(self, cb_env): |
| 211 | + # positional names + positional options |
| 212 | + opts = CreateCollectionOptions(timeout=timedelta(seconds=30)) |
| 213 | + await cb_env.test_bucket_cm.create_collection("_default", self.TEST_COLLECTION, None, opts) |
| 214 | + assert await cb_env.get_collection("_default", self.TEST_COLLECTION) is not None |
| 215 | + |
| 216 | + @pytest.mark.usefixtures("cleanup_collection") |
| 217 | + @pytest.mark.asyncio |
| 218 | + async def test_create_collection_timeout_kwarg(self, cb_env): |
| 219 | + # kwargs path + timeout as a raw keyword |
| 220 | + await cb_env.test_bucket_cm.create_collection(scope_name="_default", |
| 221 | + collection_name=self.TEST_COLLECTION, |
| 222 | + timeout=timedelta(seconds=30)) |
| 223 | + assert await cb_env.get_collection("_default", self.TEST_COLLECTION) is not None |
| 224 | + |
| 225 | + @pytest.mark.usefixtures("cleanup_collection") |
| 226 | + @pytest.mark.asyncio |
| 227 | + async def test_create_collection_collection_spec_kwarg(self, cb_env): |
| 228 | + spec = CollectionSpec(self.TEST_COLLECTION) |
| 229 | + await cb_env.test_bucket_cm.create_collection(collection=spec) |
| 230 | + assert await cb_env.get_collection("_default", self.TEST_COLLECTION) is not None |
| 231 | + |
| 232 | + @pytest.mark.asyncio |
| 233 | + async def test_create_collection_invalid_args(self, cb_env): |
| 234 | + spec = CollectionSpec("coll", "scope") |
| 235 | + with pytest.raises(InvalidArgumentException): |
| 236 | + await cb_env.test_bucket_cm.create_collection(spec, collection=spec) |
| 237 | + with pytest.raises(InvalidArgumentException): |
| 238 | + await cb_env.test_bucket_cm.create_collection(spec, scope_name="_default") |
| 239 | + with pytest.raises(InvalidArgumentException): |
| 240 | + await cb_env.test_bucket_cm.create_collection(spec, settings=CreateCollectionSettings()) |
| 241 | + with pytest.raises(InvalidArgumentException): |
| 242 | + await cb_env.test_bucket_cm.create_collection(collection=spec, collection_name="c") |
| 243 | + with pytest.raises(InvalidArgumentException): |
| 244 | + await cb_env.test_bucket_cm.create_collection("_default", collection=spec) |
| 245 | + with pytest.raises(InvalidArgumentException): |
| 246 | + await cb_env.test_bucket_cm.create_collection("_default", scope_name="_default") |
| 247 | + with pytest.raises(InvalidArgumentException): |
| 248 | + await cb_env.test_bucket_cm.create_collection("_default", "c", collection_name="c") |
| 249 | + with pytest.raises(InvalidArgumentException): |
| 250 | + await cb_env.test_bucket_cm.create_collection("_default", "c", CreateCollectionSettings(), |
| 251 | + settings=CreateCollectionSettings()) |
| 252 | + with pytest.raises(InvalidArgumentException): |
| 253 | + await cb_env.test_bucket_cm.create_collection("_default", "c", settings="not-a-settings") |
| 254 | + |
177 | 255 | @pytest.mark.usefixtures("cleanup_scope") |
178 | 256 | @pytest.mark.asyncio |
179 | 257 | async def test_create_scope_and_collection(self, cb_env): |
@@ -316,6 +394,60 @@ async def test_drop_collection(self, cb_env): |
316 | 394 | with pytest.raises(CollectionNotFoundException): |
317 | 395 | await cb_env.test_bucket_cm.drop_collection("_default", self.TEST_COLLECTION) |
318 | 396 |
|
| 397 | + @pytest.mark.usefixtures("cleanup_collection") |
| 398 | + @pytest.mark.asyncio |
| 399 | + async def test_drop_collection_kwargs(self, cb_env): |
| 400 | + await cb_env.test_bucket_cm.create_collection("_default", self.TEST_COLLECTION) |
| 401 | + assert await cb_env.get_collection("_default", self.TEST_COLLECTION) is not None |
| 402 | + await cb_env.test_bucket_cm.drop_collection(scope_name="_default", |
| 403 | + collection_name=self.TEST_COLLECTION) |
| 404 | + with pytest.raises(CollectionNotFoundException): |
| 405 | + await cb_env.test_bucket_cm.drop_collection(scope_name="_default", |
| 406 | + collection_name=self.TEST_COLLECTION) |
| 407 | + |
| 408 | + @pytest.mark.usefixtures("cleanup_collection") |
| 409 | + @pytest.mark.asyncio |
| 410 | + async def test_drop_collection_with_options(self, cb_env): |
| 411 | + opts = DropCollectionOptions(timeout=timedelta(seconds=30)) |
| 412 | + await cb_env.test_bucket_cm.create_collection("_default", self.TEST_COLLECTION) |
| 413 | + assert await cb_env.get_collection("_default", self.TEST_COLLECTION) is not None |
| 414 | + await cb_env.test_bucket_cm.drop_collection("_default", self.TEST_COLLECTION, opts) |
| 415 | + |
| 416 | + @pytest.mark.usefixtures("cleanup_collection") |
| 417 | + @pytest.mark.asyncio |
| 418 | + async def test_drop_collection_timeout_kwarg(self, cb_env): |
| 419 | + await cb_env.test_bucket_cm.create_collection("_default", self.TEST_COLLECTION) |
| 420 | + assert await cb_env.get_collection("_default", self.TEST_COLLECTION) is not None |
| 421 | + await cb_env.test_bucket_cm.drop_collection(scope_name="_default", |
| 422 | + collection_name=self.TEST_COLLECTION, |
| 423 | + timeout=timedelta(seconds=30)) |
| 424 | + |
| 425 | + @pytest.mark.usefixtures("cleanup_collection") |
| 426 | + @pytest.mark.asyncio |
| 427 | + async def test_drop_collection_collection_spec_kwarg(self, cb_env): |
| 428 | + spec = CollectionSpec(self.TEST_COLLECTION) |
| 429 | + await cb_env.test_bucket_cm.create_collection(spec) |
| 430 | + assert await cb_env.get_collection("_default", self.TEST_COLLECTION) is not None |
| 431 | + await cb_env.test_bucket_cm.drop_collection(collection=spec) |
| 432 | + with pytest.raises(CollectionNotFoundException): |
| 433 | + await cb_env.test_bucket_cm.drop_collection(collection=spec) |
| 434 | + |
| 435 | + @pytest.mark.asyncio |
| 436 | + async def test_drop_collection_invalid_args(self, cb_env): |
| 437 | + spec = CollectionSpec("coll", "scope") |
| 438 | + with pytest.raises(InvalidArgumentException): |
| 439 | + await cb_env.test_bucket_cm.drop_collection(spec, collection=spec) |
| 440 | + with pytest.raises(InvalidArgumentException): |
| 441 | + await cb_env.test_bucket_cm.drop_collection(spec, scope_name="_default") |
| 442 | + with pytest.raises(InvalidArgumentException): |
| 443 | + await cb_env.test_bucket_cm.drop_collection(collection=spec, collection_name="c") |
| 444 | + with pytest.raises(InvalidArgumentException): |
| 445 | + await cb_env.test_bucket_cm.drop_collection("_default", collection=spec) |
| 446 | + with pytest.raises(InvalidArgumentException): |
| 447 | + await cb_env.test_bucket_cm.drop_collection("_default", scope_name="_default") |
| 448 | + with pytest.raises(InvalidArgumentException): |
| 449 | + await cb_env.test_bucket_cm.drop_collection("_default", "c", collection_name="c") |
| 450 | + |
319 | 451 | @pytest.mark.asyncio |
320 | 452 | async def test_drop_collection_not_found(self, cb_env): |
321 | 453 | with pytest.raises(CollectionNotFoundException): |
|
0 commit comments