diff --git a/spec/test/Makefile b/spec/test/Makefile index 5820d98..b11f077 100644 --- a/spec/test/Makefile +++ b/spec/test/Makefile @@ -20,4 +20,4 @@ checkbin: @which kapow >/dev/null || (echo "ERROR: Your kapow binary is not present in PATH" && exit 1) testpoc: sync pipenv run pip install -r ../../testutils/poc/requirements.txt - PATH=../../testutils/poc:$$PATH KAPOW_CONTROLAPI_URL=http://localhost:8081 KAPOW_DATAAPI_URL=http://localhost:8081 pipenv run behave --no-capture --tags=~@skip + PATH=../../testutils/poc:$$PATH KAPOW_CONTROL_URL=http://localhost:8081 KAPOW_DATA_URL=http://localhost:8081 pipenv run behave --no-capture --tags=~@skip diff --git a/spec/test/README.rst b/spec/test/README.rst index 7cf4fca..9d7c4b0 100644 --- a/spec/test/README.rst +++ b/spec/test/README.rst @@ -59,8 +59,8 @@ environment variables: * ``KAPOW_BOOT_TIMEOUT``: Timeout in ms for the server to be ready * ``KAPOW_SERVER_CMD``: The full command line to start a non-interactive listening kapow server. By default: ``kapow server`` -* ``KAPOW_CONTROLAPI_URL``: URL of the Control API. By default: ``http://localhost:8081`` -* ``KAPOW_DATAAPI_URL``: URL of the Data API. By default: ``http://localhost:8082`` +* ``KAPOW_CONTROL_URL``: URL of the Control API. By default: ``http://localhost:8081`` +* ``KAPOW_DATA_URL``: URL of the Data API. By default: ``http://localhost:8082`` * ``KAPOW_USER_URL``: URL of the User Server. By default: ``http://localhost:8080`` diff --git a/spec/test/features/steps/steps.py b/spec/test/features/steps/steps.py index 4fc6ffb..f16468a 100644 --- a/spec/test/features/steps/steps.py +++ b/spec/test/features/steps/steps.py @@ -44,10 +44,10 @@ class Env(EnvironConfig): KAPOW_SERVER_CMD = StringVar(default="kapow server") #: Where the Control API is - KAPOW_CONTROLAPI_URL = StringVar(default="http://localhost:8081") + KAPOW_CONTROL_URL = StringVar(default="http://localhost:8081") #: Where the Data API is - KAPOW_DATAAPI_URL = StringVar(default="http://localhost:8082") + KAPOW_DATA_URL = StringVar(default="http://localhost:8082") #: Where the User Interface is KAPOW_USER_URL = StringVar(default="http://localhost:8080") @@ -91,8 +91,8 @@ def run_kapow_server(context): assert is_running, "Server is not running!" with suppress(requests.exceptions.ConnectionError): open_ports = ( - requests.head(Env.KAPOW_CONTROLAPI_URL, timeout=1).status_code - and requests.head(Env.KAPOW_DATAAPI_URL, timeout=1).status_code) + requests.head(Env.KAPOW_CONTROL_URL, timeout=1).status_code + and requests.head(Env.KAPOW_DATA_URL, timeout=1).status_code) if open_ports: break sleep(.01) @@ -107,7 +107,7 @@ def step_impl(context): @when('I request a routes listing') def step_impl(context): - context.response = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes") + context.response = requests.get(f"{Env.KAPOW_CONTROL_URL}/routes") @given('I have a Kapow! server with the following routes') @@ -118,7 +118,7 @@ def step_impl(context): raise RuntimeError("A table must be set for this step.") for row in context.table: - response = requests.post(f"{Env.KAPOW_CONTROLAPI_URL}/routes", + response = requests.post(f"{Env.KAPOW_CONTROL_URL}/routes", json={h: row[h] for h in row.headings}) response.raise_for_status() @@ -132,7 +132,7 @@ def step_impl(context): for row in context.table: response = requests.post( - f"{Env.KAPOW_CONTROLAPI_URL}/routes", + f"{Env.KAPOW_CONTROL_URL}/routes", json={"entrypoint": " ".join( [sys.executable, shlex.quote(os.path.join(HERE, "testinghandler.py")), @@ -170,7 +170,7 @@ def step_impl(context): @when('I append the route') def step_impl(context): - context.response = requests.post(f"{Env.KAPOW_CONTROLAPI_URL}/routes", + context.response = requests.post(f"{Env.KAPOW_CONTROL_URL}/routes", data=context.text, headers={"Content-Type": "application/json"}) @@ -212,12 +212,12 @@ def step_impl(context): @when('I delete the route with id "{id}"') def step_impl(context, id): - context.response = requests.delete(f"{Env.KAPOW_CONTROLAPI_URL}/routes/{id}") + context.response = requests.delete(f"{Env.KAPOW_CONTROL_URL}/routes/{id}") @when('I insert the route') def step_impl(context): - context.response = requests.put(f"{Env.KAPOW_CONTROLAPI_URL}/routes", + context.response = requests.put(f"{Env.KAPOW_CONTROL_URL}/routes", headers={"Content-Type": "application/json"}, data=context.text) @@ -225,7 +225,7 @@ def step_impl(context): @when('I try to append with this malformed JSON document') def step_impl(context): context.response = requests.post( - f"{Env.KAPOW_CONTROLAPI_URL}/routes", + f"{Env.KAPOW_CONTROL_URL}/routes", headers={"Content-Type": "application/json"}, data=context.text) @@ -233,29 +233,29 @@ def step_impl(context): @when('I delete the {order} route') def step_impl(context, order): idx = WORD2POS.get(order) - routes = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes") + routes = requests.get(f"{Env.KAPOW_CONTROL_URL}/routes") id = routes.json()[idx]["id"] - context.response = requests.delete(f"{Env.KAPOW_CONTROLAPI_URL}/routes/{id}") + context.response = requests.delete(f"{Env.KAPOW_CONTROL_URL}/routes/{id}") @when('I try to insert with this JSON document') def step_impl(context): context.response = requests.put( - f"{Env.KAPOW_CONTROLAPI_URL}/routes", + f"{Env.KAPOW_CONTROL_URL}/routes", headers={"Content-Type": "application/json"}, data=context.text) @when('I get the route with id "{id}"') def step_impl(context, id): - context.response = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes/{id}") + context.response = requests.get(f"{Env.KAPOW_CONTROL_URL}/routes/{id}") @when('I get the {order} route') def step_impl(context, order): idx = WORD2POS.get(order) - routes = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes") + routes = requests.get(f"{Env.KAPOW_CONTROL_URL}/routes") id = routes.json()[idx]["id"] - context.response = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes/{id}") + context.response = requests.get(f"{Env.KAPOW_CONTROL_URL}/routes/{id}") @when('I get the resource "{resource}"') @@ -265,13 +265,13 @@ def step_impl(context, resource, handler_id=None): handler_id = context.testing_handler_id context.response = requests.get( - f"{Env.KAPOW_DATAAPI_URL}/handlers/{handler_id}{resource}") + f"{Env.KAPOW_DATA_URL}/handlers/{handler_id}{resource}") @when('I set the resource "{resource}" with value "{value}"') def step_impl(context, resource, value): context.response = requests.put( - f"{Env.KAPOW_DATAAPI_URL}/handlers/{context.testing_handler_id}{resource}", + f"{Env.KAPOW_DATA_URL}/handlers/{context.testing_handler_id}{resource}", data=value.encode("utf-8")) diff --git a/spec/test/kapow/Dockerfile b/spec/test/kapow/Dockerfile new file mode 100644 index 0000000..fab43b5 --- /dev/null +++ b/spec/test/kapow/Dockerfile @@ -0,0 +1,3 @@ +FROM kapow-spec-test +ADD https://github.com/BBVA/kapow/releases/download/v0.5.4/kapow_0.5.4_linux_amd64 /usr/bin/kapow +RUN chmod 755 /usr/bin/kapow diff --git a/testutils/poc/kapow b/testutils/poc/kapow index cd09f55..c3a4519 100755 --- a/testutils/poc/kapow +++ b/testutils/poc/kapow @@ -255,8 +255,8 @@ def handle_route(entrypoint, command): shell_task = await asyncio.create_subprocess_shell( args, env={**os.environ, - "KAPOW_DATAAPI_URL": "http://localhost:8081", - "KAPOW_CONTROLAPI_URL": "http://localhost:8081", + "KAPOW_DATA_URL": "http://localhost:8081", + "KAPOW_CONTROL_URL": "http://localhost:8081", "KAPOW_HANDLER_ID": id }, stdin=asyncio.subprocess.DEVNULL) @@ -426,8 +426,8 @@ async def run_init_script(app, scripts, interactive): cmd, executable="/bin/bash", env={**os.environ, - "KAPOW_DATAAPI_URL": "http://localhost:8081", - "KAPOW_CONTROLAPI_URL": "http://localhost:8081" + "KAPOW_DATA_URL": "http://localhost:8081", + "KAPOW_CONTROL_URL": "http://localhost:8081" }) await shell_task.wait() @@ -554,7 +554,7 @@ def route(): @click.option("-c", "--command", nargs=1) @click.option("-e", "--entrypoint", default="/bin/sh -c") @click.option("-X", "--method", default="GET") -@click.option("--url", envvar='KAPOW_CONTROLAPI_URL') +@click.option("--url", envvar='KAPOW_CONTROL_URL') @click.argument("url_pattern", nargs=1) @click.argument("command_file", required=False) def route_add(url_pattern, entrypoint, command, method, url, command_file): @@ -582,7 +582,7 @@ def route_add(url_pattern, entrypoint, command, method, url, command_file): @route.command("remove") -@click.option("--url", envvar='KAPOW_CONTROLAPI_URL') +@click.option("--url", envvar='KAPOW_CONTROL_URL') @click.argument("route-id") def route_remove(route_id, url): response = requests.delete(f"{url}/routes/{route_id}") @@ -590,7 +590,7 @@ def route_remove(route_id, url): @route.command("list") -@click.option("--url", envvar='KAPOW_CONTROLAPI_URL') +@click.option("--url", envvar='KAPOW_CONTROL_URL') @click.argument("route-id", nargs=1, required=False, default=None) def route_list(route_id, url): if route_id is None: @@ -602,7 +602,7 @@ def route_list(route_id, url): @kapow.command("set", help="Set data from the current context") -@click.option("--url", envvar='KAPOW_DATAAPI_URL') +@click.option("--url", envvar='KAPOW_DATA_URL') @click.option("--handler-id", envvar='KAPOW_HANDLER_ID') @click.argument("path", nargs=1) @click.argument("value", required=False) @@ -622,7 +622,7 @@ def kapow_set(url, handler_id, path, value): @kapow.command("get", help="Get data from the current context") -@click.option("--url", envvar='KAPOW_DATAAPI_URL') +@click.option("--url", envvar='KAPOW_DATA_URL') @click.option("--handler-id", envvar='KAPOW_HANDLER_ID') @click.argument("path", nargs=1) def kapow_get(url, handler_id, path):