Пример #1
0
def test_create_virtual_repository_fail_if_user_already_exists(mocker):
    responses.add(
        responses.GET,
        f"{URL}/api/repositories/{VIRTUAL_REPOSITORY.key}",
        json=VIRTUAL_REPOSITORY_RESPONSE.dict(),
        status=200,
    )

    artifactory_repo = ArtifactoryRepository(AuthModel(url=URL, auth=AUTH))
    mocker.spy(artifactory_repo, "get_virtual_repo")
    with pytest.raises(RepositoryAlreadyExistsException):
        artifactory_repo.create_virtual_repo(VIRTUAL_REPOSITORY)

        artifactory_repo.get_virtual_repo.assert_called_once_with(
            VIRTUAL_REPOSITORY.key)
Пример #2
0
def test_create_virtual_repository_success(mocker):
    responses.add(responses.GET,
                  f"{URL}/api/repositories/{VIRTUAL_REPOSITORY.key}",
                  status=404)
    responses.add(
        responses.PUT,
        f"{URL}/api/repositories/{VIRTUAL_REPOSITORY.key}",
        json=VIRTUAL_REPOSITORY_RESPONSE.dict(),
        status=201,
    )
    responses.add(
        responses.GET,
        f"{URL}/api/repositories/{VIRTUAL_REPOSITORY.key}",
        json=VIRTUAL_REPOSITORY_RESPONSE.dict(),
        status=200,
    )

    artifactory_repo = ArtifactoryRepository(AuthModel(url=URL, auth=AUTH))
    mocker.spy(artifactory_repo, "get_virtual_repo")
    virtual_repo = artifactory_repo.create_virtual_repo(VIRTUAL_REPOSITORY)

    artifactory_repo.get_virtual_repo.assert_called_with(
        VIRTUAL_REPOSITORY.key)
    assert artifactory_repo.get_virtual_repo.call_count == 2
    assert virtual_repo == VIRTUAL_REPOSITORY_RESPONSE.dict()