示例#1
0
def step_impl_we_delete_event_file(context):
    url = '/events_files/%s' % context.fetched_data['_id']
    context.headers.append(('Accept', 'application/json'))
    headers = if_match(context, context.fetched_data.get('_etag'))
    response = context.client.delete(get_prefixed_url(context.app, url), headers=headers)
    assert_200(response)
    response = context.client.get(get_prefixed_url(context.app, url), headers=headers)
    assert_404(response)
示例#2
0
def then_we_get_formatted_item(context):
    assert_200(context.response)
    try:
        response_data = json.loads(context.response.get_data())
        formatted_item = json.loads(response_data.get('formatted_item', ''))
    except Exception:
        fail_and_print_body(context.response, 'response does not contain a valid formatted_item field')
    context_data = json.loads(apply_placeholders(context, context.text))
    assert_equal(json_match(context_data, formatted_item), True,
                 msg=str(context_data) + '\n != \n' + str(formatted_item))
示例#3
0
def step_impl_then_get_event_file(context):
    assert_200(context.response)
    data = get_json_data(context.response)
    url = '/upload-raw/%s' % data['filemeta']['media_id']
    headers = [('Accept', 'application/json')]
    headers = unique_headers(headers, context.headers)
    response = context.client.get(get_prefixed_url(context.app, url), headers=headers)
    assert_200(response)
    assert len(response.get_data()), response
    fetched_data = get_json_data(context.response)
    context.fetched_data = fetched_data
示例#4
0
def step_impl_then_get_media_stream(context, check_string):
    assert_200(context.response)
    data = get_json_data(context.response)
    url = '/upload-raw/%s' % data['filemeta']['media_id']
    headers = [('Content - Type', 'application / octet - stream')]
    headers = unique_headers(headers, context.headers)
    response = context.client.get(get_prefixed_url(context.app, url), headers=headers)
    assert_200(response)
    assert len(response.get_data()), response
    check_string = apply_placeholders(context, check_string)
    assert check_string in str(response.stream.response.data)
示例#5
0
def then_we_get_formatted_items(context, total_count):
    assert_200(context.response)
    data = get_json_data(context.response)
    int_count = int(total_count.replace('+', '').replace('<', ''))

    if '+' in total_count:
        assert int_count <= data['_meta']['total'], '%d items is not enough' % data['_meta']['total']
    elif total_count.startswith('<'):
        assert int_count > data['_meta']['total'], '%d items is too much' % data['_meta']['total']
    else:
        assert int_count == data['_meta']['total'], 'got %d: %s' % (data['_meta']['total'],
                                                                    format_items(data['_items']))
    if context.text:
        test_json(context, ['formatted_item'])
示例#6
0
def step_impl_then_we_get_config(context, report_id):
    assert_200(context.response)

    if not context.text:
        return

    data = get_json_data(context.response)

    config = next(
        (c for c in (data.get('_items') or []) if c.get('_id') == report_id),
        None)

    expected_config = json.loads(apply_placeholders(context, context.text))
    assert_equal(json_match(expected_config, config), True)
示例#7
0
def then_we_get_formatted_items(context, total_count):
    assert_200(context.response)
    data = get_json_data(context.response)
    int_count = int(total_count.replace("+", "").replace("<", ""))

    if "+" in total_count:
        assert int_count <= data["_meta"][
            "total"], "%d items is not enough" % data["_meta"]["total"]
    elif total_count.startswith("<"):
        assert int_count > data["_meta"][
            "total"], "%d items is too much" % data["_meta"]["total"]
    else:
        assert int_count == data["_meta"]["total"], "got %d: %s" % (
            data["_meta"]["total"],
            format_items(data["_items"]),
        )
    if context.text:
        test_json(context, ["formatted_item"])
示例#8
0
def step_impl_then_get_charts(context, total_count):
    assert_200(context.response)
    data = get_json_data(context.response)
    int_count = int(total_count)
    report = (data.get('_items') or [{}])[0]
    num_reports = len(report.get('highcharts'))

    assert int_count == num_reports, 'Number of charts not equal. {} != {}'.format(
        int_count, num_reports)

    if context.text:
        try:
            response_data = json.loads(context.response.get_data())
        except Exception:
            fail_and_print_body(context.response, 'response is not valid json')
            return

        report = (response_data.get('_items') or [{}])[0]
        context_data = json.loads(apply_placeholders(context, context.text))

        chart_index = 0
        for context_chart in context_data:
            response_chart = report.get('highcharts')[chart_index]

            for key, value in context_chart.items():
                if isinstance(value, dict):
                    for subkey, subvalue in value.items():
                        assert response_chart[key][subkey] == subvalue,\
                            'chart[{}][{}][{}] {} != {}'.format(
                            chart_index,
                            key,
                            subkey,
                            subvalue,
                            response_chart[key][subkey]
                        )
                else:
                    assert response_chart[
                        key] == value, 'chart[{}][{}] {} != {}'.format(
                            chart_index, key, value, response_chart[key])

            chart_index += 1
        return response_data
示例#9
0
def step_impl_then_get_stats_for_item(context):
    assert_200(context.response)

    if context.text:
        try:
            response_data = json.loads(context.response.get_data())
        except Exception:
            fail_and_print_body(context.response, 'response is not valid json')
            return

        stats = response_data.get('stats') or {}
        context_stats = json.loads(apply_placeholders(context, context.text))

        # parent stat entries (i.e. timeline, desk_transitions, featuremedia_updates)
        for stat_type, stat_entries in context_stats.items():
            assert stat_type in stats.keys(), 'stats.{} does not exist'.format(
                stat_type)

            if stat_entries is None:
                assert stats[stat_type] is None, 'stats.{} is not empty'.format(
                    stat_type)
                continue
            elif stats[stat_type] is None:
                assert stat_entries == stats[
                    stat_type], 'stats.{} {} != {}'.format(
                        stat_type, stats[stat_type], stat_entries)

            assert len(stat_entries) == len(stats[stat_type]),\
                'stats.{}. len {} != {}.\nStats={}'.format(
                stat_type,
                len(stat_entries),
                len(stats[stat_type]),
                stats[stat_type]
            )

            stat_index = 0
            for stat_entry in stat_entries:
                expected_stats = stats[stat_type][stat_index]

                for key, value in stat_entry.items():
                    assert key in expected_stats.keys(
                    ), 'stats.{}[{}] key "{}" not found'.format(
                        stat_type, stat_index, key)

                    if isinstance(value, dict):
                        for subkey, subvalue in value.items():
                            assert subkey in expected_stats[key].keys(),\
                                'stats.{}[{}][{}] key "{}" not found.\nEntry={}'.format(
                                stat_type,
                                stat_index,
                                key,
                                subkey,
                                expected_stats[key]
                            )
                            assert json_match(subvalue, expected_stats[key][subkey]),\
                                'stats.{}[{}].{}.{} {} != {}\nEntry={}'.format(
                                stat_type,
                                stat_index,
                                key,
                                subkey,
                                expected_stats[key][subkey],
                                subvalue,
                                expected_stats[key]
                            )
                    else:
                        assert expected_stats[
                            key] == value, 'stats.{}[{}].{} {} != {}'.format(
                                stat_type, stat_index, key,
                                expected_stats[key], value)

                stat_index += 1

        return response_data