import json import logging from behave import step from nose.tools import assert_equal, assert_dict_contains_subset logger = logging.getLogger(__name__) @step( 'I should get JSON response with "{status}" status and the following body' ) def step_should_get_json_response(context, status): expected_response = json.loads(context.text) assert_equal(int(status), context.response.status_code) assert_equal(expected_response, context.response.json) @step('I should get JSON response with "{status}" status and body containing') def step_should_get_json_response_containing(context, status): expected_response = json.loads(context.text) assert_equal(int(status), context.response.status_code) assert_dict_contains_subset(expected_response, context.response.json) @step( 'I should get JSON response with "{status}" status and body containing items' # noqa ) def step_should_get_json_response_containing_items(context, status): expected_response = json.loads(context.text) assert_equal(int(status), context.response.status_code) for item in context.response.json: assert_dict_contains_subset(expected_response[0], item)