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
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def test_get_permission_error_not_found():
    responses.add(
        responses.GET, f"{URL}/api/security/permissions/{PERMISSION.name}", status=404
    )

    artifactory_permission = ArtifactoryPermission(AuthModel(url=URL, auth=AUTH))
    with pytest.raises(PermissionNotFoundException):
        artifactory_permission.get(PERMISSION.name)
def test_get_permission_error_not_found(api_version, permission, api_uri):
    responses.add(responses.GET,
                  f"{URL}/{api_uri}/{permission.name}",
                  status=404)

    artifactory_permission = ArtifactoryPermission(
        AuthModel(url=URL, auth=AUTH, api_version=api_version))
    with pytest.raises(PermissionNotFoundException):
        artifactory_permission.get(permission.name)
Ejemplo n.º 5
0
def test_delete_permission_fail_if_group_not_found(mocker):
    responses.add(
        responses.GET, f"{URL}/api/security/permissions/{PERMISSION.name}", status=404
    )

    artifactory_permission = ArtifactoryPermission(AuthModel(url=URL, auth=AUTH))
    mocker.spy(artifactory_permission, "get")

    with pytest.raises(PermissionNotFoundException):
        artifactory_permission.delete(PERMISSION.name)

    artifactory_permission.get.assert_called_once_with(PERMISSION.name)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
def test_list_group_success(mocker):
    responses.add(
        responses.GET,
        f"{URL}/api/security/permissions",
        json=[SIMPLE_PERMISSION.dict()],
        status=200,
    )

    artifactory_permission = ArtifactoryPermission(AuthModel(url=URL, auth=AUTH))
    mocker.spy(artifactory_permission, "list")
    permission_list = artifactory_permission.list()
    artifactory_permission.list.assert_called_once()

    assert permission_list == [SIMPLE_PERMISSION.dict()]
def test_delete_permission_fail_if_group_not_found(mocker, api_version,
                                                   permission, api_uri):
    responses.add(responses.GET,
                  f"{URL}/{api_uri}/{permission.name}",
                  status=404)

    artifactory_permission = ArtifactoryPermission(
        AuthModel(url=URL, auth=AUTH, api_version=api_version))
    mocker.spy(artifactory_permission, "get")

    with pytest.raises(PermissionNotFoundException):
        artifactory_permission.delete(permission.name)

    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)
Ejemplo n.º 10
0
def test_delete_group_success(mocker):
    responses.add(
        responses.GET,
        f"{URL}/api/security/permissions/{PERMISSION.name}",
        json=PERMISSION.dict(),
        status=200,
    )

    responses.add(
        responses.DELETE,
        f"{URL}/api/security/permissions/{PERMISSION.name}",
        status=204,
    )
    artifactory_permission = ArtifactoryPermission(AuthModel(url=URL, auth=AUTH))
    mocker.spy(artifactory_permission, "get")
    artifactory_permission.delete(PERMISSION.name)

    artifactory_permission.get.assert_called_once_with(PERMISSION.name)
Ejemplo n.º 11
0
def test_delete_group_success(mocker, api_version, permission, api_uri):
    responses.add(
        responses.GET,
        f"{URL}/{api_uri}/{permission.name}",
        json=permission.dict(),
        status=200,
    )

    responses.add(
        responses.DELETE,
        f"{URL}/{api_uri}/{permission.name}",
        status=204,
    )
    artifactory_permission = ArtifactoryPermission(
        AuthModel(url=URL, auth=AUTH, api_version=api_version))
    mocker.spy(artifactory_permission, "get")
    artifactory_permission.delete(permission.name)

    artifactory_permission.get.assert_called_once_with(permission.name)