Пример #1
0
def test_get_artifact_url_specified_path_has_no_children():

    with patch('flow.utils.commons.printMSG') as mock_printmsg_fn:
        _b = MagicMock(BuildConfig)
        _b.build_env_info = mock_build_config_dict['environments']['unittest']
        _b.json_config = mock_build_config_dict
        _b.project_name = mock_build_config_dict['projectInfo']['name']
        _b.version_number = 'v1.0.0'
        _b.artifact_extension = 'bob'
        _b.artifact_extensions = None

        art = ArtiFactory(config_override=_b)

        test_url = "https://testdomain/artifactory/api/storage/release-repo/group/testproject/v1.0.0"

        responses.add(responses.GET,
                      test_url,
                      body=response_body_artifactory_no_children,
                      status=200,
                      content_type="application/json")

        with pytest.raises(ArtifactException) as cm:
            art.get_artifact_url()

        print(str(mock_printmsg_fn.mock_calls))
        mock_printmsg_fn.assert_called_with('ArtiFactory', 'get_artifact_url',
                                            'Could not locate artifact bob',
                                            'ERROR')
Пример #2
0
def test_get_artifact_url_not_found():

    with patch('flow.utils.commons.printMSG') as mock_printmsg_fn:
        _b = MagicMock(BuildConfig)
        _b.build_env_info = mock_build_config_dict['environments']['unittest']
        _b.json_config = mock_build_config_dict
        _b.project_name = mock_build_config_dict['projectInfo']['name']
        _b.version_number = 'v1.0.0'

        art = ArtiFactory(config_override=_b)

        test_url = "https://testdomain/artifactory/api/storage/release-repo/group/testproject/v1.0.0"

        responses.add(responses.GET,
                      test_url,
                      body=response_body_artifactory_not_found,
                      status=404,
                      content_type="application/json")

        with pytest.raises(ArtifactException) as cm:
            art.get_artifact_url()

        print(str(mock_printmsg_fn.mock_calls))
        mock_printmsg_fn.assert_called_with(
            'ArtiFactory', 'get_artifact_url',
            'Unable to locate artifactory path https://testdomain/artifactory/api/storage/release-repo/group/testproject/v1.0.0\r\n Response: \n{\n  "errors" : [ {\n    "status" : 404,\n    "message" : "Unable to find item"\n  } ]\n}\n',
            'ERROR')
Пример #3
0
def test_get_artifact_with_includePom():
    _b = MagicMock(BuildConfig)
    _b.build_env_info = mock_build_config_artifactoryConfig_include_POM[
        'environments']['unittest']
    _b.json_config = mock_build_config_artifactoryConfig_include_POM
    _b.project_name = mock_build_config_artifactoryConfig_include_POM[
        'projectInfo']['name']
    _b.include_pom = mock_build_config_artifactoryConfig_include_POM[
        'artifactoryConfig']['includePom']
    _b.version_number = 'v1.0.0'
    _b.artifact_extension = 'bob'
    _b.artifact_extensions = None
    art = ArtiFactory(config_override=_b)

    test_url = "https://testdomain/artifactory/api/storage/release-repo/group/testproject/v1.0.0"

    responses.add(responses.GET,
                  test_url,
                  body=response_body_artifactory,
                  status=200,
                  content_type="application/json")

    url = art.get_artifact_url()

    assert url == "https://testdomain/artifactory/release-repo/group/testproject/v1.0.0/testproject.bob"
Пример #4
0
def test_get_artifact_url_failure():

    with patch('flow.utils.commons.printMSG') as mock_printmsg_fn:
        _b = MagicMock(BuildConfig)
        _b.build_env_info = mock_build_config_dict['environments']['unittest']
        _b.json_config = mock_build_config_dict
        _b.project_name = mock_build_config_dict['projectInfo']['name']
        _b.version_number = 'v1.0.0'

        art = ArtiFactory(config_override=_b)

        test_url = "https://testdomain/artifactory/api/storage/release-repo/group/testproject/v1.0.0"

        exception = HTTPError('Something went wrong')
        responses.add(responses.GET, test_url, body=exception)

        with pytest.raises(ArtifactException) as cm:
            art.get_artifact_url()

        print(str(mock_printmsg_fn.mock_calls))
        mock_printmsg_fn.assert_called_with(
            'ArtiFactory', 'get_artifact_url',
            'Unable to locate artifactory path https://testdomain/artifactory/api/storage/release-repo/group/testproject/v1.0.0',
            'ERROR')