def test_unflag_triggers_remove_nipsa_job(self, db_session, users, remove_nipsa): svc = NipsaService(db_session) svc.unflag(users['renata']) remove_nipsa.delay.assert_called_once_with('acct:[email protected]')
def test_flag_sets_nipsa_true(self, db_session, users): svc = NipsaService(db_session) svc.flag(users["dominic"]) assert svc.is_flagged("acct:[email protected]") assert users["dominic"].nipsa is True
def test_unflag_sets_nipsa_false(self, db_session, users): svc = NipsaService(db_session) svc.unflag(users["renata"]) assert not svc.is_flagged("acct:[email protected]") assert users["renata"].nipsa is False
def test_unflag_triggers_reindex_job(self, db_session, users, reindex_user_annotations): svc = NipsaService(db_session) svc.unflag(users["renata"]) reindex_user_annotations.delay.assert_called_once_with( "acct:[email protected]")
def test_flag_triggers_reindex_job(self, db_session, users, reindex_user_annotations): svc = NipsaService(db_session) svc.flag(users['dominic']) reindex_user_annotations.delay.assert_called_once_with( 'acct:[email protected]')
def test_fetch_all_flagged_userids_returns_set_of_userids( self, db_session): svc = NipsaService(db_session) assert svc.fetch_all_flagged_userids() == { "acct:[email protected]", "acct:[email protected]", }
def test_unflag_triggers_reindex_job( self, db_session, users, reindex_user_annotations ): svc = NipsaService(db_session) svc.unflag(users["renata"]) reindex_user_annotations.delay.assert_called_once_with( "acct:[email protected]" )
def test_fetch_all_flagged_userids_caches_lookup(self, db_session, users): svc = NipsaService(db_session) svc.fetch_all_flagged_userids() users["renata"].nipsa = False # Returns `True` because status is cached. assert svc.is_flagged("acct:[email protected]") assert svc.fetch_all_flagged_userids() == set( ["acct:[email protected]", "acct:[email protected]"] )
def test_clear_resets_cache(self, db_session, users): svc = NipsaService(db_session) assert svc.flagged_userids == set(['acct:[email protected]', 'acct:[email protected]']) users['dominic'].nipsa = True svc.clear() assert svc.flagged_userids == set(['acct:[email protected]', 'acct:[email protected]', 'acct:[email protected]'])
def handle_annotation_event(message, sockets, 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) for socket in sockets: reply = _generate_annotation_event(message, socket, annotation, user_nipsad) if reply is None: continue socket.send_json(reply)
def test_clear_resets_cache(self, db_session, users): svc = NipsaService(db_session) svc.fetch_all_flagged_userids() users["renata"].nipsa = False svc.clear() assert not svc.is_flagged("acct:[email protected]")
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 test_flag_updates_cache(self, db_session, users): svc = NipsaService(db_session) svc.fetch_all_flagged_userids() svc.flag(users["dominic"]) users[ "dominic"].nipsa = False # Make sure result below comes from cache. assert svc.is_flagged(users["dominic"].userid)
def test_unflag_updates_cache(self, db_session, users): svc = NipsaService(db_session) svc.fetch_all_flagged_userids() svc.unflag(users["renata"]) users[ "renata"].nipsa = True # Make sure result below comes from cache. assert not svc.is_flagged(users["renata"].userid)
def test_flag_updates_cache(self, db_session, users): svc = NipsaService(db_session) svc.fetch_all_flagged_userids() svc.flag(users["dominic"]) users["dominic"].nipsa = False # Make sure result below comes from cache. assert svc.is_flagged(users["dominic"].userid)
def test_unflag_updates_cache(self, db_session, users): svc = NipsaService(db_session) svc.fetch_all_flagged_userids() svc.unflag(users["renata"]) users["renata"].nipsa = True # Make sure result below comes from cache. assert not svc.is_flagged(users["renata"].userid)
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 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 test_fetch_all_flagged_userids_caches_lookup(self, db_session, users): svc = NipsaService(db_session) svc.fetch_all_flagged_userids() users['renata'].nipsa = False # Returns `True` because status is cached. assert svc.is_flagged('acct:[email protected]') assert svc.fetch_all_flagged_userids() == set( ['acct:[email protected]', 'acct:[email protected]'])
def test_is_flagged_returns_false_for_unknown_users(self, db_session): svc = NipsaService(db_session) assert not svc.is_flagged("acct:[email protected]")
def svc(self, db_session, search_index): return NipsaService(db_session, lambda: search_index)
def test_flag_triggers_add_nipsa_job(self, db_session, users, add_nipsa): svc = NipsaService(db_session) svc.flag(users['dominic']) add_nipsa.delay.assert_called_once_with('acct:[email protected]')
def test_flagged_userids_returns_set_of_userids(self, db_session): svc = NipsaService(db_session) assert svc.flagged_userids == set( ['acct:[email protected]', 'acct:[email protected]'])
def test_is_flagged_returns_false_for_unflagged_users(self, db_session): svc = NipsaService(db_session) assert not svc.is_flagged("acct:[email protected]")
def test_is_flagged_returns_true_for_flagged_users(self, db_session, users): svc = NipsaService(db_session) assert svc.is_flagged("acct:[email protected]") assert svc.is_flagged("acct:[email protected]")
def test_flag_sets_nipsa_true(self, db_session, users): svc = NipsaService(db_session) svc.flag(users['dominic']) assert users['dominic'].nipsa is True
def test_unflag_triggers_remove_nipsa_job(self, db_session, users, remove_nipsa): svc = NipsaService(db_session) svc.unflag(users["renata"]) remove_nipsa.delay.assert_called_once_with("acct:[email protected]")
def test_unflag_sets_nipsa_false(self, db_session, users): svc = NipsaService(db_session) svc.unflag(users["renata"]) assert users["renata"].nipsa is False
def test_flag_triggers_add_nipsa_job(self, db_session, users, add_nipsa): svc = NipsaService(db_session) svc.flag(users["dominic"]) add_nipsa.delay.assert_called_once_with("acct:[email protected]")
def test_flag_sets_nipsa_true(self, db_session, users): svc = NipsaService(db_session) svc.flag(users["dominic"]) assert users["dominic"].nipsa is True
def test_is_flagged_returns_false_for_unflagged_users(self, db_session): svc = NipsaService(db_session) assert not svc.is_flagged("acct:[email protected]") assert not svc.is_flagged("acct:[email protected]")
def test_fetch_all_flagged_userids_returns_set_of_userids(self, db_session): svc = NipsaService(db_session) assert svc.fetch_all_flagged_userids() == set( ["acct:[email protected]", "acct:[email protected]"] )
def test_unflag_sets_nipsa_false(self, db_session, users): svc = NipsaService(db_session) svc.unflag(users['renata']) assert users['renata'].nipsa is False