-
Notifications
You must be signed in to change notification settings - Fork 422
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
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'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hard to believe : this is cloud storage :) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ;)) There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat, I know what's next in line then :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
commit this ?
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Natim : fully agree!
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Created mozilla-services/cliquet#31