Skip to content

Commit

Permalink
Merge pull request #98 from mansimarkaur/delete-method_plural_endpoints
Browse files Browse the repository at this point in the history
Removed if_exists argument from the delete_*s methods for plural endpoints
  • Loading branch information
Natim authored Sep 16, 2016
2 parents f977331 + 8cf20dc commit dea329a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 31 deletions.
21 changes: 3 additions & 18 deletions kinto_http/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 14 additions & 13 deletions kinto_http/tests/functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ 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_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']})
Expand Down Expand Up @@ -180,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(
Expand Down Expand Up @@ -235,12 +239,10 @@ 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):
def test_collections_deletion_when_no_collections_exist(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)
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,
Expand Down Expand Up @@ -356,14 +358,13 @@ def test_multiple_record_deletion(self):
client.delete_records()
assert len(client.get_records()) == 0

def test_records_deletion_if_exists(self):
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()
client.create_record({'foo': 'bar'})
client.delete_records()
client.delete_records(if_exists=True)
deleted_records = client.delete_records()
assert len(deleted_records) == 0

def test_bucket_sharing(self):
alice_credentials = ('alice', 'p4ssw0rd')
Expand Down

0 comments on commit dea329a

Please sign in to comment.