def test_set_group_if_reply_calls_fetcher_if_reply(): fetcher = _fake_fetcher(None) annotation = {'references': ['parent_id']} transform.set_group_if_reply(annotation, fetcher=fetcher) fetcher.assert_called_once_with('parent_id')
def test_set_group_if_reply_adds_group_to_replies(): """If a reply has no group it gets the group of its parent annotation.""" fetcher = _fake_fetcher({'group': 'parent_group'}) annotation = {'references': ['parent_id']} transform.set_group_if_reply(annotation, fetcher=fetcher) assert annotation['group'] == "parent_group"
def test_set_group_if_reply_does_not_modify_non_replies(): fetcher = _fake_fetcher(None) # This annotation is not a reply. annotation = {'group': 'test-group'} transform.set_group_if_reply(annotation, fetcher=fetcher) assert annotation['group'] == 'test-group'
def test_set_group_if_reply_clears_group_if_parent_has_no_group(): fetcher = _fake_fetcher({}) annotation = { 'group': 'this should be deleted', 'references': ['parent_id'] } transform.set_group_if_reply(annotation, fetcher=fetcher) assert 'group' not in annotation
def test_set_group_if_reply_overwrites_groups_in_replies(): """If a reply has a group it's overwritten with the parent's group.""" fetcher = _fake_fetcher({'group': 'parent_group'}) annotation = { 'group': 'this should be overwritten', 'references': ['parent_id'] } transform.set_group_if_reply(annotation, fetcher=fetcher) assert annotation['group'] == "parent_group"
def _prepare(request, annotation): """ Prepare the given annotation for storage. Scan the passed annotation for any target URIs or document metadata URIs and add normalized versions of these to the document. """ fetcher = partial(fetch_annotation, request) transform.set_group_if_reply(annotation, fetcher=fetcher) transform.insert_group_if_none(annotation) transform.set_group_permissions(annotation) # FIXME: Remove this in a month or so, when all our clients have been # updated. -N 2015-09-25 transform.fix_old_style_comments(annotation) # FIXME: When this becomes simply part of a search indexing operation, this # should probably not mutate its argument. transform.normalize_annotation_target_uris(annotation) # 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 test_set_group_if_reply_does_nothing_if_parent_not_found(): fetcher = _fake_fetcher(None) annotation = {'references': ['parent_id']} transform.set_group_if_reply(annotation, fetcher=fetcher)