예제 #1
0
def test_get_component_info_from_nexus_multiple_results(
        mock_search_components, components_search_results):
    mock_search_components.return_value = components_search_results["items"]

    expected = "The component search in Nexus unexpectedly returned more than one result"
    with pytest.raises(CachitoError, match=expected):
        nexus.get_component_info_from_nexus("cachito-js-proxy", "npm", "rxjs",
                                            "*")
예제 #2
0
def test_get_component_info_from_nexus_version_vs_raw(raw, version):
    component_format = "raw" if raw else "npm"

    expected = "'version' argument must be provided if and only if format is not 'raw'"
    with pytest.raises(ValueError, match=expected):
        nexus.get_component_info_from_nexus("some-repository",
                                            component_format, "some-name",
                                            version)
예제 #3
0
def _get_js_component_info_from_nexus(
    name: str, version: str, repository: str, is_hosted: bool, max_attempts: int = 1
) -> Optional[dict]:
    """
    Get the JS component information a Nexus repository using Nexus' REST API.

    :param str name: the name of the dependency including the scope if present
    :param str version: the version of the dependency; a wildcard can be specified but it should
        not match more than a single version
    :param str repository: the name of the Nexus repository to get information from
    :param bool is_hosted: is the repository in the hosted Nexus instance?
    :param int max_attempts: the number of attempts to try to get a result; this defaults to ``1``
    :return: the JSON about the NPM component or None
    :rtype: dict or None
    :raise CachitoError: if the search fails or more than one component is returned
    """
    if name.startswith("@"):
        component_group_with_prefix, component_name = name.split("/", 1)
        # Remove the "@" prefix
        component_group: Union[str, object] = component_group_with_prefix[1:]
    else:
        component_name = name
        component_group = nexus.NULL_GROUP

    return nexus.get_component_info_from_nexus(
        repository,
        "npm",
        component_name,
        version,
        component_group,
        max_attempts,
        from_nexus_hoster=is_hosted,
    )
예제 #4
0
def test_get_component_info_from_nexus_no_results(mock_search_components,
                                                  mock_sleep):
    mock_search_components.return_value = []

    results = nexus.get_component_info_from_nexus("cachito-js-proxy",
                                                  "npm",
                                                  "rxjs",
                                                  "6.55.5",
                                                  max_attempts=3)

    assert results is None
    assert mock_sleep.call_count == 2
    assert mock_search_components.call_count == 3
예제 #5
0
def test_get_component_info_from_nexus_any_group(mock_search_components):
    mock_search_components.return_value = [
        {
            "name": "foo",
            "group": "some",
            "version": "1.0.0"
        },
    ]

    result = nexus.get_component_info_from_nexus("cachito-js-proxy",
                                                 "npm",
                                                 "foo",
                                                 version="1.0.0",
                                                 group=None)

    assert result == mock_search_components.return_value[0]
예제 #6
0
def test_get_component_info_from_nexus(mock_search_components,
                                       components_search_results):
    repository = "cachito-js-proxy"
    component_format = "npm"
    name = "rxjs"
    version = "6.5.5-external-gitcommit-78032157f5c1655436829017bbda787565b48c30"
    group = "reactive"
    components_search_results["items"].pop(0)
    mock_search_components.return_value = components_search_results["items"]

    results = nexus.get_component_info_from_nexus(repository,
                                                  component_format,
                                                  name,
                                                  version,
                                                  group=group)

    expected = components_search_results["items"][0]
    assert results == expected
예제 #7
0
def get_npm_component_info_from_nexus(name, version, max_attempts=1):
    """
    Get the NPM component information from the NPM hosted repository using Nexus' REST API.

    :param str name: the name of the dependency including the scope if present
    :param str version: the version of the dependency; a wildcard can be specified but it should
        not match more than a single version
    :param int max_attempts: the number of attempts to try to get a result; this defaults to ``1``
    :return: the JSON about the NPM component or None
    :rtype: dict or None
    :raise CachitoError: if the search fails or more than one component is returned
    """
    if name.startswith("@"):
        component_group, component_name = name.split("/", 1)
        # Remove the "@" prefix
        component_group = component_group[1:]
    else:
        component_name = name
        component_group = None

    repository = get_js_hosted_repo_name()
    return nexus.get_component_info_from_nexus(repository, "npm",
                                               component_name, version,
                                               component_group, max_attempts)