def test_it_copies_target_uri_normalized_to_target_scope(self): annotation = mock.Mock( target_uri_normalized='http://example.com/normalized', extra={}) annotation_dict = AnnotationSearchIndexPresenter(annotation).asdict() assert annotation_dict['target'][0]['scope'] == [ 'http://example.com/normalized' ]
def test_it_does_not_mark_annotation_hidden_when_not_moderated_and_no_replies( self, pyramid_request): thread_ids = [] annotation = mock.MagicMock(userid='acct:[email protected]', thread_ids=thread_ids) annotation_dict = AnnotationSearchIndexPresenter( annotation, pyramid_request).asdict() assert annotation_dict['hidden'] is False
def test_it_marks_annotation_hidden_when_moderated_and_no_replies( self, pyramid_request, moderation_service): annotation = mock.MagicMock(userid='acct:[email protected]') moderation_service.hidden.return_value = True annotation_dict = AnnotationSearchIndexPresenter( annotation, pyramid_request).asdict() assert annotation_dict['hidden'] is True
def test_it_does_not_mark_annotation_hidden_when_it_is_not_moderated( self, pyramid_request, moderation_service, thread_ids): annotation = mock.MagicMock(userid='acct:[email protected]', thread_ids=thread_ids) moderation_service.all_hidden.return_value = thread_ids annotation_dict = AnnotationSearchIndexPresenter( annotation, pyramid_request).asdict() assert annotation_dict['hidden'] is False
def test_it_does_not_mark_annotation_hidden_when_children_are_not_moderated( self, pyramid_request, moderation_service, thread_ids): annotation = mock.MagicMock(userid="acct:[email protected]", thread_ids=thread_ids) moderation_service.all_hidden.return_value = [annotation.id ] + thread_ids[1:] annotation_dict = AnnotationSearchIndexPresenter( annotation, pyramid_request).asdict() assert annotation_dict["hidden"] is False
def test_it_copies_target_uri_normalized_to_target_scope( self, pyramid_request): annotation = mock.MagicMock( userid='acct:[email protected]', target_uri_normalized='http://example.com/normalized', extra={}) annotation_dict = AnnotationSearchIndexPresenter( annotation, pyramid_request).asdict() assert annotation_dict['target'][0]['scope'] == [ 'http://example.com/normalized' ]
def test_it_marks_annotation_hidden_when_moderated_and_no_replies( self, pyramid_request, moderation_service): thread_ids = [] annotation = mock.MagicMock(userid="acct:[email protected]", thread_ids=thread_ids) moderation_service.all_hidden.return_value = [annotation.id ] + thread_ids annotation_dict = AnnotationSearchIndexPresenter( annotation, pyramid_request).asdict() assert annotation_dict["hidden"] is True
def test_it_marks_annotation_nipsaed_correctly(self, pyramid_request, nipsa_service, is_nipsaed, factories): annotation = factories.Annotation.build() nipsa_service.is_flagged.return_value = is_nipsaed annotation_dict = AnnotationSearchIndexPresenter( annotation, pyramid_request).asdict() if is_nipsaed: assert annotation_dict["nipsa"] else: assert "nipsa" not in annotation_dict
def test_it_copies_target_uri_normalized_to_target_scope( self, pyramid_request): annotation = mock.MagicMock( userid="acct:[email protected]", target_uri_normalized="http://example.com/normalized", extra={}, ) annotation_dict = AnnotationSearchIndexPresenter( annotation, pyramid_request).asdict() assert annotation_dict["target"][0]["scope"] == [ "http://example.com/normalized" ]
def test_asdict(self, DocumentSearchIndexPresenter): annotation = mock.Mock( id='xyz123', created=datetime.datetime(2016, 2, 24, 18, 3, 25, 768), updated=datetime.datetime(2016, 2, 29, 10, 24, 5, 564), userid='acct:[email protected]', target_uri='http://example.com', target_uri_normalized='http://example.com/normalized', text='It is magical!', tags=['magic'], groupid='__world__', shared=True, target_selectors=[{'TestSelector': 'foobar'}], references=['referenced-id-1', 'referenced-id-2'], thread_ids=['thread-id-1', 'thread-id-2'], extra={'extra-1': 'foo', 'extra-2': 'bar'}) DocumentSearchIndexPresenter.return_value.asdict.return_value = {'foo': 'bar'} annotation_dict = AnnotationSearchIndexPresenter(annotation).asdict() assert annotation_dict == { 'authority': 'hypothes.is', 'id': 'xyz123', 'created': '2016-02-24T18:03:25.000768+00:00', 'updated': '2016-02-29T10:24:05.000564+00:00', 'user': '******', 'user_raw': 'acct:[email protected]', 'uri': 'http://example.com', 'text': 'It is magical!', 'tags': ['magic'], 'tags_raw': ['magic'], 'group': '__world__', 'shared': True, 'target': [{'scope': ['http://example.com/normalized'], 'source': 'http://example.com', 'selector': [{'TestSelector': 'foobar'}]}], 'document': {'foo': 'bar'}, 'references': ['referenced-id-1', 'referenced-id-2'], 'thread_ids': ['thread-id-1', 'thread-id-2'], }
def test_asdict(self, DocumentSearchIndexPresenter, pyramid_request): annotation = mock.MagicMock( id="xyz123", created=datetime.datetime(2016, 2, 24, 18, 3, 25, 768), updated=datetime.datetime(2016, 2, 29, 10, 24, 5, 564), userid="acct:[email protected]", text="It is magical!", tags=["magic"], groupid="__world__", shared=True, references=["referenced-id-1", "referenced-id-2"], thread_ids=["thread-id-1", "thread-id-2"], extra={"extra-1": "foo", "extra-2": "bar"}, ) DocumentSearchIndexPresenter.return_value.asdict.return_value = {"foo": "bar"} annotation_dict = AnnotationSearchIndexPresenter( annotation, pyramid_request ).asdict() assert annotation_dict == { "authority": "hypothes.is", "id": "xyz123", "created": "2016-02-24T18:03:25.000768+00:00", "updated": "2016-02-29T10:24:05.000564+00:00", "user": "******", "user_raw": "acct:[email protected]", "uri": annotation.target_uri, "text": "It is magical!", "tags": ["magic"], "tags_raw": ["magic"], "group": "__world__", "shared": True, "target": annotation.target, "document": {"foo": "bar"}, "references": ["referenced-id-1", "referenced-id-2"], "thread_ids": ["thread-id-1", "thread-id-2"], "hidden": False, }
def test_it_marks_annotation_hidden_correctly(self, pyramid_request, moderation_service, is_moderated, replies_moderated): # Annotation reply ids are referred to as thread_ids in our code base. reply_ids = ["thread-id-1", "thread-id-2"] annotation = mock.MagicMock(userid="acct:[email protected]", thread_ids=reply_ids) # Configure moderation return value moderated_ids = [] if is_moderated: moderated_ids.append(annotation.id) if replies_moderated: moderated_ids.extend(reply_ids) moderation_service.all_hidden.return_value = moderated_ids annotation_dict = AnnotationSearchIndexPresenter( annotation, pyramid_request).asdict() # We are hidden if both we, and all of our replies are moderated assert annotation_dict["hidden"] == bool(is_moderated and replies_moderated)