def find_empty_dictionary_under_the_path(context, path):
    """Check if the value (attribute) can be found in the JSON output."""
    jsondata = context.response.json()
    assert jsondata is not None
    v = get_value_using_path(jsondata, path)
    assert v == {}, "An empty dictionary is expected, but value {v} with type {t} has been found" \
                    .format(v=v, t=type(v))
def find_timestamp_value_under_the_path(context, path):
    """Check if the value (attribute) can be found in the JSON output."""
    jsondata = context.response.json()
    assert jsondata is not None
    v = get_value_using_path(jsondata, path)
    assert v is not None
    check_timestamp(v)
def find_value_under_the_path(context, expected, path):
    """Check if the value (attribute) can be found in the JSON output."""
    jsondata = context.response.json()
    assert jsondata is not None
    value = get_value_using_path(jsondata, path)
    assert value is not None
    compare_value_from_json(value, expected)
def check_outliers(context, component):
    """Check the outlier record in the stack analysis."""
    json_data = get_json_data(context)

    path = 'recommendation/usage_outliers'
    usage_outliers = get_value_using_path(json_data, path)
    check_frequency_count(usage_outliers, component)
Esempio n. 5
0
def find_null_value_under_the_path(context, path):
    """Check if the value (attribute) can be found in the JSON output."""
    jsondata = context.response.json()
    assert jsondata is not None
    v = get_value_using_path(jsondata, path)
    assert v is None, "None/null is expected, but {value} has been found".format(
        value=v)
def check_equal_expectation_for_int(context, path, expected):
    """Check equality check for array object count."""
    json_data = get_json_data(context)
    actual_count = get_value_using_path(json_data, path)
    assert actual_count == expected, \
        "Found {} object(s) at {}, but {} is expected".format(
            actual_count, path, expected)
def stack_analysis_check_licenses(context, licenses, path):
    """Check the license(s) in the stack analysis."""
    licenses = split_comma_separated_list(licenses)
    json_data = context.response.json()
    node = get_value_using_path(json_data, path)
    assert node is not None
    check_licenses(node, licenses)
def check_outlier_validity(context):
    """Check the outlier validity in the stack analysis."""
    json_data = context.response.json()
    path = "result/0/recommendation/usage_outliers"
    usage_outliers = get_value_using_path(json_data, path)
    for usage_outlier in usage_outliers:
        # log.info("PACKAGE: {}".format(usage_outlier["package_name"]))
        check_frequency_count(usage_outliers, usage_outlier["package_name"])
def check_unknown_dependencies_count(context, expected):
    """Check number of unknown dependencies."""
    json_data = get_json_data(context)
    path = "result/0/user_stack_info/unknown_dependencies_count"
    unknown_dependencies_count = get_value_using_path(json_data, path)
    assert unknown_dependencies_count <= expected, \
        "Found {} unknown dependencies, but at most {} is expected".format(
            unknown_dependencies_count, expected)
def get_analyzed_components(context):
    """Return all analyzed components from the deserialized JSON file."""
    json_data = get_json_data(context)

    components = get_value_using_path(json_data, 'analyzed_dependencies')
    assert components is not None

    return components
def check_analyzed_dependencies_count(context, expected=1):
    """Check number of analyzed dependencies."""
    json_data = get_json_data(context)
    path = "result/0/user_stack_info/analyzed_dependencies_count"
    analyzed_dependencies_count = get_value_using_path(json_data, path)
    assert analyzed_dependencies_count >= expected, \
        "Found only {} analyzed dependencies, but at least {} is expected".format(
            analyzed_dependencies_count, expected)
def check_unknown_dependencies_count_exact_check(context, expected=1):
    """Check number of really unknown dependencies (for specific manifests)."""
    json_data = get_json_data(context)
    path = "result/0/user_stack_info/unkwnown_dependencies_count"
    unknown_dependencies_count = get_value_using_path(json_data, path)
    assert unknown_dependencies_count == expected, \
        "Found {} unknown dependencies, but {} is expected".format(
            unknown_dependencies_count, expected)
def check_dependencies_count(context, expected=1):
    """Check number of dependencies."""
    json_data = get_json_data(context)
    path = "result/0/user_stack_info/dependencies"
    dependencies_count = len(get_value_using_path(json_data, path))
    assert dependencies_count >= expected, \
        "Found only {} dependencies, but at least {} is expected".format(
            dependencies_count, expected)
def get_analyzed_components(context):
    """Return all analyzed components from the deserialized JSON file."""
    json_data = get_json_data(context)

    path = "result/0/user_stack_info/analyzed_dependencies"
    components = get_value_using_path(json_data, path)
    assert components is not None

    return components
def validate_topic_list(context, key):
    """Verify topics' list for stack dependencies with the input stack topics."""
    json_data = context.response.json()
    path = "result"
    manifest_results = get_value_using_path(json_data, path)

    # loop through results for each of the manifest files
    for result in manifest_results:
        path = "recommendation/input_stack_topics"
        input_stack_topics = get_value_using_path(result, path)

        deps = get_value_using_path(result, key)

        for dep in deps:
            assert len(dep['topic_list']) == len(
                input_stack_topics[dep['name']])
            assert sorted(dep['topic_list']) == sorted(
                input_stack_topics[dep['name']])
def check_timestamp_under_path(context, path):
    """Check the timestamp stored in selected attribute.

    Check if timestamp value can be found in the JSON response object
    under the given path.
    """
    jsondata = context.response.json()
    assert jsondata is not None
    timestamp = get_value_using_path(jsondata, path)
    check_timestamp(timestamp)
