anancarv / python-artifactory

Typed interactions with the Jfrog Artifactory REST API
MIT License
55 stars 50 forks source link

Fix test_download_artifact_success on Windows #155

Closed kraai closed 6 months ago

kraai commented 6 months ago

Description

test_download_artifact_success fails on Windows because ArtifactoryArtifact.as_posix returns forward slashes, whereas the test expects backward ones. Use Path.as_posix instead of Path.resolve in the test case to expect forward slashes instead.

Here's the test output without this change:

==================================================================================== FAILURES ====================================================================================
_________________________________________________________________________ test_download_artifact_success _________________________________________________________________________

tmp_path = WindowsPath('C:/Users/mkraai/AppData/Local/Temp/1/pytest-of-mkraai/pytest-4/test_download_artifact_success0')

    @responses.activate
    def test_download_artifact_success(tmp_path):
        artifact_name = ARTIFACT_PATH.split("/")[1]
        responses.add(
            responses.GET,
            f"{URL}/api/storage/{ARTIFACT_PATH}",
            status=200,
            json=FILE_INFO_RESPONSE,
        )
        responses.add(responses.GET, f"{URL}/{ARTIFACT_PATH}", json=artifact_name, status=200)

        artifactory = ArtifactoryArtifact(AuthModel(url=URL, auth=AUTH))
        artifact = artifactory.download(ARTIFACT_PATH, str(tmp_path.resolve()))

>       assert artifact.as_posix() == f"{tmp_path.resolve()}/{artifact_name}"
E       AssertionError: assert 'C:/Users/mkr...ess0/file.txt' == 'C:\\Users\\m...ess0/file.txt'
E
E         - C:\Users\mkraai\AppData\Local\Temp\1\pytest-of-mkraai\pytest-4\test_download_artifact_success0/file.txt
E         ?   ^     ^      ^       ^     ^    ^ ^                ^        ^
E         + C:/Users/mkraai/AppData/Local/Temp/1/pytest-of-mkraai/pytest-4/test_download_artifact_success0/file.txt
E         ?   ^     ^      ^       ^     ^    ^ ^                ^        ^

tests\test_artifacts.py:190: AssertionError
============================================================================ short test summary info =============================================================================
FAILED tests/test_artifacts.py::test_download_artifact_success - AssertionError: assert 'C:/Users/mkr...ess0/file.txt' == 'C:\\Users\\m...ess0/file.txt'

Type of change

Please delete options that are not relevant.

How has it been tested ?

I tested this change by running pytest and verifying that there were no failures.

Checklist: