示例#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
示例#2
0
文件: storage.py 项目: ackermann/h
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)
示例#3
0
文件: storage.py 项目: 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)
示例#4
0
文件: storage.py 项目: VanyTang/h
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
示例#5
0
文件: storage.py 项目: VanyTang/h
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
示例#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)
示例#7
0
def test_prepare_adds_scope_field(_, ann_in, ann_out, uri_normalize):
    transform.prepare(ann_in)
    assert ann_in == ann_out
示例#8
0
def test_prepare_noop_when_nothing_to_normalize(_, ann_in, ann_out):
    transform.prepare(ann_in)
    assert ann_in == ann_out
示例#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)
示例#10
0
def test_prepare_transforms_old_style_comments(groups, ann_in, ann_out):
    transform.prepare(ann_in)
    assert ann_in == ann_out