Skip to content

Commit

Permalink
Merge pull request Kinto#720 from Kinto/prepare-3.2.3
Browse files Browse the repository at this point in the history
Prepare 3.2.3
  • Loading branch information
leplatrem authored Jul 18, 2016
2 parents 201ad5c + 4aa8679 commit 75e15d7
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 4 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ Changelog

This document describes changes between each past release.

3.2.3 (unreleased)
3.2.3 (2016-07-18)
==================

- Nothing changed yet.
**Bug fixes**

- Allow filtering and sorting by any attribute on buckets, collections and groups list endpoints
- Fix crash in memory backend with Python3 when filtering on unknown field


3.2.2 (2016-07-13)
Expand Down
9 changes: 8 additions & 1 deletion kinto/core/storage/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ def apply_filters(self, records, filters):
COMPARISON.IN: operator.contains,
COMPARISON.EXCLUDE: lambda x, y: not operator.contains(x, y),
}

for record in records:
matches = True
for f in filters:
Expand All @@ -109,6 +108,14 @@ def apply_filters(self, records, filters):
if f.operator in (COMPARISON.IN, COMPARISON.EXCLUDE):
right = left
left = f.value
else:
# Python3 cannot compare None to other value.
if left is None:
if f.operator in (COMPARISON.GT, COMPARISON.MIN):
matches = False
continue
elif f.operator in (COMPARISON.LT, COMPARISON.MAX):
continue # matches = matches and True
matches = matches and operators[f.operator](left, right)
if matches:
yield record
Expand Down
13 changes: 13 additions & 0 deletions kinto/tests/core/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,19 @@ def test_get_all_can_filter_with_strings(self):
self.assertEqual(records[1]['name'], "Marie")
self.assertEqual(len(records), 2)

def test_get_all_can_filter_with_none_values(self):
self.create_record({"name": "Alexis"})
self.create_record({"title": "haha"})
self.create_record({"name": "Mathieu"})
filters = [Filter("name", "Fanny", utils.COMPARISON.GT)]
records, _ = self.storage.get_all(filters=filters, **self.storage_kw)
self.assertEqual(len(records), 1) # None is not greater than "Fanny"
self.assertEqual(records[0]["name"], "Mathieu")

filters = [Filter("name", "Fanny", utils.COMPARISON.LT)]
records, _ = self.storage.get_all(filters=filters, **self.storage_kw)
self.assertEqual(len(records), 2) # None is less than "Fanny"

def test_get_all_can_filter_with_list_of_values_on_id(self):
record1 = self.create_record({'code': 'a'})
record2 = self.create_record({'code': 'b'})
Expand Down
10 changes: 10 additions & 0 deletions kinto/tests/test_views_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ def test_buckets_can_handle_arbitrary_attributes(self):
self.assertIn('public_key', data)
self.assertEqual(data['public_key'], public_key)

def test_buckets_can_be_filtered_by_arbitrary_attribute(self):
bucket = MINIMALIST_BUCKET.copy()
bucket['data'] = {'size': 3}
self.app.put_json('/buckets/beers',
bucket,
headers=self.headers)
resp = self.app.get('/buckets?min_size=2', headers=self.headers)
data = resp.json['data']
self.assertEqual(len(data), 1)


class BucketCreationTest(BaseWebTest, unittest.TestCase):
def test_buckets_can_be_created_with_post(self):
Expand Down
11 changes: 11 additions & 0 deletions kinto/tests/test_views_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ def test_collections_can_handle_arbitrary_attributes(self):
self.assertIn('fingerprint', data)
self.assertEqual(data['fingerprint'], fingerprint)

def test_collections_can_be_filtered_by_arbitrary_attribute(self):
collection = MINIMALIST_COLLECTION.copy()
collection['data'] = {'size': 3}
self.app.put_json('/buckets/beers/collections/moderator',
collection,
headers=self.headers)
resp = self.app.get('/buckets/beers/collections?min_size=2',
headers=self.headers)
data = resp.json['data']
self.assertEqual(len(data), 1)


class CollectionDeletionTest(BaseWebTest, unittest.TestCase):

Expand Down
11 changes: 11 additions & 0 deletions kinto/tests/test_views_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ def test_groups_can_have_arbitrary_attributes(self):
self.assertIn('mailinglist', data)
self.assertEqual(data['mailinglist'], mailinglist)

def test_groups_can_be_filtered_by_arbitrary_attribute(self):
group = MINIMALIST_GROUP.copy()
group['data']['size'] = 3
self.app.put_json('/buckets/beers/groups/moderator',
group,
headers=self.headers)
resp = self.app.get('/buckets/beers/groups?min_size=2',
headers=self.headers)
data = resp.json['data']
self.assertEqual(len(data), 1)

def test_groups_should_reject_unaccepted_request_content_type(self):
headers = self.headers.copy()
headers['Content-Type'] = 'text/plain'
Expand Down
4 changes: 4 additions & 0 deletions kinto/views/buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ def get_parent_id(self, request):
# Buckets are not isolated by user, unlike Kinto-Core resources.
return ''

def is_known_field(self, field_name):
"""Without schema, any field is considered as known."""
return True


@subscriber(ResourceChanged,
for_resources=('bucket',),
Expand Down
4 changes: 4 additions & 0 deletions kinto/views/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ def get_parent_id(self, request):
parent_id = '/buckets/%s' % bucket_id
return parent_id

def is_known_field(self, field_name):
"""Without schema, any field is considered as known."""
return True


@subscriber(ResourceChanged,
for_resources=('collection',),
Expand Down
4 changes: 4 additions & 0 deletions kinto/views/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ def get_parent_id(self, request):
parent_id = '/buckets/%s' % bucket_id
return parent_id

def is_known_field(self, field_name):
"""Without schema, any field is considered as known."""
return True


@subscriber(ResourceChanged,
for_resources=('group',),
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def read_file(filename):


setup(name='kinto',
version='3.2.3.dev0',
version='3.2.3',
description='Kinto Web Service - Store, Sync, Share, and Self-Host.',
long_description=README + "\n\n" + CHANGELOG + "\n\n" + CONTRIBUTORS,
license='Apache License (2.0)',
Expand Down

0 comments on commit 75e15d7

Please sign in to comment.