Esempio n. 1
0
def test_create_permission_fail_if_group_already_exists(mocker):
    responses.add(
        responses.GET,
        f"{URL}/api/security/permissions/{PERMISSION.name}",
        json=PERMISSION.dict(),
        status=200,
    )

    artifactory_permission = ArtifactoryPermission(AuthModel(url=URL, auth=AUTH))
    mocker.spy(artifactory_permission, "get")
    with pytest.raises(PermissionAlreadyExistsException):
        artifactory_permission.create(PERMISSION)
    artifactory_permission.get.assert_called_once_with(PERMISSION.name)
def test_create_permission_fail_if_group_already_exists(
        mocker, api_version, permission, api_uri):
    responses.add(
        responses.GET,
        f"{URL}/{api_uri}/{permission.name}",
        json=permission.dict(),
        status=200,
    )

    artifactory_permission = ArtifactoryPermission(
        AuthModel(url=URL, auth=AUTH, api_version=api_version))
    mocker.spy(artifactory_permission, "get")
    with pytest.raises(PermissionAlreadyExistsException):
        artifactory_permission.create(permission)
    artifactory_permission.get.assert_called_once_with(permission.name)
Esempio n. 3
0
def test_create_permission_success(mocker):
    responses.add(responses.GET,
                  f"{URL}/api/security/permissions/{PERMISSION.name}",
                  status=404)
    responses.add(
        responses.PUT,
        f"{URL}/api/security/permissions/{PERMISSION.name}",
        json=PERMISSION.dict(),
        status=201,
    )
    responses.add(
        responses.GET,
        f"{URL}/api/security/permissions/{PERMISSION.name}",
        json=PERMISSION.dict(),
        status=200,
    )

    artifactory_permission = ArtifactoryPermission(
        AuthModel(url=URL, auth=AUTH))
    mocker.spy(artifactory_permission, "get")
    permission = artifactory_permission.create(PERMISSION)
    artifactory_permission.get.assert_called_with(PERMISSION.name)
    assert permission == PERMISSION.dict()

    assert artifactory_permission.get.call_count == 2
def test_create_permission_success(mocker, api_version, permission, api_uri):
    responses.add(responses.GET,
                  f"{URL}/{api_uri}/{permission.name}",
                  status=404)
    responses.add(
        responses.PUT,
        f"{URL}/{api_uri}/{permission.name}",
        json=permission.dict(),
        status=201,
    )
    responses.add(
        responses.GET,
        f"{URL}/{api_uri}/{permission.name}",
        json=permission.dict(),
        status=200,
    )

    artifactory_permission = ArtifactoryPermission(
        AuthModel(url=URL, auth=AUTH, api_version=api_version))
    mocker.spy(artifactory_permission, "get")
    mocked_permission = artifactory_permission.create(permission)
    artifactory_permission.get.assert_called_with(permission.name)
    assert mocked_permission == permission.dict()

    assert artifactory_permission.get.call_count == 2