Example #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]')
Example #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
Example #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
Example #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
Example #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
Example #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]")
Example #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]')
Example #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]",
        }
Example #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]"
        )
Example #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]"]
        )
Example #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]'])
Example #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)
Example #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]")
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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)
Example #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]")
Example #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)
Example #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)
Example #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)
Example #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]'])
Example #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]")
Example #26
0
 def svc(self, db_session, search_index):
     return NipsaService(db_session, lambda: search_index)
Example #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]')
Example #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]'])
Example #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]")
Example #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]")
Example #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]")
Example #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
Example #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]")
Example #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
Example #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]")
Example #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
Example #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]")
Example #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]"]
        )
Example #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
Example #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]")