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
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)
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)
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
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
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)
def test_prepare_adds_scope_field(_, ann_in, ann_out, uri_normalize): transform.prepare(ann_in) assert ann_in == ann_out
def test_prepare_noop_when_nothing_to_normalize(_, ann_in, ann_out): transform.prepare(ann_in) assert ann_in == ann_out
def test_prepare_calls_insert_group(groups): annotation = {'permissions': {'read': []}} transform.prepare(annotation) groups.insert_group_if_none.assert_called_once_with(annotation)
def test_prepare_transforms_old_style_comments(groups, ann_in, ann_out): transform.prepare(ann_in) assert ann_in == ann_out