Skip to content

Commit

Permalink
Merge pull request #66 from mozilla-services/65_add_tests_for_permiss…
Browse files Browse the repository at this point in the history
…ion_create

Bug #65 — Add functionnal test about create permissions.
  • Loading branch information
Natim committed Jun 17, 2015
2 parents e603d83 + db093f5 commit 9451923
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
20 changes: 20 additions & 0 deletions kinto/tests/test_views_buckets.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ def test_buckets_name_should_be_simple(self):
headers=self.headers,
status=400)

def test_create_permissions_can_be_added_on_buckets(self):
bucket = MINIMALIST_BUCKET.copy()
bucket['permissions'] = {'collection:create': ['fxa:user'],
'group:create': ['fxa:user']}
resp = self.app.put_json('/buckets/beers',
bucket,
headers=self.headers,
status=200)
permissions = resp.json['permissions']
self.assertIn('fxa:user', permissions['collection:create'])
self.assertIn('fxa:user', permissions['group:create'])

def test_wrong_create_permissions_cannot_be_added_on_buckets(self):
bucket = MINIMALIST_BUCKET.copy()
bucket['permissions'] = {'record:create': ['fxa:user']}
self.app.put_json('/buckets/beers',
bucket,
headers=self.headers,
status=400)


class BucketDeletionTest(BaseWebTest, unittest.TestCase):

Expand Down
18 changes: 18 additions & 0 deletions kinto/tests/test_views_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,24 @@ def test_collections_are_isolated_by_bucket(self):
headers=self.headers)
self.app.get(other_bucket, headers=self.headers, status=404)

def test_create_permissions_can_be_added_on_collections(self):
collection = MINIMALIST_COLLECTION.copy()
collection['permissions'] = {'record:create': ['fxa:user']}
resp = self.app.put_json('/buckets/beers/collections/barley',
collection,
headers=self.headers,
status=200)
permissions = resp.json['permissions']
self.assertIn('fxa:user', permissions['record:create'])

def test_wrong_create_permissions_cannot_be_added_on_collections(self):
collection = MINIMALIST_COLLECTION.copy()
collection['permissions'] = {'collection:create': ['fxa:user']}
self.app.put_json('/buckets/beers/collections/barley',
collection,
headers=self.headers,
status=400)


class CollectionDeletionTest(BaseWebTest, unittest.TestCase):

Expand Down
8 changes: 8 additions & 0 deletions kinto/tests/test_views_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ def test_groups_are_isolated_by_bucket(self):
headers=self.headers)
self.app.get(other_bucket, headers=self.headers, status=404)

def test_wrong_create_permissions_cannot_be_added_on_groups(self):
group = MINIMALIST_GROUP.copy()
group['permissions'] = {'group:create': ['fxa:user']}
self.app.put_json('/buckets/beers/groups/moderator',
group,
headers=self.headers,
status=400)


class GroupManagementTest(BaseWebTest, unittest.TestCase):

Expand Down
8 changes: 8 additions & 0 deletions kinto/tests/test_views_records.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,11 @@ def test_records_can_be_sorted_on_any_field(self):
names = [i['name'] for i in response.json['data']]
self.assertEqual(names,
['Stout 2', 'Stout 1', 'Stout 0', 'Hulled Barley'])

def test_wrong_create_permissions_cannot_be_added_on_records(self):
record = MINIMALIST_RECORD.copy()
record['permissions'] = {'record:create': ['fxa:user']}
self.app.put_json(self.record_url,
record,
headers=self.headers,
status=400)
9 changes: 2 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,14 @@
'cornice',
'six',
'waitress',
'cliquet[postgresql,monitoring]' # > 2.0 once released.
'cliquet[postgresql,monitoring] >= 2.0.0'
]

ENTRY_POINTS = {
'paste.app_factory': [
'main = kinto:main',
]}

DEPENDENCY_LINKS = [
# Pre-release of Cliquet.
'https://github.com/mozilla-services/cliquet/tarball/2.0.dev4#egg=Cliquet-2.0dev4',
]

setup(name='kinto',
version='1.0.0.dev0',
Expand All @@ -47,5 +43,4 @@
include_package_data=True,
zip_safe=False,
install_requires=REQUIREMENTS,
entry_points=ENTRY_POINTS,
dependency_links=DEPENDENCY_LINKS)
entry_points=ENTRY_POINTS)

0 comments on commit 9451923

Please sign in to comment.