Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Allow empty valid json objects in write api #31

Merged
merged 2 commits into from

2 participants

@robyoung
Owner

Previously empty arrays or empty objects would cause a 400 because
they're falsy.

robyoung and others added some commits
@robyoung robyoung Allow empty valid json objects in write api
Previously empty arrays or empty objects would cause a 400 because
they're falsy.
2c2e8f0
@gtrogers gtrogers Rename test 4d7a2f1
@gtrogers

Renamed the test because we aren't checking that an empty list gets stored, only that our validation doesn't bounce it.

@gtrogers gtrogers merged commit 7958843 into master

1 check failed

Details default Build #128 is running on Jenkins
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Apr 3, 2013
  1. @robyoung

    Allow empty valid json objects in write api

    robyoung authored
    Previously empty arrays or empty objects would cause a 400 because
    they're falsy.
  2. @gtrogers

    Rename test

    gtrogers authored
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 1 deletion.
  1. +1 −1  backdrop/write/api.py
  2. +12 −0 tests/write/test_flask_integration.py
View
2  backdrop/write/api.py
@@ -66,7 +66,7 @@ def health_check():
@app.route('/<bucket_name>', methods=['POST'])
def post_to_bucket(bucket_name):
- if not request.json:
+ if request.json is None:
app.logger.error("Request must be JSON")
return jsonify(status='error', message='Request must be JSON'), 400
View
12 tests/write/test_flask_integration.py
@@ -25,6 +25,18 @@ def test_request_must_be_json(self):
assert_that( response, is_error_response())
@patch("backdrop.core.bucket.Bucket.store")
+ def test_empty_list_gets_accepted(self, store):
+ self.app.post(
+ '/foo-bucket',
+ data='[]',
+ content_type="application/json"
+ )
+
+ store.assert_called_with(
+ []
+ )
+
+ @patch("backdrop.core.bucket.Bucket.store")
def test_data_gets_stored(self, store):
self.app.post(
'/foo-bucket',
Something went wrong with that request. Please try again.