def remap_citations(archived_murs): for mur in archived_murs: mur = Result(mur) # Include regulations and us_code citations in the re-map mur.citations = get_citations(map(lambda c: c['text'], list(mur.citations['regulations']) + list(mur.citations['us_code']))) yield mur
def test_should_give_create_response_with_no_unique_id_fields(self): form_model = MagicMock(spec=FormModel) required_field_names = ['ds_id', 'ds_name', 'some_question'] results = Response({ "_hits": [ Result({ '_type': "form_model_id", '_id': 'index_id', '_source': { 'ds_id': 'his_id', 'ds_name': 'his_name', 'some_question': 'answer' } }) ] }) form_model.entity_questions = [] form_model.id = 'form_model_id' local_time_delta = ('+', 2, 0) submissions = SubmissionQueryResponseCreator( form_model, local_time_delta).create_response(required_field_names, results) expected = [[ 'index_id', ["his_name<span class='small_grey'> his_id</span>"], 'answer' ]] self.assertEqual(submissions, expected)
def test_should_format_non_image_media_question(self): form_model = MagicMock(spec=FormModel) form_model.is_media_type_fields_present = True form_model.media_fields = [VideoField("video", "mp4", "mp4")] required_field_names = [ 'some_question', 'ds_id', 'ds_name', 'form_model_id_mp4' ] results = Response({ "_hits": [ Result({ '_type': "form_model_id", '_id': 'index_id', '_source': { 'ds_id': 'his_id', 'ds_name': 'his_name', 'form_model_id_q1': 'sub_last_name', 'form_model_id_mp4': 'vid.mp4', 'some_question': 'answer for it' } }) ] }) form_model.id = 'form_model_id' local_time_delta = ('+', 2, 0) submissions = SubmissionQueryResponseCreator( form_model, local_time_delta).create_response(required_field_names, results) expected = [[ 'index_id', 'answer for it', ["his_name<span class='small_grey'> his_id</span>"], ' <a href=\'/download/attachment/index_id/vid.mp4\'>vid.mp4</a>' ]] self.assertEqual(submissions, expected)
def test_should_format_image_question(self): form_model = MagicMock(spec=FormModel) form_model.is_media_type_fields_present = True form_model.media_fields = [PhotoField("photo", "img", "img")] required_field_names = [ 'some_question', 'ds_id', 'ds_name', 'form_model_id_img' ] hits = AttrList([ Result({ '_type': "form_model_id", '_id': 'index_id', '_source': { 'ds_id': 'his_id', 'ds_name': 'his_name', 'form_model_id_q1': 'sub_last_name', 'form_model_id_img': 'img2.png', 'some_question': 'answer for it' } }) ]) hits.total = 1 results = Response({"_hits": hits}) form_model.id = 'form_model_id' local_time_delta = ('+', 2, 0) submissions = SubmissionQueryResponseCreator( form_model, local_time_delta).create_response(required_field_names, results, {}) expected = ([[ 'index_id', 'answer for it', ["his_name<span class='small_grey'> his_id</span>"], '<img src=\'/download/attachment/index_id/preview_img2.png\' alt=\'\'/> <a href=\'/download/attachment/index_id/img2.png\'>img2.png</a>', 0 ]], 1) self.assertEqual(submissions, expected)
def test_should_give_back_entries_according_to_header_order(self): form_model = MagicMock(spec=FormModel) required_field_names = [ 'some_question', 'ds_id', 'ds_name', 'form_model_id_q1', 'form_model_id_q1_unique_code' ] hits = AttrList([ Result({ '_type': "form_model_id", '_id': 'index_id', '_source': { 'ds_id': 'his_id', 'ds_name': 'his_name', 'form_model_id_q1_unique_code': 'subject_id', 'form_model_id_q1': 'sub_last_name', 'some_question': 'answer for it' } }) ]) hits.total = 1 results = Response({"_hits": hits}) form_model.entity_questions = [ UniqueIdField('Test subject', 'name', 'q1', 'which subject') ] form_model.id = 'form_model_id' local_time_delta = ('+', 2, 0) submissions = SubmissionQueryResponseCreator( form_model, local_time_delta).create_response(required_field_names, results, {}) expected = ([[ 'index_id', 'answer for it', ["his_name<span class='small_grey'> his_id</span>"], ["sub_last_name<span class='small_grey'> subject_id</span>"], 0 ]], 1) self.assertEqual(submissions, expected)