Exemplo n.º 1
0
def test_prepare_sets_nipsa_field(_, ann, nipsa, has_nipsa):
    has_nipsa.return_value = nipsa
    transform.prepare(ann)
    if nipsa:
        assert ann["nipsa"] is True
    else:
        assert "nipsa" not in ann
Exemplo n.º 2
0
def _prepare(request, annotation):
    """Prepare the given annotation for storage."""
    fetcher = partial(fetch_annotation, request, _postgres=False)
    transform.prepare(annotation, fetcher)

    # Fire an AnnotationBeforeSaveEvent so subscribers who wish to modify an
    # annotation before save can do so.
    event = AnnotationBeforeSaveEvent(request, annotation)
    request.registry.notify(event)
Exemplo n.º 3
0
Arquivo: storage.py Projeto: fchasen/h
def _prepare(request, annotation):
    """Prepare the given annotation for storage."""
    fetcher = partial(fetch_annotation, request, _postgres=False)
    transform.prepare(annotation, fetcher)

    # Fire an AnnotationTransformEvent so subscribers who wish to modify an
    # annotation before save can do so.
    event = AnnotationTransformEvent(request, annotation)
    request.registry.notify(event)
Exemplo n.º 4
0
def create_annotation(data):
    """
    Create an annotation from passed data.

    :param data: a dictionary of annotation properties
    :type data: dict

    :returns: the created annotation
    :rtype: dict
    """
    annotation = models.Annotation(data)

    # FIXME: this should happen when indexing, not storing.
    transform.prepare(annotation)

    annotation.save()
    return annotation
Exemplo n.º 5
0
def update_annotation(id, data):
    """
    Update the annotation with the given id from passed data.

    This executes a partial update of the annotation identified by `id` using
    the passed data.

    :param id: the annotation id
    :type id: str
    :param data: a dictionary of annotation properties
    :type data: dict

    :returns: the updated annotation
    :rtype: dict
    """
    annotation = models.Annotation.fetch(id)
    annotation.update(data)

    # FIXME: this should happen when indexing, not storing.
    transform.prepare(annotation)

    annotation.save()
    return annotation
Exemplo n.º 6
0
def test_prepare_calls_set_group_if_reply(groups):
    annotation = {'permissions': {'read': []}}

    transform.prepare(annotation)

    groups.set_group_if_reply.assert_called_once_with(annotation)
Exemplo n.º 7
0
def test_prepare_adds_scope_field(_, ann_in, ann_out, uri_normalize):
    transform.prepare(ann_in)
    assert ann_in == ann_out
Exemplo n.º 8
0
def test_prepare_noop_when_nothing_to_normalize(_, ann_in, ann_out):
    transform.prepare(ann_in)
    assert ann_in == ann_out
Exemplo n.º 9
0
def test_prepare_calls_insert_group(groups):
    annotation = {'permissions': {'read': []}}

    transform.prepare(annotation)

    groups.insert_group_if_none.assert_called_once_with(annotation)
Exemplo n.º 10
0
def test_prepare_transforms_old_style_comments(groups, ann_in, ann_out):
    transform.prepare(ann_in)
    assert ann_in == ann_out