def session(self, db_session, added_ann_id, changed_ann_id, deleted_ann_id): # Populate the DB session with different types of change relative to the # last-committed state. We could use any model object for this purpose # but annotations are the primary object in the system. doc = Document(web_uri="https://example.org") changed = Annotation(id=changed_ann_id, userid="foo", groupid="wibble", document=doc) deleted = Annotation(id=deleted_ann_id, userid="foo", groupid="wibble", document=doc) db_session.add(changed) db_session.add(deleted) db_session.commit() changed.text = "changed text" db_session.delete(deleted) added = Annotation(id=added_ann_id, userid="foo", groupid="wibble", document=doc) db_session.add(added) return db_session
def test_generate_notifications_empty_if_action_not_create(): """If the action is not 'create', no notifications should be generated.""" annotation = Annotation() request = DummyRequest() notifications = rt.generate_notifications(request, annotation, 'update') assert list(notifications) == []
def reply(self): common = { "id": "bar456", "created": datetime.datetime.utcnow(), "updated": datetime.datetime.utcnow(), "text": "No it is not!", } return Annotation(target_uri="http://example.org/", **common)
def annotation(db_session): from h.models import Annotation ann = Annotation(userid='acct:testuser@localhost', groupid='__world__', shared=True) db_session.add(ann) db_session.commit() return ann
def parent(self): common = { 'id': 'foo123', 'created': datetime.datetime.utcnow(), 'updated': datetime.datetime.utcnow(), 'text': 'Foo is true', } return Annotation(target_uri='http://example.org/', **common)
def parent(self): common = { "id": "foo123", "created": datetime.datetime.utcnow(), "updated": datetime.datetime.utcnow(), "text": "Foo is true", } return Annotation(target_uri="http://example.org/", **common)
def reply(self): common = { 'id': 'bar456', 'created': datetime.datetime.utcnow(), 'updated': datetime.datetime.utcnow(), 'text': 'No it is not!', } return Annotation(target_uri='http://example.org/', **common)
def test_og_no_document(pyramid_request, group_service, links_service, sidebar_app): annotation = Annotation(id='123', userid='foo', target_uri='http://example.com') context = AnnotationResource(annotation, group_service, links_service) sidebar_app.side_effect = _fake_sidebar_app ctx = main.annotation_page(context, pyramid_request) def test(d): return 'foo' in d['content'] assert any(test(d) for d in ctx['meta_attrs'])
def group_with_two_users(db_session, factories): """ Create a group with two members and an annotation created by each. """ creator = factories.User() member = factories.User() group = Group(authority=creator.authority, creator=creator, members=[creator, member], name='test', pubid='group_with_two_users') db_session.add(group) doc = Document(web_uri='https://example.org') creator_ann = Annotation(userid=creator.userid, groupid=group.pubid, document=doc) member_ann = Annotation(userid=member.userid, groupid=group.pubid, document=doc) db_session.add(creator_ann) db_session.add(member_ann) db_session.flush() return (group, creator, member, creator_ann, member_ann)
def reply(self, storage_driver): common = { 'id': 'bar456', 'created': datetime.datetime.utcnow(), 'updated': datetime.datetime.utcnow(), 'text': 'No it is not!', } uri = 'http://example.org/' if storage_driver == 'elastic': return elastic.Annotation(uri=uri, **common) else: return Annotation(target_uri=uri, **common)
def parent(self, storage_driver): common = { 'id': 'foo123', 'created': datetime.datetime.utcnow(), 'updated': datetime.datetime.utcnow(), 'text': 'Foo is true', } uri = 'http://example.org/' if storage_driver == 'elastic': return elastic.Annotation(uri=uri, **common) else: return Annotation(target_uri=uri, **common)
def test_og_no_document( pyramid_request, groupfinder_service, links_service, sidebar_app ): annotation = Annotation(id="123", userid="foo", target_uri="http://example.com") context = AnnotationContext(annotation, groupfinder_service, links_service) sidebar_app.side_effect = _fake_sidebar_app ctx = main.annotation_page(context, pyramid_request) expected = Any.dict.containing({"content": Any.string.containing("foo")}) assert expected in ctx["meta_attrs"]
def broadcast_from_queue(queue, sockets): """ Pulls messages from a passed queue object, and handles dispatching them to appropriate active sessions. """ for message in queue: data_in = json.loads(message.body) action = data_in['action'] annotation = Annotation(**data_in['annotation']) payload = _annotation_packet([annotation], action) data_out = json.dumps(payload) for socket in list(sockets): if should_send_event(socket, annotation, data_in): socket.send(data_out)
def test_og_no_document(pyramid_request, group_service, links_service, sidebar_app): annotation = Annotation(id="123", userid="foo", target_uri="http://example.com") context = AnnotationContext(annotation, group_service, links_service) sidebar_app.side_effect = _fake_sidebar_app ctx = main.annotation_page(context, pyramid_request) def test(d): return "foo" in d["content"] assert any(test(d) for d in ctx["meta_attrs"])
def reply(self, annotations, parent): # We need to create a document object to provide the title, and # ensure it is associated with the annotation through the # annotation's `target_uri` doc = Document.find_or_create_by_uris(db.Session, claimant_uri='http://example.net/foo', uris=[]).one() doc.meta.append(DocumentMeta(type='title', value=['Some document'], claimant='http://example.com/foo')) reply = Annotation(**FIXTURE_DATA['reply']) reply.target_uri = 'http://example.net/foo' reply.references = [parent.id] db.Session.add(reply) db.Session.flush() annotations[reply.id] = reply return reply
def _create_annotation(fields, user): """Create and store an annotation""" # Some fields are not to be set by the user, ignore them for field in PROTECTED_FIELDS: fields.pop(field, None) # Create Annotation instance annotation = Annotation(fields) annotation['user'] = user.id annotation['consumer'] = user.consumer.key # Save it in the database annotation.save() log.debug('Created annotation; user: %s, consumer key: %s', annotation['user'], annotation['consumer']) return annotation
def handle_annotation_event(message, socket): """ Get message about annotation event `message` to be sent to `socket`. Inspects the embedded annotation event and decides whether or not the passed socket should receive notification of the event. Returns None if the socket should not receive any message about this annotation event, otherwise a dict containing information about the event. """ action = message['action'] annotation = Annotation(**message['annotation']) if action == 'read': return None if message['src_client_id'] == socket.client_id: return None if annotation.get('nipsa') and (socket.request.authenticated_userid != annotation.get('user', '')): return None if not _authorized_to_read(socket.request, annotation): return None # We don't send anything until we have received a filter from the client if socket.filter is None: return None if not socket.filter.match(annotation, action): return None return { 'payload': [annotation], 'type': 'annotation-notification', 'options': { 'action': action }, }
def parent(self, annotations): parent = Annotation(**FIXTURE_DATA['parent']) annotations[parent.id] = parent return parent
def fetch(request): patcher = patch.object(Annotation, 'fetch') func = patcher.start() func.side_effect = lambda x: Annotation(**store_fake_data[int(x)]) request.addfinalizer(patcher.stop) return func