Implement feature list success.

This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-08-14 13:19:56 +02:00
parent 4e86cf1ba4
commit bc2b323923
8 changed files with 277 additions and 9 deletions
@@ -1,14 +1,14 @@
Feature: Listing routes in a Kapow server
Feature: Listing routes in a Kapow! server
Listing routes allow users to know what commands are
available on a Kapow server. The List endpoint returns
available on a Kapow! server. The List endpoint returns
a list of the routes the server has configured.
Scenario: Listing routes on a fresh started server
A fresh server, just started or with all routes removed,
will show an empty list of routes.
Given I have a just started Kapow server
Given I have a just started Kapow! server
When I request a routes listing
Then I get an empty list
@@ -16,11 +16,10 @@ Feature: Listing routes in a Kapow server
After some route creation/insertion operations the server
must return an ordered list of routes stored.
Given I have a Kapow server whith this routes appended:
Given I have a Kapow! server whith this routes appended:
| method | url_pattern | entrypoint | command |
| GET | /listRootDir | /bin/sh -c | ls -la / \| response /body |
| GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
When I request a routes listing
Then I get a list with the following elements:
| method | url_pattern | entrypoint | command | index | id |
+4
View File
@@ -0,0 +1,4 @@
def after_scenario(context, scenario):
if hasattr(context, 'server'):
context.server.terminate()
context.server.wait()
+71
View File
@@ -0,0 +1,71 @@
import subprocess
from time import sleep
import requests
from environconfig import EnvironConfig, StringVar
class Env(EnvironConfig):
#: How to run Kapow! server
KAPOW_SERVER_CMD = StringVar(default="kapow server")
#: Where the Control API is
KAPOW_CONTROLAPI_URL = StringVar(default="http://localhost:8081")
#: Where the Data API is
KAPOW_DATAAPI_URL = StringVar(default="http://localhost:8080")
@given('I have a just started Kapow! server')
def step_impl(context):
context.server = subprocess.Popen(
Env.KAPOW_SERVER_CMD,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
shell=True)
is_running = context.server.poll() is None
assert is_running, "Server is not running!"
@when('I request a routes listing')
def step_impl(context):
context.response = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes")
@then('I get an empty list')
def step_impl(context):
context.response.raise_for_status()
assert context.response.json() == []
@given('I have a Kapow! server whith this routes appended')
def step_impl(context):
context.server = subprocess.Popen(
Env.KAPOW_SERVER_CMD,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
shell=True)
is_running = context.server.poll() is None
assert is_running, "Server is not running!"
if not hasattr(context, 'table'):
raise RuntimeError("A table must be set for this step.")
for row in context.table:
response = requests.post(f"{Env.KAPOW_CONTROLAPI_URL}/routes",
json={h: row[h] for h in row.headings})
response.raise_for_status()
@then('I get a list with the following elements')
def step_impl(context):
context.response.raise_for_status()
if not hasattr(context, 'table'):
raise RuntimeError("A table must be set for this step.")
for entry, row in zip(context.response.json(), context.table):
for header in row.headings:
assert header in entry, f"Response does not contain the key {header}"
if row[header] != '*':
assert entry[header] == row[header], f"Values mismatch"