コード例 #1
0
def test_product():
    """tests the example function from the ergo README"""
    with ergo("http", f"{__file__}:product"):
        resp = session.get("http://localhost?x=4&y=5")
        assert resp.status_code == 200
        result = resp.json()
        assert result == 20.0
コード例 #2
0
def test_product__ergo_start():
    manifest = {"func": f"{__file__}:product"}
    namespace = {
        "protocol": "http",
    }
    with ergo("start", manifest=manifest, namespace=namespace):
        resp = session.get("http://localhost", params={"x": 2.5, "y": 3})
        assert resp.status_code == 200
        result = resp.json()
        assert result == 7.5
コード例 #3
0
ファイル: test_amqp.py プロジェクト: mattian7741/ergo
def test_error_path(rabbitmq):
    manifest = {
        "func": f"{__file__}:assert_false",
    }
    namespace = {
        "protocol": "amqp",
        "host": AMQP_HOST,
        "exchange": "test_exchange",
        "subtopic": "assert_false.in",
        "pubtopic": "assert_false.out",
    }
    with ergo("start", manifest=manifest, namespace=namespace):
        with pytest.raises(ComponentFailure):
            next(rpc("{}", **manifest, **namespace))
コード例 #4
0
ファイル: test_amqp.py プロジェクト: mattian7741/ergo
def test_product_amqp(rabbitmq):
    manifest = {
        "func": f"{__file__}:product",
    }
    namespace = {
        "protocol": "amqp",
        "host": AMQP_HOST,
        "exchange": "test_exchange",
        "subtopic": "product.in",
        "pubtopic": "product.out",
    }
    with ergo("start", manifest=manifest, namespace=namespace):
        payload = json.dumps({"x": 4, "y": 5})
        result = next(rpc(payload, **manifest, **namespace))
        assert result == {'data': 20.0, 'key': 'out.product', 'log': []}
コード例 #5
0
def test_get_data(getter):
    """assert that ergo flask response data preserves the type and dimensionality of the component function's return
    value"""
    manifest = {"func": f"{__file__}:{getter.__name__}"}
    namespace = {
        "protocol": "http",
    }
    with ergo("start", manifest=manifest, namespace=namespace):
        resp = session.get("http://localhost")
        assert resp.ok
        actual = resp.json()
        if inspect.isgeneratorfunction(getter):
            expected = [i for i in getter()]
        else:
            expected = getter()

        assert actual == expected
コード例 #6
0
ファイル: test_amqp.py プロジェクト: mattian7741/ergo
def test_get_two_dicts(rabbitmq):
    manifest = {
        "func": f"{__file__}:get_two_dicts",
    }
    namespace = {
        "protocol": "amqp",
        "host": AMQP_HOST,
        "exchange": "test_exchange",
        "subtopic": "get_two_dicts.in",
        "pubtopic": "get_two_dicts.out",
    }
    with ergo("start", manifest=manifest, namespace=namespace):
        payload = '{"data": {}}'
        results = rpc(payload, **manifest, **namespace)
        expected = {
            'data': get_two_dicts(),
            'key': 'get_two_dicts.out',
            'log': []
        }
        assert next(results) == expected
コード例 #7
0
def test_product__post_request():
    with ergo("http", f"{__file__}:product"):
        resp = session.post("http://localhost?x=4&y=5")
        assert resp.status_code == 200
        result = resp.json()
        assert result == 20.0