|
17 | 17 |
|
18 | 18 | import pytest |
19 | 19 |
|
20 | | -from couchbase.exceptions import (BucketDoesNotExistException, |
21 | | - CollectionAlreadyExistsException, |
| 20 | +from couchbase.exceptions import (CollectionAlreadyExistsException, |
22 | 21 | CollectionNotFoundException, |
23 | 22 | DocumentNotFoundException, |
24 | 23 | FeatureUnavailableException, |
@@ -95,6 +94,11 @@ def check_negative_collection_max_expiry_supported(self, cb_env): |
95 | 94 | cb_env.server_version_short, |
96 | 95 | cb_env.mock_server_type) |
97 | 96 |
|
| 97 | + @pytest.fixture() |
| 98 | + def drop_bucket(self, cb_env): |
| 99 | + yield |
| 100 | + cb_env.drop_bucket() |
| 101 | + |
98 | 102 | def test_collection_goes_in_correct_bucket(self, cb_env): |
99 | 103 | collection_name = cb_env.get_collection_name() |
100 | 104 | scope_name = '_default' |
@@ -287,89 +291,95 @@ def test_get_all_scopes(self, cb_env): |
287 | 291 | assert c.history is None or isinstance(c.history, bool) |
288 | 292 |
|
289 | 293 | @pytest.mark.usefixtures('check_non_deduped_history_supported') |
| 294 | + @pytest.mark.usefixtures('drop_bucket') |
290 | 295 | def test_create_collection_history_retention(self, cb_env): |
291 | | - bucket_name = 'test-magma-bucket' |
| 296 | + bucket_name = cb_env.get_bucket_name() |
292 | 297 | scope_name = '_default' |
293 | | - collection_name = cb_env.get_collection_name() |
| 298 | + collection_name = 'test-collection' |
294 | 299 |
|
295 | 300 | cb_env.create_bucket(bucket_name, storage_backend=StorageBackend.MAGMA) |
296 | 301 | bucket = TestEnvironment.try_n_times(3, 5, cb_env.cluster.bucket, bucket_name) |
297 | 302 | cm = bucket.collections() |
298 | 303 |
|
299 | 304 | cm.create_collection(scope_name, collection_name, CreateCollectionSettings(history=True)) |
300 | 305 | cb_env.consistency.wait_until_collection_present(bucket.name, scope_name, collection_name) |
| 306 | + |
301 | 307 | collection_spec = cb_env.get_collection(scope_name, collection_name, bucket_name=bucket_name) |
302 | 308 | assert collection_spec is not None |
303 | 309 | assert collection_spec.history |
304 | 310 |
|
305 | | - TestEnvironment.try_n_times_till_exception(10, |
306 | | - 3, |
307 | | - cb_env.bm.drop_bucket, |
308 | | - bucket_name, |
309 | | - expected_exceptions=(BucketDoesNotExistException,)) |
310 | | - |
311 | 311 | @pytest.mark.usefixtures('check_non_deduped_history_supported') |
| 312 | + @pytest.mark.usefixtures('drop_bucket') |
312 | 313 | def test_create_collection_history_retention_unsupported(self, cb_env): |
| 314 | + bucket_name = cb_env.get_bucket_name() |
313 | 315 | scope_name = '_default' |
314 | | - collection_name = cb_env.get_collection_name() |
| 316 | + collection_name = 'test-collection' |
| 317 | + |
| 318 | + cb_env.create_bucket(bucket_name, storage_backend=StorageBackend.COUCHSTORE) |
| 319 | + bucket = TestEnvironment.try_n_times(3, 5, cb_env.cluster.bucket, bucket_name) |
| 320 | + cm = bucket.collections() |
315 | 321 |
|
316 | 322 | # Couchstore does not support history retention |
317 | 323 | with pytest.raises(FeatureUnavailableException): |
318 | | - cb_env.test_bucket_cm.create_collection( |
| 324 | + cm.create_collection( |
319 | 325 | scope_name, collection_name, CreateCollectionSettings(history=True)) |
320 | 326 |
|
321 | 327 | with pytest.raises(FeatureUnavailableException): |
322 | | - cb_env.test_bucket_cm.create_collection( |
| 328 | + cm.create_collection( |
323 | 329 | scope_name, collection_name, CreateCollectionSettings(history=False)) |
324 | 330 |
|
325 | 331 | @pytest.mark.usefixtures('check_non_deduped_history_supported') |
326 | 332 | @pytest.mark.usefixtures('check_update_collection_supported') |
| 333 | + @pytest.mark.usefixtures('drop_bucket') |
327 | 334 | def test_update_collection_history_retention(self, cb_env): |
328 | | - bucket_name = 'test-magma-bucket' |
| 335 | + bucket_name = cb_env.get_bucket_name() |
329 | 336 | scope_name = '_default' |
330 | | - collection_name = cb_env.get_collection_name() |
| 337 | + collection_name = 'test-collection' |
331 | 338 |
|
332 | 339 | cb_env.create_bucket(bucket_name, storage_backend=StorageBackend.MAGMA) |
333 | 340 | bucket = TestEnvironment.try_n_times(3, 5, cb_env.cluster.bucket, bucket_name) |
334 | 341 | cm = bucket.collections() |
335 | 342 |
|
336 | 343 | cm.create_collection(scope_name, collection_name, CreateCollectionSettings(history=False)) |
337 | 344 | cb_env.consistency.wait_until_collection_present(bucket.name, scope_name, collection_name) |
| 345 | + |
338 | 346 | collection_spec = cb_env.get_collection(scope_name, collection_name, bucket_name=bucket_name) |
339 | 347 | assert collection_spec is not None |
340 | 348 | assert not collection_spec.history |
341 | 349 |
|
342 | 350 | cm.update_collection(scope_name, collection_name, UpdateCollectionSettings(history=True)) |
343 | 351 | cb_env.consistency.wait_until_collection_has_settings( |
344 | 352 | bucket.name, scope_name, collection_name, {'history': True}) |
| 353 | + |
345 | 354 | collection_spec = cb_env.get_collection(scope_name, collection_name, bucket_name=bucket_name) |
346 | 355 | assert collection_spec is not None |
347 | 356 | assert collection_spec.history |
348 | 357 |
|
349 | | - TestEnvironment.try_n_times_till_exception(10, |
350 | | - 3, |
351 | | - cb_env.bm.drop_bucket, |
352 | | - bucket_name, |
353 | | - expected_exceptions=(BucketDoesNotExistException,)) |
354 | | - |
355 | 358 | @pytest.mark.usefixtures('check_non_deduped_history_supported') |
356 | 359 | @pytest.mark.usefixtures('check_update_collection_supported') |
| 360 | + @pytest.mark.usefixtures('drop_bucket') |
357 | 361 | def test_update_collection_history_retention_unsupported(self, cb_env): |
| 362 | + bucket_name = cb_env.get_bucket_name() |
358 | 363 | scope_name = '_default' |
359 | | - collection_name = cb_env.get_collection_name() |
| 364 | + collection_name = 'test-collection' |
360 | 365 |
|
361 | | - cb_env.test_bucket_cm.create_collection(scope_name, collection_name) |
362 | | - cb_env.consistency.wait_until_collection_present(cb_env.test_bucket.name, scope_name, collection_name) |
363 | | - collection_spec = cb_env.get_collection(scope_name, collection_name) |
| 366 | + cb_env.create_bucket(bucket_name, storage_backend=StorageBackend.COUCHSTORE) |
| 367 | + bucket = TestEnvironment.try_n_times(3, 5, cb_env.cluster.bucket, bucket_name) |
| 368 | + cm = bucket.collections() |
| 369 | + |
| 370 | + cm.create_collection(scope_name, collection_name) |
| 371 | + cb_env.consistency.wait_until_collection_present(bucket_name, scope_name, collection_name) |
| 372 | + |
| 373 | + collection_spec = cb_env.get_collection(scope_name, collection_name, bucket_name) |
364 | 374 | assert collection_spec is not None |
365 | 375 | assert collection_spec.history is False |
366 | 376 |
|
367 | 377 | # Couchstore does not support history retention |
368 | 378 | with pytest.raises(FeatureUnavailableException): |
369 | | - cb_env.test_bucket_cm.update_collection(scope_name, collection_name, UpdateCollectionSettings(history=True)) |
| 379 | + cm.update_collection(scope_name, collection_name, UpdateCollectionSettings(history=True)) |
370 | 380 |
|
371 | 381 | # Collection history retention setting remains unchanged |
372 | | - collection_spec = cb_env.get_collection(scope_name, collection_name) |
| 382 | + collection_spec = cb_env.get_collection(scope_name, collection_name, bucket_name) |
373 | 383 | assert collection_spec is not None |
374 | 384 | assert collection_spec.history is False |
375 | 385 |
|
|
0 commit comments