Пример #1
0
    def test_auth_failure(self):
        app = Firefly(auth_token='abcd')
        app.add_route("/", square)

        request = Request.blank("/", POST='{"a": 3}')
        response = app.process_request(request)
        print(response.text)
        assert response.status == '403 Forbidden'

        headers = {"Authorization": "token bad-token"}
        request = Request.blank("/", POST='{"a": 3}', headers=headers)
        response = app.process_request(request)
        assert response.status == '403 Forbidden'
Пример #2
0
    def test_http_error_404(self):
        app = Firefly()
        app.add_route("/", square)

        request = Request.blank("/sq", POST='{"a": 3}')
        response = app.process_request(request)
        assert response.status == '404 Not Found'
Пример #3
0
    def test_function_call(self):
        app = Firefly()
        app.add_route("/", square)

        request = Request.blank("/", POST='{"a": 3}')
        response = app.process_request(request)
        assert response.status == '200 OK'
        assert response.text == '9'
Пример #4
0
    def test_ctx_cross_request(self):
        def peek_ctx():
            print("peek_ctx", ctx.__dict__)
            ctx.count = getattr(ctx, "count", 0) + 1
            return ctx.count

        app = Firefly()
        app.add_route("/", peek_ctx)

        request = Request.blank("/", POST='{}')
        response = app.process_request(request)
        assert response.status == '200 OK'
        assert response.json == 1

        # Subsequent requests should not have count in the context
        request = Request.blank("/", POST='{}')
        response = app.process_request(request)
        assert response.status == '200 OK'
        assert response.json == 1
Пример #5
0
    def test_ctx(self):
        def peek_ctx():
            keys = sorted(ctx.__dict__.keys())
            return list(keys)

        app = Firefly()
        app.add_route("/", peek_ctx)

        request = Request.blank("/", POST='{}')
        response = app.process_request(request)
        assert response.status == '200 OK'
        assert response.json == ['request']