Return route information on insert & append
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
@wip
|
||||
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.
|
||||
|
||||
@@ -4,7 +4,7 @@ from functools import singledispatch
|
||||
def assert_same_type(f):
|
||||
def wrapper(a, b):
|
||||
if type(a) != type(b):
|
||||
raise TypeError("Non-matching types")
|
||||
raise TypeError(f"Non-matching types {a!r} != {b!r}")
|
||||
return f(a, b)
|
||||
return wrapper
|
||||
|
||||
@@ -12,7 +12,10 @@ def assert_same_type(f):
|
||||
@singledispatch
|
||||
@assert_same_type
|
||||
def is_subset(model, obj):
|
||||
return model == obj
|
||||
if model == obj:
|
||||
return True
|
||||
else:
|
||||
raise ValueError(f"Non-matching values {model!r} != {obj!r}")
|
||||
|
||||
|
||||
@is_subset.register(dict)
|
||||
@@ -20,16 +23,17 @@ def is_subset(model, obj):
|
||||
def _(model, obj):
|
||||
for key, value in model.items():
|
||||
if key not in obj or not is_subset(value, obj[key]):
|
||||
return False
|
||||
raise ValueError(f"Non-matching dicts {model!r} != {obj!r}")
|
||||
return True
|
||||
|
||||
|
||||
@is_subset.register(list)
|
||||
@assert_same_type
|
||||
def _(model, obj):
|
||||
if type(model) != type(obj):
|
||||
raise TypeError("Non-matching types")
|
||||
return is_subset(set(model), set(obj))
|
||||
if is_subset(set(model), set(obj)):
|
||||
return True
|
||||
else:
|
||||
raise ValueError(f"Non-matching lists {model!r} != {obj!r}")
|
||||
|
||||
|
||||
@is_subset.register(set)
|
||||
|
||||
@@ -134,10 +134,7 @@ def step_impl(context, reason):
|
||||
|
||||
@then('I get the following response body')
|
||||
def step_impl(context):
|
||||
for row in context.table:
|
||||
for name, value in row.items():
|
||||
assert name in context.response.json(), f"Field {name} not present in {context.response.json()}"
|
||||
assert set(json.loads(value)) == set(context.response.json()[name])
|
||||
assert is_subset(json.loads(context.text), context.response.json())
|
||||
|
||||
|
||||
@then('I get an empty response body')
|
||||
|
||||
Reference in New Issue
Block a user