Example #1
0
 def test_object_in_array_fail(self):
     with self.assertRaises(WooperAssertionError):
         expect.expect_json_contains(
             response,
             {"baz": "spa", "second": "item"},
             path="list"
         )
Example #2
0
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)
Example #3
0
 def test_item_fail(self):
     with self.assertRaises(WooperAssertionError):
         expect.expect_json_contains(
             response,
             "span",
             path="list/[0]/baz"
         )
Example #4
0
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})
Example #5
0
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)
Example #6
0
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)
Example #7
0
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})
Example #8
0
 def test_item_in_array_fail(self):
     with self.assertRaises(WooperAssertionError):
         expect.expect_json_contains(
             response,
             2,
             path="list"
         )
Example #9
0
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)
Example #10
0
 def test_object_in_object_pass(self):
     expect.expect_json_contains(
         response,
         {
             "list":
             [{"baz": "spam", "second": "item"}, 1, "qwe", ["a", "b"]]
         }
     )
Example #11
0
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)
Example #12
0
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)
Example #13
0
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)
Example #14
0
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)
Example #15
0
 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"]]
             }
         )
Example #16
0
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')
Example #17
0
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')
Example #18
0
 def test_fulljson_pass(self):
     expect.expect_json_contains(
         response,
         """{
             "foo": "bar",
             "list": [
                 {"baz": "spam", "second": "item"},
                 1,
                 "qwe",
                 ["a", "b"]
             ]
         }"""
     )
Example #19
0
 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"]
                 ]
             }"""
         )
Example #20
0
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
Example #21
0
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
Example #22
0
 def test_object_in_array_pass(self):
     expect.expect_json_contains(
         response,
         {"baz": "spam", "second": "item"},
         path="list"
     )
Example #23
0
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')
Example #24
0
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)
Example #25
0
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)
Example #26
0
def assert_ok(response):
    """Assert we get ok status within api response."""
    expect_status_in(response, (200, 201))
    expect_json_contains(response, {'_status': 'OK'})
Example #27
0
def step_impl_then_get_version(context, version):
    assert_200(context.response)
    expect_json_contains(context.response, {'_version': int(version)})
Example #28
0
def step_impl_then_get_action(context):
    response = context.client.get('/activity', headers=context.headers)
    expect_json_contains(response, '_items')
Example #29
0
 def test_array_in_array_pass(self):
     expect.expect_json_contains(
         response,
         ['a', 'b'],
         path="list"
     )
Example #30
0
def step_impl_then_get_picture(context):
    assert_ok(context.response)
    expect_json_contains(context.response, 'picture_url')
Example #31
0
def step_impl_then_get_picture(context):
    assert_ok(context.response)
    expect_json_contains(context.response, 'picture_url')
Example #32
0
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)
Example #33
0
 def test_partitem_pass(self):
     expect.expect_json_contains(
         response,
         "spa",
         path="list/[0]/baz"
     )
Example #34
0
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])
Example #35
0
def step_impl_then_get_field_value(context, field, value):
    assert_200(context.response)
    expect_json_contains(context.response, {field: value})
Example #36
0
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')
Example #37
0
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)
Example #38
0
def step_impl_then_get_version(context, version):
    assert_200(context.response)
    expect_json_contains(context.response, {'_version': int(version)})
Example #39
0
 def test_item_in_array_pass(self):
     expect.expect_json_contains(
         response,
         1,
         path="list"
     )
Example #40
0
def step_impl_then_get_field_value(context, field, value):
    assert_200(context.response)
    expect_json_contains(context.response, {field: value})
Example #41
0
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])
Example #42
0
def assert_ok(response):
    """Assert we get ok status within api response."""
    expect_status_in(response, (200, 201))
    expect_json_contains(response, {'_status': 'OK'})
Example #43
0
def step_impl_then_get_action(context):
    response = context.client.get('/activity', headers=context.headers)
    expect_json_contains(response, '_items')