def mock_app_exclude():
    return create_test_app(
        'tests/view_maker_test_files',
        'tests/view_maker_test_files/responses',
        packages=None,
        excluded_path=['/exclude_me'],
    )
Example #2
0
def test_queryparams():
    @flask_transmute.annotate({"name": [str]})
    def return_input_string(name):
        return str(name)

    test_app = create_test_app("/foo", return_input_string)
    resp = test_app.get("/foo?name=testme&name=again")
    assert "testme" in resp.data.decode("UTF-8")
    assert "again" in resp.data.decode("UTF-8")
Example #3
0
def test_route_with_no_type_hints_argument():

    def return_input_string(input_string):
        return input_string

    test_app = create_test_app("/foo", return_input_string)
    assert json.loads(test_app.get("/foo?input_string=testme").data.decode("UTF-8")) == {
        "success": True,
        "result": "testme"
    }
Example #4
0
def test_route_with_no_type_hints_argument():
    def return_input_string(input_string):
        return input_string

    test_app = create_test_app("/foo", return_input_string)
    assert json.loads(
        test_app.get("/foo?input_string=testme").data.decode("UTF-8")) == {
            "success": True,
            "result": "testme"
        }
Example #5
0
def test_or_serializer():
    @flask_transmute.annotate({"either": Or(bool, int)})
    def return_input_string(either):
        return str(type(either))

    test_app = create_test_app("/foo", return_input_string)
    resp = test_app.get("/foo?either=false")
    assert "bool" in resp.data.decode("UTF-8")
    resp = test_app.get("/foo?either=1234")
    assert "int" in resp.data.decode("UTF-8")
Example #6
0
def test_list_body():
    @flask_transmute.annotate({"name": [str]})
    @flask_transmute.updates
    def return_input_string(name):
        return str(name)

    test_app = create_test_app("/foo", return_input_string)
    resp = test_app.post("/foo",
                         data=json.dumps({"name": ["testme", "again"]}))
    assert "testme" in resp.data.decode("UTF-8")
    assert "again" in resp.data.decode("UTF-8")
Example #7
0
def test_route_yaml():
    def return_input_string(input_string):
        return input_string

    test_app = create_test_app("/foo", return_input_string)
    resp = test_app.get("/foo?input_string=testme",
                        headers={"content-type": "application/yaml"})
    assert "success: true" in resp.data.decode("UTF-8")
    assert yaml.load(resp.data.decode("UTF-8")) == {
        "success": True,
        "result": "testme"
    }
Example #8
0
def test_route_with_no_type_hints(ret_val):
    """
    with no type hinting, the serializer should just try to serialize
    to json with json.dumps
    """
    def return_foo():
        return ret_val

    test_app = create_test_app("/foo", return_foo)
    assert json.loads(test_app.get("/foo").data.decode("UTF-8")) == {
        "success": True,
        "result": ret_val
    }
Example #9
0
def test_route_yaml():

    def return_input_string(input_string):
        return input_string

    test_app = create_test_app("/foo", return_input_string)
    resp = test_app.get("/foo?input_string=testme", headers={
        "content-type": "application/yaml"
    })
    assert "success: true" in resp.data.decode("UTF-8")
    assert yaml.load(resp.data.decode("UTF-8")) == {
        "success": True,
        "result": "testme"
    }
Example #10
0
def test_route_with_no_type_hints(ret_val):
    """
    with no type hinting, the serializer should just try to serialize
    to json with json.dumps
    """

    def return_foo():
        return ret_val

    test_app = create_test_app("/foo", return_foo)
    assert json.loads(test_app.get("/foo").data.decode("UTF-8")) == {
        "success": True,
        "result": ret_val
    }
def mock_app():
    return create_test_app(
        'tests/view_maker_test_files',
        'tests/view_maker_test_files/responses',
        packages=[sys.modules[__name__]],
    )