def test_flag_adds_record_to_database(self, db_session): svc = NipsaService(db_session) svc.flag('acct:[email protected]') user_query = db_session.query(NipsaUser).filter_by(userid='acct:[email protected]') assert user_query.one_or_none() is not None
def test_unflag_removes_record_from_database(self, db_session): svc = NipsaService(db_session) svc.unflag('acct:[email protected]') user_query = db_session.query(NipsaUser).filter_by(userid='acct:[email protected]') assert user_query.one_or_none() is None
def test_unflag_is_idempotent(self, db_session): svc = NipsaService(db_session) svc.unflag('acct:[email protected]') svc.unflag('acct:[email protected]') user_query = db_session.query(NipsaUser).filter_by(userid='acct:[email protected]') assert user_query.one_or_none() is None
def test_unflag_removes_record_from_database(self, db_session): svc = NipsaService(db_session) svc.unflag('acct:[email protected]') user_query = db_session.query(NipsaUser).filter_by( userid='acct:[email protected]') assert user_query.one_or_none() is None
def test_flag_adds_record_to_database(self, db_session): svc = NipsaService(db_session) svc.flag('acct:[email protected]') user_query = db_session.query(NipsaUser).filter_by( userid='acct:[email protected]') assert user_query.one_or_none() is not None
def test_unflag_is_idempotent(self, db_session): svc = NipsaService(db_session) svc.unflag('acct:[email protected]') svc.unflag('acct:[email protected]') user_query = db_session.query(NipsaUser).filter_by( userid='acct:[email protected]') assert user_query.one_or_none() is None
def test_flagged_userids_returns_list_of_userids(self, db_session): svc = NipsaService(db_session) assert set(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_) # FIXME: It isn't really nice to try and get the userid from the fetched # annotation or otherwise get it from the maybe-already serialized # annotation dict, to then only access the database for the nipsa flag once. # We do this because the event action is `delete` at which point we can't # load the annotation from the database. Handling annotation deletions is # a known problem and will be fixed in the future. userid = None if annotation: userid = annotation.userid else: userid = message.get('annotation_dict', {}).get('userid') nipsa_service = NipsaService(session) user_nipsad = nipsa_service.is_flagged(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_is_flagged_returns_false_for_unflagged_userids(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_is_flagged_returns_true_for_flagged_userids(self, db_session): svc = NipsaService(db_session) assert svc.is_flagged('acct:[email protected]') assert svc.is_flagged('acct:[email protected]')
def test_unflag_triggers_remove_nipsa_job(self, db_session, users, worker): svc = NipsaService(db_session) svc.unflag(users['renata']) worker.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, worker): svc = NipsaService(db_session) svc.flag(users['dominic']) worker.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