Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose a /collections/ endpoint to deal with collections. #1

Merged
merged 3 commits into from
Feb 27, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/kinto.ini
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ cliquet.retry_after = 30
cliquet.eos =

pyramid.debug_notfound = true
# cliquet.basic_auth_backdoor = true
cliquet.basic_auth_backdoor = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

commit this ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should rename it to basic_auth_activated since it is not really a backdoor anymore but an Auth feature.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, ok, seen the tests

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Natim : fully agree!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I should remove it from here and put it only in the tests.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

# cliquet.backoff = 10
cliquet.userid_hmac_secret = b4c96a8692291d88fe5a97dd91846eb4
# cliquet.batch_max_requests = 25
Expand Down
40 changes: 40 additions & 0 deletions kinto/tests/test_views_collections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from .support import BaseWebTest, unittest
from base64 import b64encode


def get_user_headers(user):
return {
'Authorization': 'Basic {0}'.format(b64encode("%s:secret" % user)),
}


class CollectionViewTest(BaseWebTest, unittest.TestCase):
def test_empty_collection_returns_an_empty_list(self):
response = self.app.get('/collections/barley/records',
headers=self.headers)
self.assertEqual(response.json['items'], [])

def test_individual_collections_can_be_deleted(self):
self.app.post('/collections/barley/records',
headers=self.headers)

self.app.delete('/collections/barley/records',
headers=self.headers)

def test_items_can_be_added_to_collections(self):
response = self.app.post('/collections/barley/records',
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm updating the tests to use a non-empty record.

I'm actually not sure we should support empty records, but I don't see any good reason to not support them.

headers=self.headers)
self.assertIsNotNone(response.json['id'])

def test_collections_are_user_bound(self):
# Add items in the collections.
response = self.app.post('/collections/barley/records',
headers=self.headers)
self.app.get('/collections/barley/records/%s' % response.json['id'],
headers=get_user_headers("alice"), status=404)

def test_collection_items_can_be_accessed_by_id(self):
response = self.app.post('/collections/barley/records',
headers=self.headers)
self.app.get('/collections/barley/records/%s' % response.json['id'],
headers=self.headers)
10 changes: 10 additions & 0 deletions kinto/views/collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from cliquet.resource import crud, BaseResource


@crud(path="/collections/{collection_id}/records/{id}",
collection_path="/collections/{collection_id}/records")
class Collection(BaseResource):

@property
def name(self):
return self.request.matchdict['collection_id']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hard to believe : this is cloud storage :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, cliquet rocks!

We will need a bit more code to handle collections management, plus currently it seems I can only add empty items to the collections (not very handy ;))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, that's because of mozilla-services/cliquet#30

collections management is definitely not a requirement :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat, I know what's next in line then :)