Exemplo n.º 1
0
    def test_needs_an_authorization_header(self):
        response = self.app.post(
            '/foo',
            data='[]',
        )

        assert_that(response, is_unauthorized())
        assert_that(response, is_error_response())
Exemplo n.º 2
0
    def test_needs_an_authorization_header(self):
        response = self.app.post(
            '/foo',
            data='[]',
        )

        assert_that( response, is_unauthorized())
        assert_that( response, is_error_response())
Exemplo n.º 3
0
    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())
Exemplo n.º 4
0
    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())
Exemplo n.º 5
0
    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")
Exemplo n.º 6
0
    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',)"])))
Exemplo n.º 7
0
    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())
Exemplo n.º 8
0
    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())
Exemplo n.º 9
0
    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")
Exemplo n.º 10
0
    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())
Exemplo n.º 11
0
    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())
Exemplo n.º 12
0
    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())
Exemplo n.º 13
0
    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())
Exemplo n.º 14
0
    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())
Exemplo n.º 15
0
    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())
Exemplo n.º 16
0
    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())
Exemplo n.º 17
0
    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())
Exemplo n.º 18
0
    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())
Exemplo n.º 19
0
    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())
Exemplo n.º 20
0
    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())
Exemplo n.º 21
0
    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")
Exemplo n.º 22
0
    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")
Exemplo n.º 23
0
    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")
Exemplo n.º 24
0
    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")
Exemplo n.º 25
0
    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',)"
                ])))
Exemplo n.º 26
0
    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())
Exemplo n.º 27
0
    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())
Exemplo n.º 28
0
    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())