Esempio n. 1
0
def test_create_local_repository_fail_if_user_already_exists(mocker):
    responses.add(
        responses.GET,
        f"{URL}/api/repositories/{LOCAL_REPOSITORY.key}",
        json=LOCAL_REPOSITORY_RESPONSE.dict(),
        status=200,
    )

    artifactory_repo = ArtifactoryRepository(AuthModel(url=URL, auth=AUTH))
    mocker.spy(artifactory_repo, "get_local_repo")
    with pytest.raises(RepositoryAlreadyExistsException):
        artifactory_repo.create_local_repo(LOCAL_REPOSITORY)

        artifactory_repo.get_local_repo.assert_called_once_with(
            LOCAL_REPOSITORY.key)
    def test_create_local_repository_success(mocker):
        responses.add(responses.GET,
                      f"{URL}/api/repositories/{LOCAL_REPOSITORY.key}",
                      status=404)
        responses.add(
            responses.PUT,
            f"{URL}/api/repositories/{LOCAL_REPOSITORY.key}",
            json=LOCAL_REPOSITORY_RESPONSE.dict(),
            status=201,
        )
        responses.add(
            responses.GET,
            f"{URL}/api/repositories/{LOCAL_REPOSITORY.key}",
            json=LOCAL_REPOSITORY_RESPONSE.dict(),
            status=200,
        )

        artifactory_repo = ArtifactoryRepository(AuthModel(url=URL, auth=AUTH))
        mocker.spy(artifactory_repo, "get_local_repo")
        local_repo = artifactory_repo.create_local_repo(LOCAL_REPOSITORY)

        artifactory_repo.get_local_repo.assert_called_with(
            LOCAL_REPOSITORY.key)
        assert artifactory_repo.get_local_repo.call_count == 2
        assert local_repo == LOCAL_REPOSITORY_RESPONSE.dict()