From 057658b0c8535bff7e147f55973168457f3c08b7 Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 16 Sep 2016 00:56:13 +0530 Subject: [PATCH 1/2] Fixes #96 --- kinto_http/__init__.py | 21 +++------------------ kinto_http/tests/functional.py | 21 --------------------- 2 files changed, 3 insertions(+), 39 deletions(-) diff --git a/kinto_http/__init__.py b/kinto_http/__init__.py index 751c732..a6a63be 100644 --- a/kinto_http/__init__.py +++ b/kinto_http/__init__.py @@ -254,11 +254,7 @@ def delete_bucket(self, bucket=None, safe=True, if_match=None, if_exists=False): resp, _ = self.session.request('delete', endpoint, headers=headers) return resp['data'] - def delete_buckets(self, safe=True, if_match=None, if_exists=False): - if if_exists: - return self._delete_if_exists('buckets', - safe=safe, - if_match=if_match) + def delete_buckets(self, safe=True, if_match=None): endpoint = self.get_endpoint('buckets') headers = self._get_cache_headers(safe, if_match=if_match) resp, _ = self.session.request('delete', endpoint, headers=headers) @@ -415,12 +411,7 @@ def delete_collection(self, collection=None, bucket=None, resp, _ = self.session.request('delete', endpoint, headers=headers) return resp['data'] - def delete_collections(self, bucket=None, safe=True, if_match=None, if_exists=False): - if if_exists: - return self._delete_if_exists('collections', - bucket=bucket, - safe=safe, - if_match=if_match) + def delete_collections(self, bucket=None, safe=True, if_match=None): endpoint = self.get_endpoint('collections', bucket=bucket) headers = self._get_cache_headers(safe, if_match=if_match) resp, _ = self.session.request('delete', endpoint, headers=headers) @@ -523,13 +514,7 @@ def delete_record(self, id, collection=None, bucket=None, return resp['data'] def delete_records(self, collection=None, bucket=None, - safe=True, if_match=None, if_exists=False): - if if_exists: - return self._delete_if_exists('records', - collection=collection, - bucket=bucket, - safe=safe, - if_match=if_match) + safe=True, if_match=None): endpoint = self.get_endpoint('records', bucket=bucket, collection=collection) diff --git a/kinto_http/tests/functional.py b/kinto_http/tests/functional.py index c0196d7..8af5cf8 100644 --- a/kinto_http/tests/functional.py +++ b/kinto_http/tests/functional.py @@ -94,11 +94,6 @@ def test_buckets_deletion(self): assert buckets[0]['id'] == 'mozilla' self.assertRaises(BucketNotFound, self.client.get_bucket, 'mozilla') - def test_buckets_deletion_if_exists(self): - self.client.create_bucket('mozilla') - self.client.delete_buckets() - self.client.delete_buckets(if_exists=True) - def test_bucket_save(self): self.client.create_bucket('mozilla', permissions={'write': ['alexis']}) bucket = self.client.get_bucket('mozilla') @@ -235,13 +230,6 @@ def test_collections_deletion(self): self.client.delete_collections(bucket='mozilla') assert len(self.client.get_collections(bucket='mozilla')) == 0 - def test_collections_deletion_if_exists(self): - self.client.create_bucket('mozilla') - self.client.create_collection('amo', bucket='mozilla') - self.client.create_collection('blocklist', bucket='mozilla') - self.client.delete_collections(bucket='mozilla') - self.client.delete_collections(bucket='mozilla', if_exists=True) - def test_record_creation_and_retrieval(self): client = Client(server_url=self.server_url, auth=self.auth, bucket='mozilla', collection='payments') @@ -356,15 +344,6 @@ def test_multiple_record_deletion(self): client.delete_records() assert len(client.get_records()) == 0 - def test_records_deletion_if_exists(self): - client = Client(server_url=self.server_url, auth=self.auth, - bucket='mozilla', collection='payments') - client.create_bucket() - client.create_collection() - client.create_record({'foo': 'bar'}) - client.delete_records() - client.delete_records(if_exists=True) - def test_bucket_sharing(self): alice_credentials = ('alice', 'p4ssw0rd') alice_userid = self.get_user_id(alice_credentials) From 8cf20dc5e609353ed82205a82dbda0593318538d Mon Sep 17 00:00:00 2001 From: mansimarkaur Date: Fri, 16 Sep 2016 04:48:27 +0530 Subject: [PATCH 2/2] Added tests to ensure no failure on deleting non existent plural endpoints --- kinto_http/tests/functional.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/kinto_http/tests/functional.py b/kinto_http/tests/functional.py index 8af5cf8..e751e08 100644 --- a/kinto_http/tests/functional.py +++ b/kinto_http/tests/functional.py @@ -94,6 +94,10 @@ def test_buckets_deletion(self): assert buckets[0]['id'] == 'mozilla' self.assertRaises(BucketNotFound, self.client.get_bucket, 'mozilla') + def test_buckets_deletion_when_no_buckets_exist(self): + deleted_buckets = self.client.delete_buckets() + assert len(deleted_buckets) == 0 + def test_bucket_save(self): self.client.create_bucket('mozilla', permissions={'write': ['alexis']}) bucket = self.client.get_bucket('mozilla') @@ -175,6 +179,11 @@ def test_groups_deletion(self): self.client.delete_groups(bucket='mozilla') assert len(self.client.get_groups(bucket='mozilla')) == 0 + def test_groups_deletion_when_no_groups_exist(self): + self.client.create_bucket('mozilla') + deleted_groups = self.client.delete_groups(bucket='mozilla') + assert len(deleted_groups) == 0 + def test_collection_creation(self): self.client.create_bucket('mozilla') self.client.create_collection( @@ -230,6 +239,11 @@ def test_collections_deletion(self): self.client.delete_collections(bucket='mozilla') assert len(self.client.get_collections(bucket='mozilla')) == 0 + def test_collections_deletion_when_no_collections_exist(self): + self.client.create_bucket('mozilla') + deleted_collections = self.client.delete_collections(bucket='mozilla') + assert len(deleted_collections) == 0 + def test_record_creation_and_retrieval(self): client = Client(server_url=self.server_url, auth=self.auth, bucket='mozilla', collection='payments') @@ -344,6 +358,14 @@ def test_multiple_record_deletion(self): client.delete_records() assert len(client.get_records()) == 0 + def test_records_deletion_when_no_records_exist(self): + client = Client(server_url=self.server_url, auth=self.auth, + bucket='mozilla', collection='payments') + client.create_bucket() + client.create_collection() + deleted_records = client.delete_records() + assert len(deleted_records) == 0 + def test_bucket_sharing(self): alice_credentials = ('alice', 'p4ssw0rd') alice_userid = self.get_user_id(alice_credentials)