Repository: Kinto/kinto

Issue:
Activate POST on collections
```
$ curl -H "Content-Type: application/json" \
          -X POST -d '{"data": {"test": "some_data"}}' --user testuser:abc123 \
          https://kinto.dev.mozaws.net/v1/buckets/test_bucket/collections

{"errno":115,"message":"Method not allowed on this endpoint.","code":405,"error":"Method Not Allowed"}
```



Discussion:
Related #64 


Resolving patch:
diff --git a/kinto/views/collections.py b/kinto/views/collections.py
--- a/kinto/views/collections.py
+++ b/kinto/views/collections.py
@@ -34,7 +34,7 @@ class Options:
 
 
 @resource.register(name='collection',
-                   collection_methods=('GET',),
+                   collection_methods=('GET', 'POST'),
                    collection_path='/buckets/{{bucket_id}}/collections',
                    record_path='/buckets/{{bucket_id}}/collections/{{id}}')
 class Collection(resource.ProtectedResource):


Test patch:
diff --git a/kinto/tests/test_views_collections.py b/kinto/tests/test_views_collections.py
--- a/kinto/tests/test_views_collections.py
+++ b/kinto/tests/test_views_collections.py
@@ -22,10 +22,6 @@ def test_collection_endpoint_lists_them_all(self):
         self.assertEqual(len(records), 1)
         self.assertEqual(records[0]['id'], 'barley')
 
-    def test_collections_do_not_support_post(self):
-        self.app.post(self.collections_url, headers=self.headers,
-                      status=405)
-
     def test_collections_can_be_put_with_simple_name(self):
         self.assertEqual(self.record['id'], 'barley')
 
@@ -107,3 +103,39 @@ def test_records_of_collection_are_deleted_too(self):
         resp = self.app.get('%s/records?_since=0' % self.collection_url,
                             headers=self.headers)
         self.assertEqual(len(resp.json['data']), 0)
+
+
+class CollectionCreationTest(BaseWebTest, unittest.TestCase):
+
+    collections_url = '/buckets/beers/collections'
+
+    def setUp(self):
+        super(CollectionCreationTest, self).setUp()
+        self.app.put_json('/buckets/beers', MINIMALIST_BUCKET,
+                          headers=self.headers)
+
+    def test_collection_can_be_created_with_post(self):
+        r = self.app.post_json(self.collections_url,
+                               MINIMALIST_COLLECTION,
+                               headers=self.headers)
+        self.assertEqual(r.status_code, 201)
+        self.assertTrue(len(r.json['data']['id']) == 8)
+
+    def test_collection_can_be_specified_in_post(self):
+        collection = 'barley'
+        r = self.app.post_json(self.collections_url,
+                               {'data': {'id': collection}},
+                               headers=self.headers)
+        self.assertEqual(r.status_code, 201)
+        self.assertEqual(r.json['data']['id'], collection)
+
+    def test_collection_already_exists_post(self):
+        collection = "barley"
+        self.app.post_json(self.collections_url,
+                           {'data': {'id': collection}},
+                           headers=self.headers)
+        r = self.app.post_json(self.collections_url,
+                               {'data': {'id': collection}},
+                               headers=self.headers)
+        self.assertEqual(r.json['data']['id'], collection)
+        self.assertEqual(r.status_code, 200)