示例#1
0
    def test_you_cannot_change_an_annotations_userid(self):
        schema = schemas.UpdateAnnotationSchema(testing.DummyRequest(), '', '')

        appstruct = schema.validate({'userid': 'new_userid'})

        assert 'userid' not in appstruct
        assert 'userid' not in appstruct.get('extra', {})
示例#2
0
    def test_you_cannot_change_an_annotations_references(self):
        schema = schemas.UpdateAnnotationSchema(testing.DummyRequest(), '', '')

        appstruct = schema.validate({'references': ['new_parent']})

        assert 'references' not in appstruct
        assert 'references' not in appstruct.get('extra', {})
示例#3
0
def test_updateannotationschema_raises_if_structure_validator_raises():
    request = testing.DummyRequest()
    schema = schemas.UpdateAnnotationSchema(request, {})
    schema.structure = mock.Mock()
    schema.structure.validate.side_effect = schemas.ValidationError('asplode')

    with pytest.raises(schemas.ValidationError):
        schema.validate({'foo': 'bar'})
示例#4
0
    def test_it_returns_the_appstruct_from_AnnotationSchema(
            self, annotation, AnnotationSchema):
        schema = schemas.UpdateAnnotationSchema(testing.DummyRequest(),
                                                annotation)

        appstruct = schema.validate(mock.sentinel.input_data)

        assert appstruct == AnnotationSchema.return_value.validate.return_value
示例#5
0
    def test_it_passes_input_to_AnnotationSchema_validator(
            self, annotation, AnnotationSchema):
        schema = schemas.UpdateAnnotationSchema(testing.DummyRequest(),
                                                annotation)

        schema.validate(mock.sentinel.input_data)

        schema.structure.validate.assert_called_once_with(
            mock.sentinel.input_data)
示例#6
0
    def test_it_raises_if_AnnotationSchema_validate_raises(
            self, annotation, AnnotationSchema):
        AnnotationSchema.return_value.validate.side_effect = (
            schemas.ValidationError('asplode'))
        schema = schemas.UpdateAnnotationSchema(testing.DummyRequest(),
                                                annotation)

        with pytest.raises(schemas.ValidationError):
            schema.validate({'foo': 'bar'})
示例#7
0
def test_updateannotationschema_passes_input_to_structure_validator():
    request = testing.DummyRequest()
    schema = schemas.UpdateAnnotationSchema(request, {})
    schema.structure = mock.Mock()
    schema.structure.validate.return_value = {}

    schema.validate({'foo': 'bar'})

    schema.structure.validate.assert_called_once_with({'foo': 'bar'})
示例#8
0
def test_updateannotationschema_permits_all_other_changes(data):
    request = testing.DummyRequest()
    annotation = {'group': 'flibble'}
    schema = schemas.UpdateAnnotationSchema(request, annotation)

    result = schema.validate(data)

    for k in data:
        assert result[k] == data[k]
示例#9
0
    def test_it_raises_if_you_try_to_change_the_group(self, annotation,
                                                      AnnotationSchema):
        annotation.groupid = 'original-group'
        AnnotationSchema.return_value.validate.return_value['groupid'] = (
            'new-group')
        schema = schemas.UpdateAnnotationSchema(testing.DummyRequest(),
                                                annotation)

        with pytest.raises(schemas.ValidationError):
            schema.validate(mock.sentinel.input_data)
示例#10
0
def test_updateannotationschema_removes_protected_fields(field):
    request = testing.DummyRequest()
    annotation = {}
    schema = schemas.UpdateAnnotationSchema(request, annotation)
    data = {}
    data[field] = 'something forbidden'

    result = schema.validate(data)

    assert field not in result
示例#11
0
文件: views.py 项目: hashin/h
def update(annotation, request):
    """Update the specified annotation with data from the PUT payload."""
    schema = schemas.UpdateAnnotationSchema(request, annotation=annotation)
    appstruct = schema.validate(_json_payload(request))
    annotation = storage.update_annotation(request, annotation.id, appstruct)

    _publish_annotation_event(request, annotation, 'update')

    presenter = AnnotationJSONPresenter(annotation)
    return presenter.asdict()
