def test_get_sessions_by_username_multiple(self): to_insert = [ VIOSCREEN_SESSION.copy(), VIOSCREEN_SESSION.copy(), VIOSCREEN_SESSION.copy() ] # NOTE: the username is held constant across these records. This # emulates a user haveing multiple FFQ sessions to_insert[0].sessionId = 'session1' to_insert[1].sessionId = 'session2' to_insert[2].sessionId = 'session3' to_insert[0].created = _to_dt(1, 1, 1970) to_insert[1].created = _to_dt(1, 1, 1980) to_insert[2].created = _to_dt(1, 1, 1990) # the third entry, while started the latest, does not have an enddate # so cannot be complete to_insert[0].endDate = _to_dt(1, 1, 1971) to_insert[1].endDate = _to_dt(1, 1, 1981) to_insert[2].endDate = None with Transaction() as t: r = VioscreenSessionRepo(t) for record in to_insert: obs = r.upsert_session(record) self.assertEqual(obs, True) obs = r.get_sessions_by_username(VIOSCREEN_SESSION.username) self.assertEqual(obs, to_insert)
def test_get_sessions_by_username_exists(self): with Transaction() as t: r = VioscreenSessionRepo(t) obs = r.upsert_session(VIOSCREEN_SESSION) self.assertEqual(obs, True) obs = r.get_sessions_by_username(VIOSCREEN_SESSION.username) self.assertEqual(obs, [ VIOSCREEN_SESSION, ])
def _get_session_by_account_details(account_id, source_id, sample_id): with Transaction() as t: surv_temp = SurveyTemplateRepo(t) vio_sess = VioscreenSessionRepo(t) vio_username = surv_temp.get_vioscreen_id_if_exists( account_id, source_id, sample_id) if vio_username is None: return True, (jsonify(code=404, message="Username not found"), 404) vioscreen_session = vio_sess.get_sessions_by_username(vio_username) if vioscreen_session is None: return True, (jsonify(code=404, message="Session not found"), 404) return False, vioscreen_session
def test_get_ffq_status_by_sample(self): session_copy = VIOSCREEN_SESSION.copy() session_copy.username = VIOSCREEN_USERNAME1 with Transaction() as t: r = VioscreenSessionRepo(t) r.upsert_session(session_copy) session = r.get_sessions_by_username(VIOSCREEN_USERNAME1)[0] obs = r.get_ffq_status_by_sample(BARCODE_UUID_NOTIN_REGISTRY) self.assertEqual(obs, (False, False, None)) session.status = 'Finished' session.endDate = _to_dt(2, 1, 1970) r.upsert_session(session) # enumerate the empirically observed states from vioscreen # (is_complete, has_taken, exact_status) obs = r.get_ffq_status_by_sample(BARCODE_UUID_FOR_VIOSESSION) self.assertEqual(obs, (True, True, 'Finished')) session.status = 'Started' session.endDate = None r.upsert_session(session) obs = r.get_ffq_status_by_sample(BARCODE_UUID_FOR_VIOSESSION) self.assertEqual(obs, (False, True, 'Started')) session.status = 'New' r.upsert_session(session) obs = r.get_ffq_status_by_sample(BARCODE_UUID_FOR_VIOSESSION) self.assertEqual(obs, (False, False, 'New')) session.status = 'Review' r.upsert_session(session) obs = r.get_ffq_status_by_sample(BARCODE_UUID_FOR_VIOSESSION) self.assertEqual(obs, (False, True, 'Review'))
def test_get_sessions_by_username_does_not_exist(self): with Transaction() as t: r = VioscreenSessionRepo(t) obs = r.get_sessions_by_username('does not exist') self.assertEqual(obs, None)