Пример #1
0
    def test_get_access_request_by_anon(self):
        pkg = factories.Dataset()
        user = factories.User()
        create_request(package_id=pkg['id'], user_id=user['id'])

        with pytest.raises(NotAuthorized):
            get.get_access_request({}, {'id': pkg['id'], 'user': user['name']})
Пример #2
0
    def test_get_access_request_id_required(self):
        user = factories.Sysadmin()
        pkg = factories.Dataset()
        create_request(user_id=user['name'], package_id=pkg['id'])

        with pytest.raises(ValidationError):
            get.get_access_request({'user': user['name']}, {})
Пример #3
0
def test_create_or_get_request():
    req1 = create_request()
    assert req1.state == "pending"
    assert req1.id == _generate_uuid('user', 'package')

    req2 = create_request()

    assert req1.id == req2.id
Пример #4
0
    def test_get_access_request_by_user(self):
        user = factories.User()
        pkg = factories.Dataset()

        create_request(user_id=user['name'], package_id=pkg['id'])

        req = get.get_access_request({'user': user['name']}, {
            'id': pkg['id'],
            'user': user['name']
        })

        assert req
Пример #5
0
    def test_get_access_requests_list_for_org_by_member(self):
        user = factories.User()
        org = factories.Organization(users=[{
            "name": user["name"],
            "capacity": "editor"
        }])
        dataset = factories.Dataset(owner_org=org['id'])

        create_request(package_id=dataset['id'], org_id=org['id'])

        res = get.get_access_requests_for_org({'user': user['name']},
                                              {'id': org['id']})

        assert len(res) == 1
Пример #6
0
    def test_get_access_requests_list_for_pkg(self):
        user1 = factories.User(name='user1')
        user2 = factories.User(name='user2')
        sysadmin = factories.Sysadmin()

        pkg = factories.Dataset()

        create_request(user_id=user1['name'], package_id=pkg['id'])
        create_request(user_id=user2['name'], package_id=pkg['id'])

        reqs = get.get_access_requests_for_pkg({'user': sysadmin['name']},
                                               {'id': pkg['id']})

        assert len(reqs) == 2
Пример #7
0
def test_approve_request():
    req = create_request()
    assert req.state == "pending"

    AccessRequest.set_access_request_state(
        user_id='user', package_id='package', state='approved')
    assert req.state == 'approved'
Пример #8
0
def test_reject_request_by_request_id():
    req = create_request(state='approved')
    assert req.state == "approved"

    AccessRequest.set_access_request_state(
        user_id='user',
        package_id='package',
        state='rejected',
        request_id=req.id
    )
    assert req.state == 'rejected'
Пример #9
0
def test_get_package_approved_requests():
    create_request(user_id='user1')
    create_request(user_id='user2', state='approved')
    create_request(user_id='user3', state='approved')
    reqs = AccessRequest.get_access_requests_for_pkg(
        id='package', state='approved')

    assert reqs.count() == 2
Пример #10
0
def test_get_org_pending_requests():
    create_request(user_id='user1', package_id='package1')
    create_request(user_id='user2', package_id='package2')
    create_request(user_id='user3', package_id='package3', state='approved')

    reqs = AccessRequest.get_access_requests_for_org(
        id='org-name', state='pending')

    assert reqs.count() == 2
Пример #11
0
def test_create_with_custom_state():
    req = create_request(state='approved')
    assert req.state == "approved"