def check_dependency(context, package, version):
    """Check for the existence of dependency for given package."""
    json_data = get_json_data(context)
    path = "result/0/user_stack_info/dependencies"
    dependencies = get_value_using_path(json_data, path)

    assert dependencies is not None, \
        "Empty or missing attribute user_stack_info/dependencies"

    test_dependency_for_package_version(dependencies, package, version)
def check_all_analyzed_dependencies(context, packages):
    """Check all analyzed dependencies in the stack analysis."""
    json_data = get_json_data(context)
    packages = split_comma_separated_list(packages)
    path = "result/0/user_stack_info/analyzed_dependencies"
    analyzed_dependencies = get_value_using_path(json_data, path)
    assert analyzed_dependencies is not None
    dependencies = get_attribute_values(analyzed_dependencies, "name")
    for package in packages:
        if package not in dependencies:
            raise Exception(
                'Package {package} not found'.format(package=package))
def check_analyzed_packages(context, package, ecosystem):
    """Check the package in component analysis."""
    context_reponse_existence_check(context)
    json_data = context.response.json()

    package_data = get_value_using_path(json_data, "result/data/0/package")
    assert package_data is not None

    check_attribute_presence(package_data, "ecosystem")
    assert package_data["ecosystem"][0] == ecosystem

    check_attribute_presence(package_data, "name")
    assert package_data["name"][0] == package
def stack_analysis_check_replaces_count(context,
                                        component,
                                        version,
                                        expected_replacements=1):
    """Check that the component is replaced only once in the alternate analysis."""
    json_data = context.response.json()
    path = "result/0/recommendation/alternate"
    alternates = get_value_using_path(json_data, path)
    replacements = find_replacements(alternates, component, version)
    replacements_count = len(replacements)

    assert replacements_count == expected_replacements, \
        "there must be just %d replacement(s), " \
        "but %d replacements have been found" % (expected_replacements, replacements_count)
def check_analyzed_dependency(context, package, version):
    """Check for the existence of analyzed dependency for given package."""
    jsondata = context.response.json()
    assert jsondata is not None
    path = "result/0/user_stack_info/analyzed_dependencies"
    analyzed_dependencies = get_value_using_path(jsondata, path)
    assert analyzed_dependencies is not None
    for analyzed_dependency in analyzed_dependencies:
        if analyzed_dependency["name"] == package \
           and analyzed_dependency["version"] == version:
            break
    else:
        raise Exception(
            'Package {package} with version {version} not found'.format(
                package=package, version=version))
def check_analyzed_component(context, package, version, ecosystem):
    """Check the component in component analysis."""
    context_reponse_existence_check(context)
    json_data = context.response.json()

    version_data = get_value_using_path(json_data, "result/data/0/version")
    assert version_data is not None

    check_attribute_presence(version_data, "pecosystem")
    assert version_data["pecosystem"][0] == ecosystem

    check_attribute_presence(version_data, "pname")
    assert version_data["pname"][0] == package

    check_attribute_presence(version_data, "version")
    assert version_data["version"][0] == version
def stack_analysis_check_replaces(context, component, version, replaced_by,
                                  replacement_version):
    """Check that the component is replaced by the given package and version."""
    json_data = context.response.json()
    path = "result/0/recommendation/alternate"
    alternates = get_value_using_path(json_data, path)
    replacements = find_replacements(alternates, component, version)

    for replacement in replacements:
        if replacement["name"] == replaced_by and \
           replacement["version"] == replacement_version:
            break
    else:
        raise Exception("Can not found expected replacement for the component"
                        " {component} {version}".format(component=component,
                                                        version=version))
def check_security_node(context, path):
    """Check the content of security node."""
    json_data = get_json_data(context)

    components = get_value_using_path(json_data, path)
    assert components is not None

    for component in components:
        check_attribute_presence(component, "security")
        cve_items = component["security"]
        for cve_item in cve_items:
            check_attribute_presence(cve_item, "CVE")
            check_attribute_presence(cve_item, "CVSS")
            cve = cve_item["CVE"]
            cvss = cve_item["CVSS"]
            check_cve_value(cve)
            check_cvss_value(cvss)
def get_analyzed_packages(json_data):
    """Get names of all analyzed packages."""
    path = "result/0/user_stack_info/dependencies"
    analyzed_packages = get_value_using_path(json_data, path)
    return get_attribute_values(analyzed_packages, "package")
def get_alternate_components(json_data):
    """Get alternate components from the stack analysis."""
    path = "result/0/recommendation/alternate"
    return get_value_using_path(json_data, path)
def get_user_components(json_data):
    """Get user components from the stack analysis."""
    path = "result/0/user_stack_info/dependencies"
    return get_value_using_path(json_data, path)
def get_companion_packages(json_data):
    """Get names of all packages in companion list."""
    path = "result/0/recommendation/companion"
    companion = get_value_using_path(json_data, path)
    return get_attribute_values(companion, "name")
def verify_stack_level_field_presence_in_recommendation(context, field_name):
    """Check that the given field can be found in the recommendation."""
    json_data = context.response.json()
    path = 'result/0/recommendation'
    recommendation = get_value_using_path(json_data, path)
    assert recommendation.get(field_name, None) is not None
def verify_stack_level_field_presence_in_stack_report(context, field_name):
    """Check that the given field can be found in the stack report."""
    json_data = context.response.json()
    path = 'result/0/user_stack_info'
    user_stack_info = get_value_using_path(json_data, path)
    assert user_stack_info.get(field_name, None) is not None