Review feature and scenario definitions. Removing unnecesary and redundant steps.

This commit is contained in:
Roberto Abdelkader Martínez Pérez
2019-08-23 12:46:10 +02:00
parent 8752f419b5
commit 991ae618bb
13 changed files with 62 additions and 150 deletions
+1 -1
View File
@@ -11,4 +11,4 @@ test: lint
fix: lint fix: lint
KAPOW_DEBUG_TESTS=1 pipenv run behave --stop --no-capture KAPOW_DEBUG_TESTS=1 pipenv run behave --stop --no-capture
catalog: catalog:
pipenv run behave --steps-catalog pipenv run behave --format steps.usage --dry-run --no-summary -q
@@ -10,14 +10,7 @@ Feature: Kapow! server reject append requests with malformed JSON bodies.
Given I have a running Kapow! server Given I have a running Kapow! server
When I try to append with this malformed JSON document: When I try to append with this malformed JSON document:
""" """
{ Hi! I am an invalid JSON document.
"method" "GET",
"url_pattern": /hello,
"entrypoint": null
"command": "echo Hello
World | response /body",
"id": "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"
}
""" """
Then I get 400 as response code Then I get 400 as response code
And I get "Malformed JSON" as response reason phrase And I get "Malformed JSON" as response reason phrase
@@ -1,12 +1,11 @@
Feature: Kapow! server reject responses with semantic errors. Feature: Kapow! server rejects requests with semantic errors.
Kapow! server will reject to append routes when Kapow! server will refuse to append routes when
it receives a valid json document but not conforming it receives a valid json document not conforming
with the specification. to the specification.
Scenario: Error because of lack of mandatory fields. Scenario: Error because lacking mandatory fields.
If a request lacks of any of the mandatory fields If a request lacks any mandatory field the server
the server responds with an error indicating the responds with an error.
missing fields.
Given I have a running Kapow! server Given I have a running Kapow! server
When I append the route: When I append the route:
@@ -19,7 +18,7 @@ Feature: Kapow! server reject responses with semantic errors.
Then I get 422 as response code Then I get 422 as response code
And I get "Invalid Route" as response reason phrase And I get "Invalid Route" as response reason phrase
Scenario: Error because of wrong route specification. Scenario: Error because bad route format.
If a request contains an invalid expression in the If a request contains an invalid expression in the
field url_pattern the server responds with an error. field url_pattern the server responds with an error.
@@ -1,9 +1,9 @@
Feature: Append new routes in Kapow! server. Feature: Append new routes in Kapow! server.
Append routes allow users to configure the server. New Appending routes allows users to configure the server. New
routes are added to the list of existing routes. routes are added at the end of the list of existing routes.
Scenario: Append the first route. Scenario: Append the first route.
A fresh server, just started or with all routes removed, A just started server or one with all routes removed,
will create a new list of routes. The newly created rule will create a new list of routes. The newly created rule
will be at index 0. will be at index 0.
@@ -35,7 +35,7 @@ Feature: Append new routes in Kapow! server.
Appending routes on a non empty list will create new routes Appending routes on a non empty list will create new routes
at the end of the list. at the end of the list.
Given I have a Kapow! server whith the following routes: Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command | | method | url_pattern | entrypoint | command |
| GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body |
| GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
@@ -1,6 +1,6 @@
Feature: Fail to delete a route in Kapow! server. Feature: Fail to delete a route in Kapow! server.
When trying to delete a route in the server, if it When trying to delete a route that not exists in the server
does no exists the server respons with an error. the server respons with an error.
Scenario: Delete a non-existing route. Scenario: Delete a non-existing route.
A request of removing a non-existing route A request of removing a non-existing route
@@ -1,25 +1,23 @@
Feature: Routes auto-ordering after deleting in a Kapow! server. Feature: Consistent route order after a route deletion in Kapow! server.
When deleting routes the server will mantain the When deleting routes the server will mantain the
remaining routes ordered an with consecutive indexes. remaining routes ordered and with consecutive indexes.
Background: Background:
Given I have a Kapow! server whith the following routes: Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command | | method | url_pattern | entrypoint | command |
| GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body |
| GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body | | GET | /listVarDir | /bin/sh -c | ls -la /var \| response /body |
| GET | /listEtcDir | /bin/sh -c | ls -la /etc \| response /body | | GET | /listEtcDir | /bin/sh -c | ls -la /etc \| response /body |
| GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
Scenario: Removing the first routes. Scenario: Removing the first route.
After removing the first route the remaining ones After removing the first route the remaining ones
will maintain their relative order and their indexes will maintain their relative order and their indexes
will be decreased by one. will be decreased by one.
When I delete the first route inserted When I delete the first route
And I request a routes listing And I request a routes listing
Then I get a list with the following elements: Then I get the following response body:
""" """
[ [
{ {
@@ -49,13 +47,13 @@ Feature: Routes auto-ordering after deleting in a Kapow! server.
] ]
""" """
Scenario: Removing the last routes. Scenario: Removing the last route.
After removing the last route the remaining ones will After removing the last route the remaining ones will
maintain their relative order and indexes. maintain their relative order and indexes.
When I delete the last route inserted When I delete the last route
And I request a routes listing And I request a routes listing
Then I get a list with the following elements: Then I get the following response body:
""" """
[ [
{ {
@@ -90,9 +88,9 @@ Feature: Routes auto-ordering after deleting in a Kapow! server.
maintain their relative order and the indexes of the maintain their relative order and the indexes of the
following routes will be decreased by one. following routes will be decreased by one.
When I delete the second route inserted When I delete the second route
And I request a routes listing And I request a routes listing
Then I get a list with the following elements: Then I get the following response body:
""" """
[ [
{ {
@@ -1,11 +1,11 @@
Feature: Delete routes in Kapow! server. Feature: Delete routes in Kapow! server.
Delete routes allow users to remove non-desired Deleting routes allows users to remove undesired
routes from the server. routes from the server.
Scenario: Delete a route. Scenario: Delete a route.
Routes are removed from the sever by specifying their id. Routes are removed from the sever by specifying their id.
Given I have a Kapow! server whith the following routes: Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command | | method | url_pattern | entrypoint | command |
| GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body |
| GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
@@ -1,9 +1,9 @@
Feature: Kapow! server reject insert requests with malformed JSON bodies. Feature: Kapow! server rejects insertion requests with malformed JSON bodies.
Kapow! server will reject to insert a route when Kapow! server will reject to insert a route when
it receives a malformed json document in the it receives a malformed JSON document in the
request body. request body.
Scenario: Error because a malformed JSON document. Scenario: Error because of malformed JSON document.
If a request comes with an invalid JSON document If a request comes with an invalid JSON document
the server will respond with a bad request error. the server will respond with a bad request error.
@@ -1,11 +1,10 @@
Feature: Kapow! server reject insert responses with semantic errors. Feature: Kapow! server rejects insertion responses with semantic errors.
Kapow! server will reject to insert routes when Kapow! server will reject to insert routes when
it receives a valid json but not conforming document. it receives a valid JSON but not conforming document.
Scenario: Error because of lack of mandatory fields. Scenario: Error because lacking mandatory fields.
If a request lacks of any of the mandatory fields If a request lacks any mandatory fields the server
the server responds with an error indicating the responds with an error.
missing fields.
Given I have a running Kapow! server Given I have a running Kapow! server
When I insert the route: When I insert the route:
@@ -18,7 +17,7 @@ Feature: Kapow! server reject insert responses with semantic errors.
Then I get 422 as response code Then I get 422 as response code
And I get "Invalid Route" as response reason phrase And I get "Invalid Route" as response reason phrase
Scenario: Error because of wrong route specification. Scenario: Error because wrong route specification.
If a request contains an invalid expression in the If a request contains an invalid expression in the
url_pattern field the server responds with an error. url_pattern field the server responds with an error.
@@ -1,10 +1,9 @@
Feature: Routes auto-ordering after inserting in a Kapow! server. Feature: Consistent route ordering after inserting a route in a Kapow! server.
When inserting routes the server will mantain the When inserting routes the server will mantain the
whole set of routes ordered an with consecutive indexes. whole set of routes ordered and with consecutive indexes.
Background: Background:
Given I have a Kapow! server whith the following routes: Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command | | method | url_pattern | entrypoint | command |
| GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body |
| GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
@@ -24,23 +23,8 @@ Feature: Routes auto-ordering after inserting in a Kapow! server.
"index": 0 "index": 0
} }
""" """
Then I get 201 as response code And I request a routes listing
And I get "Created" as response reason phrase Then I get the following response body:
And I get the following response body:
"""
{
"method": "GET",
"url_pattern": "/listVarDir",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"index": 0,
"id": ANY
}
"""
When I request a routes listing
Then I get 200 as response code
And I get "OK" as response reason phrase
And I get a list with the following elements:
""" """
[ [
{ {
@@ -84,23 +68,8 @@ Feature: Routes auto-ordering after inserting in a Kapow! server.
"index": 2 "index": 2
} }
""" """
Then I get 201 as response code And I request a routes listing
And I get "Created" as response reason phrase Then I get the following response body:
And I get the following response body:
"""
{
"method": "GET",
"url_pattern": "/listVarDir",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"index": 2,
"id": ANY
}
"""
When I request a routes listing
Then I get 200 as response code
And I get "OK" as response reason phrase
And I get a list with the following elements:
""" """
[ [
{ {
@@ -145,23 +114,8 @@ Feature: Routes auto-ordering after inserting in a Kapow! server.
"index": 1 "index": 1
} }
""" """
Then I get 201 as response code And I request a routes listing
And I get "Created" as response reason phrase Then I get the following response body:
And I get the following response body:
"""
{
"method": "GET",
"url_pattern": "/listVarDir",
"entrypoint": "/bin/sh -c",
"command": "ls -la /var | response /body",
"index": 1,
"id": ANY
}
"""
When I request a routes listing
Then I get 200 as response code
And I get "OK" as response reason phrase
And I get a list with the following elements:
""" """
[ [
{ {
@@ -1,16 +1,16 @@
Feature: Insert new routes in Kapow! server. Feature: Insert new routes in Kapow! server.
Insert routes allow users to configure the server. New Inserting routes allows users to configure the server. New
routes could be inserted at the begining or before any routes could be inserted at the beginning or before any
existing route of the routes list. existing route of the routes list.
Background: Background:
Given I have a Kapow! server whith the following routes: Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command | | method | url_pattern | entrypoint | command |
| GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body |
| GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
Scenario: Insert a route at the beginning. Scenario: Insert a route at the beginning.
A route can be inserted at the begining of the list A route can be inserted at the beginning of the list
by specifying an index 0 in the request. by specifying an index 0 in the request.
When I insert the route: When I insert the route:
@@ -1,30 +1,33 @@
Feature: Listing routes in a Kapow! server Feature: Listing routes in a Kapow! server
Listing routes allow users to know what commands are Listing routes allows users to know what URLs 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. a list of the routes the server has configured.
Scenario: Listing routes on a fresh started server Scenario: List routes on a fresh started server
A fresh server, just started or with all routes removed, A just started or with all routes removed,
will show an empty list of routes. 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 When I request a routes listing
Then I get 200 as response code Then I get 200 as response code
And I get "OK" as response reason phrase And I get "OK" as response reason phrase
And I get an empty list And I get the following response body:
"""
[]
"""
Scenario: Listing routes on a server with routes loaded. Scenario: List routes on a server with routes loaded.
After some route creation/insertion operations the server After some route creation/insertion operations the server
must return an ordered list of routes stored. must return an ordered list of routes stored.
Given I have a Kapow! server whith the following routes: Given I have a Kapow! server with the following routes:
| method | url_pattern | entrypoint | command | | method | url_pattern | entrypoint | command |
| GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body |
| GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body |
When I request a routes listing When I request a routes listing
Then I get 200 as response code Then I get 200 as response code
And I get "OK" as response reason phrase And I get "OK" as response reason phrase
And I get a list with the following elements: And I get the following response body:
""" """
[ [
{ {
+1 -35
View File
@@ -80,13 +80,7 @@ def step_impl(context):
context.response = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes") context.response = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes")
@then('I get an empty list') @given('I have a Kapow! server with the following routes')
def step_impl(context):
context.response.raise_for_status()
assert context.response.json() == []
@given('I have a Kapow! server whith the following routes')
def step_impl(context): def step_impl(context):
run_kapow_server(context) run_kapow_server(context)
@@ -99,13 +93,6 @@ def step_impl(context):
response.raise_for_status() response.raise_for_status()
@then('I get a list with the following elements')
def step_impl(context):
context.response.raise_for_status()
assert is_subset(jsonexample.loads(context.text), context.response.json())
@when('I append the route') @when('I append the route')
def step_impl(context): def step_impl(context):
context.response = requests.post(f"{Env.KAPOW_CONTROLAPI_URL}/routes", context.response = requests.post(f"{Env.KAPOW_CONTROLAPI_URL}/routes",
@@ -133,11 +120,6 @@ def step_impl(context, id):
context.response = requests.delete(f"{Env.KAPOW_CONTROLAPI_URL}/routes/{id}") context.response = requests.delete(f"{Env.KAPOW_CONTROLAPI_URL}/routes/{id}")
@given('It has a route with id "{id}"')
def step_impl(context, id):
raise NotImplementedError('STEP: Given It has a route with id "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx"')
@when('I insert the route') @when('I insert the route')
def step_impl(context): def step_impl(context):
context.response = requests.put(f"{Env.KAPOW_CONTROLAPI_URL}/routes", context.response = requests.put(f"{Env.KAPOW_CONTROLAPI_URL}/routes",
@@ -146,7 +128,6 @@ def step_impl(context):
@when('I try to append with this malformed JSON document') @when('I try to append with this malformed JSON document')
@when('I try to append with this JSON document')
def step_impl(context): def step_impl(context):
context.response = requests.post( context.response = requests.post(
f"{Env.KAPOW_CONTROLAPI_URL}/routes", f"{Env.KAPOW_CONTROLAPI_URL}/routes",
@@ -154,22 +135,7 @@ def step_impl(context):
data=context.text) data=context.text)
# @when('I delete the first route')
# @when('I delete the first route inserted')
# def step_impl(context):
# routes = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes")
# id = routes.json()[0]["id"]
# context.response = requests.delete(f"{Env.KAPOW_CONTROLAPI_URL}/routes/{id}")
# @when('I delete the last route inserted')
# def step_impl(context):
# routes = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes")
# id = routes.json()[-1]["id"]
# context.response = requests.delete(f"{Env.KAPOW_CONTROLAPI_URL}/routes/{id}")
@when('I delete the {order} route') @when('I delete the {order} route')
@when('I delete the {order} route inserted')
def step_impl(context, order): def step_impl(context, order):
idx = {"first": 0, "second": 1, "last": -1}.get(order) idx = {"first": 0, "second": 1, "last": -1}.get(order)
routes = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes") routes = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes")