Ejemplo n.º 1
0
    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]')
Ejemplo n.º 2
0
    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
Ejemplo n.º 3
0
    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
Ejemplo n.º 4
0
    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
Ejemplo n.º 5
0
    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
Ejemplo n.º 6
0
    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]")
Ejemplo n.º 7
0
    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]')
Ejemplo n.º 8
0
    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]",
        }
Ejemplo n.º 9
0
    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]"
        )
Ejemplo n.º 10
0
    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]"]
        )
Ejemplo n.º 11
0
    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]'])
Ejemplo n.º 12
0
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)
Ejemplo n.º 13
0
    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]")
Ejemplo n.º 14
0
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)
Ejemplo n.º 15
0
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)
Ejemplo n.º 16
0
    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)
Ejemplo n.º 17
0
    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)
Ejemplo n.º 18
0
    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)
Ejemplo n.º 19
0
    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)
Ejemplo n.º 20
0
    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]")
Ejemplo n.º 21
0
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)
Ejemplo n.º 22
0
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)
Ejemplo n.º 23
0
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)
Ejemplo n.º 24
0
    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]'])
Ejemplo n.º 25
0
    def test_is_flagged_returns_false_for_unknown_users(self, db_session):
        svc = NipsaService(db_session)

        assert not svc.is_flagged("acct:[email protected]")
Ejemplo n.º 26
0
 def svc(self, db_session, search_index):
     return NipsaService(db_session, lambda: search_index)
Ejemplo n.º 27
0
    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]')
Ejemplo n.º 28
0
    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]'])
Ejemplo n.º 29
0
    def test_is_flagged_returns_false_for_unknown_users(self, db_session):
        svc = NipsaService(db_session)

        assert not svc.is_flagged("acct:[email protected]")
Ejemplo n.º 30
0
    def test_is_flagged_returns_false_for_unflagged_users(self, db_session):
        svc = NipsaService(db_session)

        assert not svc.is_flagged("acct:[email protected]")
Ejemplo n.º 31
0
    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]")
Ejemplo n.º 32
0
    def test_flag_sets_nipsa_true(self, db_session, users):
        svc = NipsaService(db_session)

        svc.flag(users['dominic'])

        assert users['dominic'].nipsa is True
Ejemplo n.º 33
0
    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]")
Ejemplo n.º 34
0
    def test_unflag_sets_nipsa_false(self, db_session, users):
        svc = NipsaService(db_session)

        svc.unflag(users["renata"])

        assert users["renata"].nipsa is False
Ejemplo n.º 35
0
    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]")
Ejemplo n.º 36
0
    def test_flag_sets_nipsa_true(self, db_session, users):
        svc = NipsaService(db_session)

        svc.flag(users["dominic"])

        assert users["dominic"].nipsa is True
Ejemplo n.º 37
0
    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]")
Ejemplo n.º 38
0
    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]"]
        )
Ejemplo n.º 39
0
    def test_unflag_sets_nipsa_false(self, db_session, users):
        svc = NipsaService(db_session)

        svc.unflag(users['renata'])

        assert users['renata'].nipsa is False
Ejemplo n.º 40
0
    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]")