def test_sets_up_cache_clearing_on_transaction_end(self, patch, db_session): decorator = patch('h.services.user.on_transaction_end') UserService(default_authority='example.com', session=db_session) decorator.assert_called_once_with(db_session)
def test_clears_cache_on_transaction_end(self, patch, db_session, users): 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 jacqui, _, _ = users svc = UserService(default_authority='example.com', session=db_session) svc.fetch('acct:[email protected]') db_session.delete(jacqui) funcs['clear_cache']() user = svc.fetch('acct:[email protected]') assert user is None
def test_clears_cache_on_transaction_end(self, patch, db_session, users): 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.on_transaction_end") decorator.side_effect = on_transaction_end_decorator jacqui, _, _, _ = users svc = UserService(default_authority="example.com", session=db_session) svc.fetch("acct:[email protected]") db_session.delete(jacqui) funcs["clear_cache"]() user = svc.fetch("acct:[email protected]") assert user is None
def test_clears_cache_on_transaction_end(self, patch, db_session, users): funcs = {} # We need to capture the inline `clear_cache` function so we can # call it manually later def on_transaction_end_decorator(session): # pylint:disable=unused-argument def on_transaction_end(func): funcs["clear_cache"] = func return on_transaction_end decorator = patch("h.services.user.on_transaction_end") decorator.side_effect = on_transaction_end_decorator jacqui, _, _, _ = users svc = UserService(default_authority="example.com", session=db_session) svc.fetch("acct:[email protected]") db_session.delete(jacqui) funcs["clear_cache"]() user = svc.fetch("acct:[email protected]") assert user is None
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 user_service(db_session, pyramid_config): service = Mock(spec_set=UserService(default_authority='example.com', session=db_session)) service.fetch_for_login.return_value = None pyramid_config.register_service(service, name='user') return service
def user_service(db_session, pyramid_config): service = mock.Mock( spec=UserService(default_authority='example.com', session=db_session)) pyramid_config.register_service(service, name='user') return service
def svc(self, db_session): return UserService(default_authority='example.com', session=db_session)