From 991ae618bb331fbf742ba60e5b158f1f179ff0b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roberto=20Abdelkader=20Mart=C3=ADnez=20P=C3=A9rez?= Date: Fri, 23 Aug 2019 12:46:10 +0200 Subject: [PATCH] Review feature and scenario definitions. Removing unnecesary and redundant steps. --- spec/test/Makefile | 2 +- .../control/append/error_malformed.feature | 9 +-- .../append/error_unprocessable.feature | 17 +++-- .../features/control/append/success.feature | 8 +-- .../control/delete/error_notfound.feature | 4 +- .../control/delete/list_order.feature | 24 ++++--- .../features/control/delete/success.feature | 4 +- .../control/insert/error_malformed.feature | 6 +- .../insert/error_unprocessable.feature | 13 ++-- .../control/insert/list_order.feature | 64 +++---------------- .../features/control/insert/success.feature | 8 +-- .../features/control/list/success.feature | 17 +++-- spec/test/features/steps/steps.py | 36 +---------- 13 files changed, 62 insertions(+), 150 deletions(-) diff --git a/spec/test/Makefile b/spec/test/Makefile index fb7244e..9fa04a6 100644 --- a/spec/test/Makefile +++ b/spec/test/Makefile @@ -11,4 +11,4 @@ test: lint fix: lint KAPOW_DEBUG_TESTS=1 pipenv run behave --stop --no-capture catalog: - pipenv run behave --steps-catalog + pipenv run behave --format steps.usage --dry-run --no-summary -q diff --git a/spec/test/features/control/append/error_malformed.feature b/spec/test/features/control/append/error_malformed.feature index 772b063..d2ee083 100644 --- a/spec/test/features/control/append/error_malformed.feature +++ b/spec/test/features/control/append/error_malformed.feature @@ -10,14 +10,7 @@ Feature: Kapow! server reject append requests with malformed JSON bodies. Given I have a running Kapow! server When I try to append with this malformed JSON document: """ - { - "method" "GET", - "url_pattern": /hello, - "entrypoint": null - "command": "echo Hello - World | response /body", - "id": "xxxxxxxx-xxxx-Mxxx-Nxxx-xxxxxxxxxxxx" - } + Hi! I am an invalid JSON document. """ Then I get 400 as response code And I get "Malformed JSON" as response reason phrase diff --git a/spec/test/features/control/append/error_unprocessable.feature b/spec/test/features/control/append/error_unprocessable.feature index eade7c3..29eb180 100644 --- a/spec/test/features/control/append/error_unprocessable.feature +++ b/spec/test/features/control/append/error_unprocessable.feature @@ -1,12 +1,11 @@ -Feature: Kapow! server reject responses with semantic errors. - Kapow! server will reject to append routes when - it receives a valid json document but not conforming - with the specification. +Feature: Kapow! server rejects requests with semantic errors. + Kapow! server will refuse to append routes when + it receives a valid json document not conforming + to the specification. - Scenario: Error because of lack of mandatory fields. - If a request lacks of any of the mandatory fields - the server responds with an error indicating the - missing fields. + Scenario: Error because lacking mandatory fields. + If a request lacks any mandatory field the server + responds with an error. Given I have a running Kapow! server When I append the route: @@ -19,7 +18,7 @@ Feature: Kapow! server reject responses with semantic errors. Then I get 422 as response code 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 field url_pattern the server responds with an error. diff --git a/spec/test/features/control/append/success.feature b/spec/test/features/control/append/success.feature index 273d4bd..19da9a6 100644 --- a/spec/test/features/control/append/success.feature +++ b/spec/test/features/control/append/success.feature @@ -1,9 +1,9 @@ Feature: Append new routes in Kapow! server. - Append routes allow users to configure the server. New - routes are added to the list of existing routes. + Appending routes allows users to configure the server. New + routes are added at the end of the list of existing routes. 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 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 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 | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | diff --git a/spec/test/features/control/delete/error_notfound.feature b/spec/test/features/control/delete/error_notfound.feature index 3fae753..f4ccda0 100644 --- a/spec/test/features/control/delete/error_notfound.feature +++ b/spec/test/features/control/delete/error_notfound.feature @@ -1,6 +1,6 @@ Feature: Fail to delete a route in Kapow! server. - When trying to delete a route in the server, if it - does no exists the server respons with an error. + When trying to delete a route that not exists in the server + the server respons with an error. Scenario: Delete a non-existing route. A request of removing a non-existing route diff --git a/spec/test/features/control/delete/list_order.feature b/spec/test/features/control/delete/list_order.feature index 6228f37..b093401 100644 --- a/spec/test/features/control/delete/list_order.feature +++ b/spec/test/features/control/delete/list_order.feature @@ -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 - remaining routes ordered an with consecutive indexes. + remaining routes ordered and with consecutive indexes. 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 | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | | GET | /listVarDir | /bin/sh -c | ls -la /var \| 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 | - Scenario: Removing the first routes. - + Scenario: Removing the first route. After removing the first route the remaining ones will maintain their relative order and their indexes will be decreased by one. - When I delete the first route inserted + When I delete the first route 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 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 - 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 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 - Then I get a list with the following elements: + Then I get the following response body: """ [ { diff --git a/spec/test/features/control/delete/success.feature b/spec/test/features/control/delete/success.feature index 7afcc21..b89147b 100644 --- a/spec/test/features/control/delete/success.feature +++ b/spec/test/features/control/delete/success.feature @@ -1,11 +1,11 @@ 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. Scenario: Delete a route. 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 | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | diff --git a/spec/test/features/control/insert/error_malformed.feature b/spec/test/features/control/insert/error_malformed.feature index 4b50e94..86e9461 100644 --- a/spec/test/features/control/insert/error_malformed.feature +++ b/spec/test/features/control/insert/error_malformed.feature @@ -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 - it receives a malformed json document in the + it receives a malformed JSON document in the 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 the server will respond with a bad request error. diff --git a/spec/test/features/control/insert/error_unprocessable.feature b/spec/test/features/control/insert/error_unprocessable.feature index 390ff0e..c8b984d 100644 --- a/spec/test/features/control/insert/error_unprocessable.feature +++ b/spec/test/features/control/insert/error_unprocessable.feature @@ -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 - 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. - If a request lacks of any of the mandatory fields - the server responds with an error indicating the - missing fields. + Scenario: Error because lacking mandatory fields. + If a request lacks any mandatory fields the server + responds with an error. Given I have a running Kapow! server 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 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 url_pattern field the server responds with an error. diff --git a/spec/test/features/control/insert/list_order.feature b/spec/test/features/control/insert/list_order.feature index 058639f..e16218b 100644 --- a/spec/test/features/control/insert/list_order.feature +++ b/spec/test/features/control/insert/list_order.feature @@ -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 - whole set of routes ordered an with consecutive indexes. + whole set of routes ordered and with consecutive indexes. 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 | | GET | /listRootDir | /bin/sh -c | ls -la / \| 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 } """ - Then I get 201 as response code - And I get "Created" as response reason phrase - 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: + And I request a routes listing + Then I get the following response body: """ [ { @@ -84,23 +68,8 @@ Feature: Routes auto-ordering after inserting in a Kapow! server. "index": 2 } """ - Then I get 201 as response code - And I get "Created" as response reason phrase - 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: + And I request a routes listing + Then I get the following response body: """ [ { @@ -145,23 +114,8 @@ Feature: Routes auto-ordering after inserting in a Kapow! server. "index": 1 } """ - Then I get 201 as response code - And I get "Created" as response reason phrase - 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: + And I request a routes listing + Then I get the following response body: """ [ { diff --git a/spec/test/features/control/insert/success.feature b/spec/test/features/control/insert/success.feature index 4dfddf8..ff22fef 100644 --- a/spec/test/features/control/insert/success.feature +++ b/spec/test/features/control/insert/success.feature @@ -1,16 +1,16 @@ Feature: Insert new routes in Kapow! server. - Insert routes allow users to configure the server. New - routes could be inserted at the begining or before any + Inserting routes allows users to configure the server. New + routes could be inserted at the beginning or before any existing route of the routes list. 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 | | GET | /listRootDir | /bin/sh -c | ls -la / \| response /body | | GET | /listDir/{dirname} | /bin/sh -c | ls -la /request/params/dirname \| response /body | 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. When I insert the route: diff --git a/spec/test/features/control/list/success.feature b/spec/test/features/control/list/success.feature index f2b221a..5430c93 100644 --- a/spec/test/features/control/list/success.feature +++ b/spec/test/features/control/list/success.feature @@ -1,30 +1,33 @@ 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 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, + Scenario: List routes on a fresh started server + A just started or with all routes removed, will show an empty list of routes. Given I have a just started Kapow! server When I request a routes listing Then I get 200 as response code 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 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 | | 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 200 as response code And I get "OK" as response reason phrase - And I get a list with the following elements: + And I get the following response body: """ [ { diff --git a/spec/test/features/steps/steps.py b/spec/test/features/steps/steps.py index 45fc051..a8d8371 100644 --- a/spec/test/features/steps/steps.py +++ b/spec/test/features/steps/steps.py @@ -80,13 +80,7 @@ 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 the following routes') +@given('I have a Kapow! server with the following routes') def step_impl(context): run_kapow_server(context) @@ -99,13 +93,6 @@ def step_impl(context): 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') def step_impl(context): 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}") -@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') def step_impl(context): 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 JSON document') def step_impl(context): context.response = requests.post( f"{Env.KAPOW_CONTROLAPI_URL}/routes", @@ -154,22 +135,7 @@ def step_impl(context): 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 inserted') def step_impl(context, order): idx = {"first": 0, "second": 1, "last": -1}.get(order) routes = requests.get(f"{Env.KAPOW_CONTROLAPI_URL}/routes")