From b039db214f1e0d3cc84dcb60450c27ddd5c3f5ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9sar=20Gallego=20Rodr=C3=ADguez?= Date: Thu, 29 Aug 2019 10:38:24 +0200 Subject: [PATCH] finished draf implementation of data debug --- .../features/data/handler/success.feature | 7 ++-- spec/test/features/steps/steps.py | 34 ++++++++++++++----- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/spec/test/features/data/handler/success.feature b/spec/test/features/data/handler/success.feature index 27f0d51..cd1b9e0 100644 --- a/spec/test/features/data/handler/success.feature +++ b/spec/test/features/data/handler/success.feature @@ -1,12 +1,13 @@ -Feature: Retrieve a handler resource in Kapow! server. - Users can retrieve handler resources from - the server by specifying the handler id +Feature: Retrieve a resource from a handler in Kapow! server. + Users can retrieve request handler resources + from the server by specifying the handler id and the resource path. Scenario: Retrieve a resource. Get the "request/path" resource for the current request through the handler id. +<<<<<<< HEAD Given I have a Kapow! server with the following testing routes: | method | url_pattern | | GET | /listRootDir | diff --git a/spec/test/features/steps/steps.py b/spec/test/features/steps/steps.py index dcc5f74..31ddf48 100644 --- a/spec/test/features/steps/steps.py +++ b/spec/test/features/steps/steps.py @@ -2,6 +2,7 @@ from contextlib import suppress from time import sleep import json import os +import time import threading import shlex import socket @@ -170,21 +171,38 @@ def step_impl(context, order): context.response = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes/{id}") -@when('I send a background request to the route {route}') +@when('I send a background request to the route "{route}"') def step_imp(context, route): def _back(): - return requests.get(f"{Env.KAPOW_DATAAPI_URL}/{route}") + resource_route = f"{Env.KAPOW_DATAAPI_URL}/{route}" + return requests.get(resource_route) context.background_request = threading.Thread(target=_back) context.background_request.start() -@when('I get the resource {resource} for the current request handler') +@when('I get the resource "{resource}" for the current request handler') def step_imp(context, resource): def retrieve_request_id(): + requests_dir = os.path.exists('/tmp/wip') + while not requests_dir: + time.sleep(1) + requests_dir = os.path.exists('/tmp/wip') + target_count = len(os.listdir('/tmp/wip')) + while target_count <= 0: + time.sleep(1) + target_count = len(os.listdir('/tmp/wip')) target = os.listdir('/tmp/wip')[0] - with open(target, "r") as f: - return f.readline().strip() - background_request_id = retrieve_request_id() - resource = f"/handlers/{background_request_id}/{resource}" - context.response = requests.get(resource) + with open(os.path.join("/tmp/wip", target), "r") as f: + return f.readline().strip() + def remove_request_id(request_id): + os.remove(os.path.join("/tmp/wip", request_id)) + background_request_id = retrieve_request_id() + resource = f"{Env.KAPOW_CONTROLAPI_URL}/handlers/{background_request_id}/{resource}" + context.response = requests.get(resource) + remove_request_id(background_request_id) + + +@then('I get the following raw body') +def step_impl(context): + assert is_subset(context.text.strip(), context.response.text.strip())