示例#1
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'
示例#2
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'
示例#3
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']
示例#4
0
 def test_generate_function_list_for_func_name(self):
     firefly = Firefly()
     firefly.add_route("/sq2", square, "sq")
     returned_dict = {
         "sq": {
             "path": "/sq2",
             "doc": "Computes square",
             "parameters": [{
                 "name": "a",
                 "kind": "POSITIONAL_OR_KEYWORD"
             }]
         }
     }
     assert firefly.generate_function_list() == returned_dict
示例#5
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'
示例#6
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