def test_clears_cache_on_transaction_end(self, patch, db_session, factories): funcs = {} # We need to capture the inline `clear_cache` function so we can # call it manually later def on_transaction_end_decorator(session): def on_transaction_end(func): funcs['clear_cache'] = func return on_transaction_end decorator = patch('h.services.user.util.db.on_transaction_end') decorator.side_effect = on_transaction_end_decorator group = factories.Group() pubid = group.pubid svc = GroupfinderService(db_session, 'example.com') svc.find(pubid) db_session.delete(group) funcs['clear_cache']() group = svc.find(pubid) assert group is None
def test_sets_up_cache_clearing_on_transaction_end(self, patch, db_session): decorator = patch('h.services.groupfinder.util.db.on_transaction_end') GroupfinderService(db_session, 'example.com') decorator.assert_called_once_with(db_session)
def handle_annotation_event(message, sockets, settings, session): id_ = message['annotation_id'] annotation = storage.fetch_annotation(session, id_) if annotation is None: log.warn('received annotation event for missing annotation: %s', id_) return nipsa_service = NipsaService(session) user_nipsad = nipsa_service.is_flagged(annotation.userid) authority = text_type(settings.get('h.authority', 'localhost')) group_service = GroupfinderService(session, authority) for socket in sockets: reply = _generate_annotation_event(message, socket, annotation, user_nipsad, group_service) if reply is None: continue socket.send_json(reply)
def handle_annotation_event(message, sockets, settings, session): id_ = message["annotation_id"] annotation = storage.fetch_annotation(session, id_) if annotation is None: log.warning("received annotation event for missing annotation: %s", id_) return # Find connected clients which are interested in this annotation. matching_sockets = SocketFilter.matching(sockets, annotation) try: # Check to see if the generator has any items first_socket = next(matching_sockets) except StopIteration: # Nothing matched return # Create a generator which has the first socket back again matching_sockets = chain((first_socket, ), matching_sockets) nipsa_service = NipsaService(session) user_nipsad = nipsa_service.is_flagged(annotation.userid) authority = settings.get("h.authority", "localhost") group_service = GroupfinderService(session, authority) user_service = UserService(authority, session) formatters = [AnnotationUserInfoFormatter(session, user_service)] for socket in matching_sockets: reply = _generate_annotation_event(message, socket, annotation, user_nipsad, group_service, formatters) if reply is None: continue socket.send_json(reply)
def handle_annotation_event(message, sockets, settings, session): id_ = message["annotation_id"] annotation = storage.fetch_annotation(session, id_) if annotation is None: log.warning("received annotation event for missing annotation: %s", id_) return nipsa_service = NipsaService(session) user_nipsad = nipsa_service.is_flagged(annotation.userid) authority = text_type(settings.get("h.authority", "localhost")) group_service = GroupfinderService(session, authority) user_service = UserService(authority, session) formatters = [AnnotationUserInfoFormatter(session, user_service)] for socket in sockets: reply = _generate_annotation_event(message, socket, annotation, user_nipsad, group_service, formatters) if reply is None: continue socket.send_json(reply)
def svc(self, db_session): return GroupfinderService(db_session, "example.com")