示例#12
0
def test_updateannotationschema_denies_group_changes():
    """An annotation may not be moved between groups."""
    request = testing.DummyRequest()
    annotation = {'group': 'flibble'}
    schema = schemas.UpdateAnnotationSchema(request, annotation)
    data = {'group': '__world__'}

    with pytest.raises(schemas.ValidationError) as exc:
        schema.validate(data)

    assert exc.value.message.startswith('group:')
示例#13
0
    def test_it_replaces_private_permissions_with_shared_False(self):
        schema = schemas.UpdateAnnotationSchema(testing.DummyRequest(), '', '')

        appstruct = schema.validate(
            {'permissions': {
                'read': ['acct:[email protected]']
            }})

        assert appstruct['shared'] is False
        assert 'permissions' not in appstruct
        assert 'permissions' not in appstruct.get('extras', {})
示例#14
0
def test_updateannotationschema_denies_permissions_changes_if_not_admin(
        annotation, authn_policy):
    """If a user is not an admin on an annotation, they cannot change perms."""
    authn_policy.authenticated_userid.return_value = 'acct:[email protected]'
    request = testing.DummyRequest()
    schema = schemas.UpdateAnnotationSchema(request, annotation)
    data = {'permissions': {'admin': ['acct:[email protected]']}}

    with pytest.raises(schemas.ValidationError) as exc:
        schema.validate(data)

    assert exc.value.message.startswith('permissions:')
示例#15
0
def test_updateannotationschema_allows_permissions_changes_if_admin(
        authn_policy):
    """If a user is an admin on an annotation, they can change perms."""
    authn_policy.authenticated_userid.return_value = 'acct:[email protected]'
    request = testing.DummyRequest()
    annotation = {'permissions': {'admin': ['acct:[email protected]']}}
    schema = schemas.UpdateAnnotationSchema(request, annotation)
    data = {'permissions': {'admin': ['acct:[email protected]']}}

    result = schema.validate(data)

    assert result == data
示例#16
0
    def test_it_replaces_shared_permissions_with_shared_True(self):
        schema = schemas.UpdateAnnotationSchema(testing.DummyRequest(), '',
                                                '__world__')

        appstruct = schema.validate(
            {'permissions': {
                'read': ['group:__world__']
            }})

        assert appstruct['shared'] is True
        assert 'permissions' not in appstruct
        assert 'permissions' not in appstruct.get('extras', {})
示例#17
0
文件: views.py 项目: openbizgit/h
def update(context, request):
    """Update the fields we received and store the updated version."""
    annotation = context.model
    schema = schemas.UpdateAnnotationSchema(request, annotation)
    appstruct = schema.validate(_json_payload(request))

    # Update and store the annotation
    logic.update_annotation(annotation, appstruct)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'update')

    # Return the updated version that was just stored.
    return search_lib.render(annotation)
示例#18
0
    def test_it_passes_existing_target_uri_to_document_metas_from_data(
            self, parse_document_claims):
        """
        If no 'uri' is given it should use the existing target_uri.

        If no 'uri' is given in the update request then
        document_metas_from_data() should be called with the existing
        target_uri of the annotation in the database.

        """
        document_data = {'foo': 'bar'}
        schema = schemas.UpdateAnnotationSchema(testing.DummyRequest(),
                                                mock.sentinel.target_uri, '')

        schema.validate({'document': document_data})

        parse_document_claims.document_metas_from_data.assert_called_once_with(
            document_data, claimant=mock.sentinel.target_uri)
示例#19
0
def update_annotation_schema_validate(data,
                                      existing_target_uri='',
                                      groupid=''):
    schema = schemas.UpdateAnnotationSchema(testing.DummyRequest(),
                                            existing_target_uri, groupid)
    return schema.validate(data)