def test_needs_an_authorization_header(self): response = self.app.post( '/foo', data='[]', ) assert_that(response, is_unauthorized()) assert_that(response, is_error_response())
def test_needs_an_authorization_header(self): response = self.app.post( '/foo', data='[]', ) assert_that( response, is_unauthorized()) assert_that( response, is_error_response())
def test_needs_an_authorization_header_even_if_no_token_is_configured(self): response = self.app.post( '/foo', data='[]', ) assert_that( response, is_unauthorized()) assert_that( response, is_error_response())
def test_request_must_be_json(self): response = self.app.post( '/foo', data='foobar', headers=[('Authorization', 'Bearer foo-bearer-token')], ) assert_that(response, is_bad_request()) assert_that(response, is_error_response())
def test_exception_handling(self, storage, statsd): storage.alive.side_effect = ValueError("BOOM") response = self.app.get("/_status") assert_that(response, has_status(500)) assert_that(response, is_error_response()) statsd.incr.assert_called_with("write.error", data_set="/_status")
def test_request_must_be_json(self): response = self.app.post( '/foo', data='foobar', headers=[('Authorization', 'Bearer foo-bearer-token')], ) assert_that( response, is_bad_request()) assert_that( response, is_error_response(json.dumps(["ValidationError('Expected header: Content-type: application/json',)"])))
def test_authorization_header_must_be_correct_format(self): response = self.app.post( '/foo', data='[]', headers=[('Authorization', 'Bearer')], ) assert_that( response, is_unauthorized()) assert_that( response, is_error_response())
def test_authorization_header_must_be_correct_format(self): response = self.app.post( '/foo', data='[]', headers=[('Authorization', 'Bearer')], ) assert_that(response, is_unauthorized()) assert_that(response, is_error_response())
def test_exception_handling(self, db, statsd): db.alive.side_effect = ValueError("BOOM") response = self.app.get("/_status") assert_that(response, has_status(500)) assert_that(response, is_error_response()) statsd.incr.assert_called_with("write.error", bucket="/_status")
def test_needs_an_authorization_header_even_if_no_token_is_configured( self): response = self.app.post( '/foo', data='[]', ) assert_that(response, is_unauthorized()) assert_that(response, is_error_response())
def test_request_must_be_json(self): response = self.app.post( '/foo', data='foobar', headers=[('Authorization', 'Bearer foo-bearer-token')], ) assert_that( response, is_bad_request()) assert_that( response, is_error_response())
def test_authorization_header_must_match_server_side_value(self): response = self.app.post( '/foo', data='[]', headers=[('Authorization', 'Bearer not-foo-bearer-token')], ) assert_that( response, is_unauthorized()) assert_that( response, is_error_response())
def test_authorization_header_must_match_server_side_value(self): response = self.app.post( '/foo', data='[]', headers=[('Authorization', 'Bearer not-foo-bearer-token')], ) assert_that(response, is_unauthorized()) assert_that(response, is_error_response())
def test_data_with_empty_keys_400s(self): response = self.app.post( '/foo_data_set', data='{"": ""}', content_type="application/json", headers=[('Authorization', 'Bearer foo_data_set-bearer-token')], ) assert_that(response, is_bad_request()) assert_that(response, is_error_response())
def test_data_with_empty_keys_400s(self): response = self.app.post( "/foo_bucket", data='{"": ""}', content_type="application/json", headers=[("Authorization", "Bearer foo_bucket-bearer-token")], ) assert_that(response, is_bad_request()) assert_that(response, is_error_response())
def test_bucket_name_validation(self): response = self.app.post( "/_foo_bucket", data='{"foo": "bar"}', content_type="application/json", headers=[("Authorization", "Bearer _foo_bucket-bearer-token")], ) assert_that(response, is_not_found()) assert_that(response, is_error_response())
def test_bucket_name_validation(self): response = self.app.post( '/_foo_bucket', data='{"foo": "bar"}', content_type="application/json", headers=[('Authorization', 'Bearer _foo_bucket-bearer-token')], ) assert_that(response, is_bad_request()) assert_that(response, is_error_response())
def test_invalid__id_returns_400(self): response = self.app.post( "/foo", data='{"_id": "f o o"}', content_type="application/json", headers=[("Authorization", "Bearer foo-bearer-token")], ) assert_that(response, is_bad_request()) assert_that(response, is_error_response())
def test_bucket_name_validation(self): response = self.app.post( '/_foo_bucket', data = '{"foo": "bar"}', content_type = "application/json", headers=[('Authorization', 'Bearer _foo_bucket-bearer-token')], ) assert_that( response, is_bad_request() ) assert_that( response, is_error_response())
def test_invalid__id_returns_400(self): response = self.app.post( '/foo', data='{"_id": "f o o"}', content_type="application/json", headers=[('Authorization', 'Bearer foo-bearer-token')], ) assert_that(response, is_bad_request()) assert_that(response, is_error_response())
def test_exception_handling(self, parse_and_store, statsd): parse_and_store.side_effect = RuntimeError("BOOM") response = self.app.post( "/foo", data="{}", content_type="application/json", headers=[("Authorization", "Bearer foo-bearer-token")] ) assert_that(response, has_status(500)) assert_that(response, is_error_response()) statsd.incr.assert_called_with("write.error", bucket="foo")
def test_exception_handling(self, bucket_is_valid, statsd): bucket_is_valid.side_effect = ValueError("BOOM") response = self.app.post("/foo", data={'foo': 'bar'}, content_type='application/json', headers=[('Authorization', 'Bearer foo-bearer-token')]) assert_that(response, has_status(500)) assert_that(response, is_error_response()) statsd.incr.assert_called_with("write.error", bucket="foo")
def test_exception_handling(self, store, statsd): store.side_effect = RuntimeError("BOOM") response = self.app.post("/foo", data="{}", content_type='application/json', headers=[('Authorization', 'Bearer foo-bearer-token')]) assert_that(response, has_status(500)) assert_that(response, is_error_response()) statsd.incr.assert_called_with("write.error", data_set="foo")
def test_exception_handling(self, bucket_is_valid, statsd): bucket_is_valid.side_effect = ValueError("BOOM") response = self.app.post( "/foo", data={'foo': 'bar'}, content_type='application/json', headers=[('Authorization', 'Bearer foo-bearer-token')] ) assert_that(response, has_status(500)) assert_that(response, is_error_response()) statsd.incr.assert_called_with("write.error", bucket="foo")
def test_request_must_be_json(self): response = self.app.post( '/foo', data='foobar', headers=[('Authorization', 'Bearer foo-bearer-token')], ) assert_that(response, is_bad_request()) assert_that( response, is_error_response( json.dumps([ "ValidationError('Expected header: Content-type: application/json',)" ])))
def test_authorization_header_must_match_server_side_value(self): response = self.app.post("/foo", data="[]", headers=[("Authorization", "Bearer not-foo-bearer-token")]) assert_that(response, is_unauthorized()) assert_that(response, is_error_response())
def test_authorization_header_must_be_correct_format(self): response = self.app.post("/foo", data="[]", headers=[("Authorization", "Bearer")]) assert_that(response, is_unauthorized()) assert_that(response, is_error_response())
def test_request_must_be_json(self): response = self.app.post("/foo", data="foobar", headers=[("Authorization", "Bearer foo-bearer-token")]) assert_that(response, is_bad_request()) assert_that(response, is_error_response())