Skip to content
This repository has been archived by the owner on Mar 24, 2021. It is now read-only.

Commit

Permalink
Merge pull request #338 from alphagov/remove-create-route
Browse files Browse the repository at this point in the history
Remove create data set route
  • Loading branch information
nick-gravgaard committed Aug 4, 2014
2 parents 9f78f8e + c300c16 commit cbe1d57
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 97 deletions.
27 changes: 0 additions & 27 deletions backdrop/write/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,33 +175,6 @@ def post_to_data_set(data_set_name):
abort(400, repr(e))


@app.route('/data-sets/<data_set_name>', methods=['POST'])
@cache_control.nocache
@statsd.timer('write.route.create_data_set')
def create_collection_for_data_set(data_set_name):
if not _allow_create_collection(request.headers.get('Authorization')):
abort(401,
'Unauthorized: invalid or '
'no token given for "{}".'.format(data_set_name))

if storage.data_set_exists(data_set_name):
abort(400, 'Collection exists with name "{}".'.format(data_set_name))

try:
data = json.loads(request.data)
except ValueError as e:
abort(400, repr(e))
else:
capped_size = data.get('capped_size', None)

if capped_size is None or not isinstance(capped_size, int):
abort(400, 'You must specify an int capped_size of 0 or more')

storage.create_data_set(data_set_name, capped_size)

return jsonify(status='ok', message='Created "{}"'.format(data_set_name))


@app.route('/data-sets/<data_set_name>', methods=['DELETE'])
@cache_control.nocache
@statsd.timer('write.route.delete_data_set')
Expand Down
63 changes: 0 additions & 63 deletions features/write_api/create_collection.feature

This file was deleted.

13 changes: 8 additions & 5 deletions features/write_api/delete_data_set.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ Feature: delete_data_set
@delete_things
Scenario: deleting a data-set
Given I have a data_set named "some-dataset" with settings
| key | value |
and I have JSON data '{"capped_size": 4096}'
and I have the bearer token "dev-create-endpoint-token"
when I POST to the specific path "/data-sets/some-dataset"
then the collection called "some-dataset" should exist
| key | value |
| data_group | "data-group" |
| data_type | "data-type" |
and I have JSON data '{"foo":"bar"}'
and I use the bearer token for the data_set
when I POST to the specific path "/data/data-group/data-type"
then I should get back a status of "200"
given I have the bearer token "dev-create-endpoint-token"
when I send a DELETE request to "/data-sets/some-dataset"
then I should get back a status of "200"
and I should get back the message "Deleted some-dataset"
Expand Down
17 changes: 15 additions & 2 deletions tests/write/test_flask_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,15 +87,28 @@ def test_empty_list_gets_accepted(self, store):
def test_data_gets_stored(self, store):
self.app.post(
'/foo_data_set',
data = '{"foo": "bar"}',
content_type = "application/json",
data='{"foo": "bar"}',
content_type="application/json",
headers=[('Authorization', 'Bearer foo_data_set-bearer-token')],
)

store.assert_called_with(
[{"foo": "bar"}]
)

@fake_data_set_exists("foo_data_set", bearer_token="foo_data_set-bearer-token")
@patch("backdrop.core.data_set.DataSet.create_if_not_exists")
@patch("backdrop.core.data_set.DataSet.store")
def test_data_set_is_created_on_write(self, store, create_if_not_exists):
self.app.post(
'/foo_data_set',
data='{"foo": "bar"}',
content_type="application/json",
headers=[("Authorization", "Bearer foo_data_set-bearer-token")],
)

create_if_not_exists.assert_called_once_with()

@fake_data_set_exists("foo_data_set", bearer_token="foo_data_set-bearer-token")
def test_data_with_empty_keys_400s(self):
response = self.app.post(
Expand Down

0 comments on commit cbe1d57

Please sign in to comment.