def test_object_in_array_fail(self): with self.assertRaises(WooperAssertionError): expect.expect_json_contains( response, {"baz": "spa", "second": "item"}, path="list" )
def step_impl_then_get_aggs(context, keys): assert_200(context.response) expect_json_contains(context.response, '_aggregations') data = get_json_data(context.response) aggs = data['_aggregations'] for key in keys.split(','): assert_in(key, aggs)
def test_item_fail(self): with self.assertRaises(WooperAssertionError): expect.expect_json_contains( response, "span", path="list/[0]/baz" )
def step_impl_then_get_etag(context, url): if context.app.config['IF_MATCH']: assert_200(context.response) expect_json_contains(context.response, '_etag') etag = get_json_data(context.response).get('_etag') response = context.client.get(url, headers=context.headers) expect_json_contains(response, {'_etag': etag})
def step_impl_then_get_facets(context, keys): assert_200(context.response) expect_json_contains(context.response, '_facets') data = get_json_data(context.response) facets = data['_facets'] for key in keys.split(','): assert_in(key, facets)
def test_item_in_array_fail(self): with self.assertRaises(WooperAssertionError): expect.expect_json_contains( response, 2, path="list" )
def test_object_in_object_pass(self): expect.expect_json_contains( response, { "list": [{"baz": "spam", "second": "item"}, 1, "qwe", ["a", "b"]] } )
def step_impl_then_get_archive_ingest_result(context): assert_200(context.response) expect_json_contains(context.response, 'task_id') item = json.loads(context.response.get_data()) url = '/archive_ingest/%s' % (item['task_id']) context.response = context.client.get(url, headers=context.headers) assert_200(context.response) test_json(context)
def step_impl_then_get_rendition_with_mimetype(context, name, mimetype): expect_json_contains(context.response, 'renditions') renditions = apply_path(parse_json_response(context.response), 'renditions') assert isinstance(renditions, dict), 'expected dict for image renditions' desc = renditions[name] assert isinstance(desc, dict), 'expected dict for rendition description' assert 'href' in desc, 'expected href in rendition description' we_can_fetch_a_file(context, desc['href'], mimetype)
def test_object_in_object_fail(self): with self.assertRaises(WooperAssertionError): expect.expect_json_contains( response, { "list": [{"baz": "spa", "second": "item"}, 1, "qwe", ["a", "b"]] } )
def step_impl_then_get_renditions(context, type): expect_json_contains(context.response, 'renditions') renditions = apply_path(parse_json_response(context.response), 'renditions') assert isinstance(renditions, dict), 'expected dict for image renditions' for rend_name in context.app.config['RENDITIONS'][type]: desc = renditions[rend_name] assert isinstance(desc, dict), 'expected dict for rendition description' assert 'href' in desc, 'expected href in rendition description' assert 'media' in desc, 'expected media identifier in rendition description' we_can_fetch_a_file(context, desc['href'], 'image/jpeg')
def test_fulljson_pass(self): expect.expect_json_contains( response, """{ "foo": "bar", "list": [ {"baz": "spam", "second": "item"}, 1, "qwe", ["a", "b"] ] }""" )
def test_fulljson_fail(self): with self.assertRaises(WooperAssertionError): expect.expect_json_contains( response, """{ "foo": "bar", "list": [ {"baz": "spam", "other": "item"}, 1, "qwe", ["a", "b"] ] }""" )
def step_impl_then_get_file(context): assert_200(context.response) expect_json_contains(context.response, 'renditions') data = get_json_data(context.response) url = '/upload/%s' % data['_id'] headers = [('Accept', 'application/json')] headers = unique_headers(headers, context.headers) response = context.client.get(url, headers=headers) assert_200(response) assert len(response.get_data()), response assert response.mimetype == 'application/json', response.mimetype expect_json_contains(response, 'renditions') expect_json_contains(response, {'mime_type': 'image/jpeg'}) fetched_data = get_json_data(context.response) context.fetched_data = fetched_data
def test_object_in_array_pass(self): expect.expect_json_contains( response, {"baz": "spam", "second": "item"}, path="list" )
def step_impl_then_get_action(context): response = context.client.get(get_prefixed_url(context.app, '/activity'), headers=context.headers) expect_json_contains(response, '_items')
def step_impl_then_get_key_in_url(context, key, url): res = context.client.get(url, headers=context.headers) assert_200(res) expect_json_contains(res, key)
def step_impl_then_get_new(context): assert_ok(context.response) expect_json_contains(context.response, 'self', path='_links') if context.text is not None: test_json(context)
def assert_ok(response): """Assert we get ok status within api response.""" expect_status_in(response, (200, 201)) expect_json_contains(response, {'_status': 'OK'})
def step_impl_then_get_version(context, version): assert_200(context.response) expect_json_contains(context.response, {'_version': int(version)})
def step_impl_then_get_action(context): response = context.client.get('/activity', headers=context.headers) expect_json_contains(response, '_items')
def test_array_in_array_pass(self): expect.expect_json_contains( response, ['a', 'b'], path="list" )
def step_impl_then_get_picture(context): assert_ok(context.response) expect_json_contains(context.response, 'picture_url')
def test_partitem_pass(self): expect.expect_json_contains( response, "spa", path="list/[0]/baz" )
def step_impl_then_get_key(context, key): assert_200(context.response) expect_json_contains(context.response, key) item = json.loads(context.response.get_data()) set_placeholder(context, '%s' % key, item[key])
def step_impl_then_get_field_value(context, field, value): assert_200(context.response) expect_json_contains(context.response, {field: value})
def test_item_in_array_pass(self): expect.expect_json_contains( response, 1, path="list" )