def get_survey_list(session, tag): logger.info("Retrieving survey todo list") party_id = session.get('party_id') business_id = request.args.get('business_party_id') survey_id = request.args.get('survey_id') survey_list = party_controller.get_survey_list_details_for_party( party_id, tag, business_party_id=business_id, survey_id=survey_id) sorted_survey_list = sorted( survey_list, key=lambda k: datetime.strptime(k['submit_by'], '%d %b %Y')) if tag == 'todo': response = make_response( render_template( 'surveys/surveys-todo.html', sorted_surveys_list=sorted_survey_list, added_survey=True if business_id and survey_id else None)) # Ensure any return to list of surveys (e.g. browser back) round trips the server to display the latest statuses response.headers.set("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store") return response else: return render_template('surveys/surveys-history.html', sorted_surveys_list=sorted_survey_list, history=True)
def test_get_survey_list_details_for_party( self, get_respondent_enrolments, get_cases, get_collection_instrument, calculate_case_status, ): enrolments = [{ "business_id": business_party["id"], "survey_id": survey["id"] }] get_respondent_enrolments.return_value = enrolments get_cases.return_value = case_list get_collection_instrument.return_value = collection_instrument_seft calculate_case_status.return_value = "In Progress" with responses.RequestsMock() as rsps: rsps.add(rsps.GET, url_get_survey, json=survey, status=200) rsps.add(rsps.GET, url_get_business_party, json=business_party, status=200) rsps.add(rsps.GET, url_get_collection_exercises_by_survey, json=collection_exercise_by_survey, status=200) survey_list = party_controller.get_survey_list_details_for_party( respondent_party["id"], "todo", business_party["id"], survey["id"]) with app.app_context(): # This test might not do anything as the survey_list might be empty... look into this for survey_details in survey_list: self.assertTrue(survey_details["case_id"] is not None) self.assertTrue(survey_details["status"] is not None) self.assertTrue( survey_details["collection_instrument_type"] is not None) self.assertTrue(survey_details["survey_id"] is not None) self.assertTrue( survey_details["survey_long_name"] is not None) self.assertTrue( survey_details["survey_short_name"] is not None) self.assertTrue( survey_details["business_party_id"] is not None) self.assertTrue( survey_details["collection_exercise_ref"] is not None)
def get_survey_list(session, tag): """ Displays the list of surveys for the respondent by tag. A tag represents the state the survey is in (e.g., todo, history, etc) """ party_id = session.get_party_id() business_id = request.args.get('business_party_id') survey_id = request.args.get('survey_id') already_enrolled = request.args.get('already_enrolled') bound_logger = logger.bind(party_id=party_id, business_id=business_id, survey_id=survey_id, already_enrolled=already_enrolled, tag=tag) bound_logger.info("Retrieving survey list") survey_list = party_controller.get_survey_list_details_for_party( party_id, tag, business_party_id=business_id, survey_id=survey_id) sorted_survey_list = sorted( survey_list, key=lambda k: datetime.strptime(k['submit_by'], '%d %b %Y'), reverse=True) bound_logger.info("Successfully retreived survey list") unread_message_count = { 'unread_message_count': conversation_controller.try_message_count_from_session(session) } if tag == 'todo': added_survey = True if business_id and survey_id and not already_enrolled else None response = make_response( render_template('surveys/surveys-todo.html', sorted_surveys_list=sorted_survey_list, added_survey=added_survey, already_enrolled=already_enrolled, unread_message_count=unread_message_count)) # Ensure any return to list of surveys (e.g. browser back) round trips the server to display the latest statuses response.headers.set("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store") return response else: return render_template('surveys/surveys-history.html', sorted_surveys_list=sorted_survey_list, history=True, unread_message_count=unread_message_count)
def test_get_survey_list_details_for_party(self, get_respondent_enrolments, get_collection_exercises, get_cases, get_collection_instrument, calculate_case_status, get_survey, get_business): enrolments = [{ 'business_id': business_party['id'], 'survey_id': survey['id'] }] for collection_exercise_index in collection_exercise_by_survey: if collection_exercise_index['events']: collection_exercise_index[ 'events'] = convert_events_to_new_format( collection_exercise_index['events']) get_respondent_enrolments.return_value = enrolments get_collection_exercises.return_value = collection_exercise_by_survey get_cases.return_value = case_list get_collection_instrument.return_value = collection_instrument_seft calculate_case_status.return_value = 'In Progress' get_survey.return_value = survey get_business.return_value = business_party survey_list = party_controller.get_survey_list_details_for_party( respondent_party['id'], 'todo', business_party['id'], survey['id']) with app.app_context(): for survey_details in survey_list: self.assertTrue(survey_details['case_id'] is not None) self.assertTrue(survey_details['status'] is not None) self.assertTrue( survey_details['collection_instrument_type'] is not None) self.assertTrue(survey_details['survey_id'] is not None) self.assertTrue(survey_details['survey_long_name'] is not None) self.assertTrue( survey_details['survey_short_name'] is not None) self.assertTrue( survey_details['business_party_id'] is not None) self.assertTrue( survey_details['collection_exercise_ref'] is not None)
def get_survey_list(session, tag): """ Displays the list of surveys for the respondent by tag. A tag represents the state the survey is in (e.g., todo, history, etc) """ flask_session.pop("help_survey_ref", None) flask_session.pop("help_ru_ref", None) party_id = session.get_party_id() business_id = request.args.get("business_party_id") survey_id = request.args.get("survey_id") already_enrolled = request.args.get("already_enrolled") logger.info( "Retrieving survey list", party_id=party_id, business_id=business_id, survey_id=survey_id, already_enrolled=already_enrolled, tag=tag, ) # This logic is added to make sure a user is provided an option to delete an account if there is no # active enrolment which is ENABLED respondent = party_controller.get_respondent_party_by_id(party_id) delete_option_allowed = is_delete_account_respondent_allowed(respondent) survey_list = party_controller.get_survey_list_details_for_party( respondent, tag, business_party_id=business_id, survey_id=survey_id) sorted_survey_list = sorted( survey_list, key=lambda k: datetime.strptime(k["submit_by"], "%d %b %Y"), reverse=True) logger.info( "Successfully retrieved survey list", party_id=party_id, business_id=business_id, survey_id=survey_id, already_enrolled=already_enrolled, tag=tag, ) unread_message_count = { "unread_message_count": conversation_controller.try_message_count_from_session(session) } if tag == "todo": added_survey = True if business_id and survey_id and not already_enrolled else None response = make_response( render_template( "surveys/surveys-todo.html", sorted_surveys_list=sorted_survey_list, added_survey=added_survey, already_enrolled=already_enrolled, unread_message_count=unread_message_count, delete_option_allowed=delete_option_allowed, )) # Ensure any return to list of surveys (e.g. browser back) round trips the server to display the latest statuses response.headers.set("Cache-Control", "no-cache, max-age=0, must-revalidate, no-store") return response else: return render_template( "surveys/surveys-history.html", sorted_surveys_list=sorted_survey_list, history=True, unread_message_count=unread_message_count, )