finished draf implementation of data debug

This commit is contained in:
César Gallego Rodríguez
2019-08-29 10:38:24 +02:00
committed by Roberto Abdelkader Martínez Pérez
parent 990cc1ba8f
commit b039db214f
2 changed files with 30 additions and 11 deletions
@@ -1,12 +1,13 @@
Feature: Retrieve a handler resource in Kapow! server. Feature: Retrieve a resource from a handler in Kapow! server.
Users can retrieve handler resources from Users can retrieve request handler resources
the server by specifying the handler id from the server by specifying the handler id
and the resource path. and the resource path.
Scenario: Retrieve a resource. Scenario: Retrieve a resource.
Get the "request/path" resource for the current Get the "request/path" resource for the current
request through the handler id. request through the handler id.
<<<<<<< HEAD
Given I have a Kapow! server with the following testing routes: Given I have a Kapow! server with the following testing routes:
| method | url_pattern | | method | url_pattern |
| GET | /listRootDir | | GET | /listRootDir |
+26 -8
View File
@@ -2,6 +2,7 @@ from contextlib import suppress
from time import sleep from time import sleep
import json import json
import os import os
import time
import threading import threading
import shlex import shlex
import socket import socket
@@ -170,21 +171,38 @@ def step_impl(context, order):
context.response = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes/{id}") 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 step_imp(context, route):
def _back(): 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 = threading.Thread(target=_back)
context.background_request.start() 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 step_imp(context, resource):
def retrieve_request_id(): 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] 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())