<commit_before>"""
    :codeauthor: <NAME> <<EMAIL>>
"""

import pytest
import salt.states.artifactory as artifactory
from tests.support.mock import MagicMock, patch


@pytest.fixture
def setup_loader_modules():
    return {artifactory: {}}


def test_downloaded():
    """
    Test to ensures that the artifact from artifactory exists at
    given location.
    """
    name = "jboss"
    arti_url = "http://artifactory.intranet.example.com/artifactory"
    artifact = {
        "artifactory_url": arti_url,
        "artifact_id": "module",
        "repository": "libs-release-local",
        "packaging": "jar",
        "group_id": "com.company.module",
        "classifier": "sources",
        "version": "1.0",
    }

    ret = {"name": name, "result": False, "changes": {}, "comment": ""}

    mck = MagicMock(return_value={"status": False, "changes": {}, "comment": ""})
    with patch.dict(artifactory.__salt__, {"artifactory.get_release": mck}):
        assert artifactory.downloaded(name, artifact) == ret

    with patch.object(
        artifactory,
        "__fetch_from_artifactory",
        MagicMock(side_effect=Exception("error")),
    ):
        ret = artifactory.downloaded(name, artifact)
        assert ret["result"] is False
        assert ret["comment"] == "error"


def test_downloaded_test_true():
    """
    Test to ensures that the artifact from artifactory exists at
    given location.
    """
    name = "jboss"
    arti_url = "http://artifactory.intranet.example.com/artifactory"
    artifact = {
        "artifactory_url": arti_url,
        "artifact_id": "module",
        "repository": "libs-release-local",
        "packaging": "jar",
        "group_id": "com.company.module",
        "classifier": "sources",
        "version": "1.0",
    }

    ret = {
        "name": name,
        "result": True,
        "changes": {},
        "comment": "Artifact would be downloaded from URL: http://artifactory.intranet.example.com/artifactory",
    }

    mck = MagicMock(return_value={"status": False, "changes": {}, "comment": ""})
    with patch.dict(artifactory.__salt__, {"artifactory.get_release": mck}):
        with patch.dict(artifactory.__opts__, {"test": True}):
            assert artifactory.downloaded(name, artifact) == ret

    with patch.object(
        artifactory,
        "__fetch_from_artifactory",
        MagicMock(side_effect=Exception("error")),
    ):
        ret = artifactory.downloaded(name, artifact)
        assert ret["result"] is False
        assert ret["comment"] == "error"
<commit_msg>Fix artifactory test<commit_after>"""
    :codeauthor: <NAME> <<EMAIL>>
"""

import pytest
import salt.states.artifactory as artifactory
from tests.support.mock import MagicMock, patch


@pytest.fixture
def configure_loader_modules():
    return {artifactory: {}}


def test_downloaded():
    """
    Test to ensures that the artifact from artifactory exists at
    given location.
    """
    name = "jboss"
    arti_url = "http://artifactory.intranet.example.com/artifactory"
    artifact = {
        "artifactory_url": arti_url,
        "artifact_id": "module",
        "repository": "libs-release-local",
        "packaging": "jar",
        "group_id": "com.company.module",
        "classifier": "sources",
        "version": "1.0",
    }

    ret = {"name": name, "result": False, "changes": {}, "comment": ""}

    mck = MagicMock(return_value={"status": False, "changes": {}, "comment": ""})
    with patch.dict(artifactory.__salt__, {"artifactory.get_release": mck}):
        assert artifactory.downloaded(name, artifact) == ret

    with patch.object(
        artifactory,
        "__fetch_from_artifactory",
        MagicMock(side_effect=Exception("error")),
    ):
        ret = artifactory.downloaded(name, artifact)
        assert ret["result"] is False
        assert ret["comment"] == "error"


def test_downloaded_test_true():
    """
    Test to ensures that the artifact from artifactory exists at
    given location.
    """
    name = "jboss"
    arti_url = "http://artifactory.intranet.example.com/artifactory"
    artifact = {
        "artifactory_url": arti_url,
        "artifact_id": "module",
        "repository": "libs-release-local",
        "packaging": "jar",
        "group_id": "com.company.module",
        "classifier": "sources",
        "version": "1.0",
    }

    ret = {
        "name": name,
        "result": True,
        "changes": {},
        "comment": "Artifact would be downloaded from URL: http://artifactory.intranet.example.com/artifactory",
    }

    mck = MagicMock(return_value={"status": False, "changes": {}, "comment": ""})
    with patch.dict(artifactory.__salt__, {"artifactory.get_release": mck}):
        with patch.dict(artifactory.__opts__, {"test": True}):
            assert artifactory.downloaded(name, artifact) == ret

    with patch.object(
        artifactory,
        "__fetch_from_artifactory",
        MagicMock(side_effect=Exception("error")),
    ):
        ret = artifactory.downloaded(name, artifact)
        assert ret["result"] is False
        assert ret["comment"] == "error"

{'fraction_non_alphanumeric': 0.14959859017035443, 'fraction_numerical': 0.0015664773839827687, 'mean_word_length': 2.9201841903300076, 'pattern_counts': {'":': 62, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3622558', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1574, 'n_words': 336}