def test_send_experiment_to_portal(self, mockRestApiClientClass): # create the groups of users and their permissions exec(open('add_initial_data.py').read()) user, user_passwd = create_user(Group.objects.all()) research_project = ObjectsFactory.create_research_project() experiment = ObjectsFactory.create_experiment(research_project) ScheduleOfSending.objects.create( experiment=experiment, responsible=user, status='scheduled', send_participant_age=False, reason_for_resending='Ein guter Grund' ) send_experiment_to_portal(experiment) api_fields = { 'nes_id', 'title', 'description', 'data_acquisition_done', 'project_url', 'ethics_committee_url', 'ethics_committee_file', 'release_notes' } (api_schema, action_keys), kwargs = \ mockRestApiClientClass.return_value.client.action.call_args self.assertTrue( set(kwargs['params'].keys()).issubset(api_fields), str(set(kwargs['params'].keys())) + ' not in ' + str(api_fields) )
def test_send_experiment_to_portal(self, mockRestApiClientClass): # create the groups of users and their permissions exec(open('add_initial_data.py').read()) user, user_passwd = create_user(Group.objects.all()) research_project = ObjectsFactory.create_research_project() experiment = ObjectsFactory.create_experiment(research_project) ScheduleOfSending.objects.create( experiment=experiment, responsible=user, status='scheduled', send_participant_age=False, reason_for_resending='Ein guter Grund') send_experiment_to_portal(experiment) api_fields = { 'nes_id', 'title', 'description', 'data_acquisition_done', 'project_url', 'ethics_committee_url', 'ethics_committee_file', 'release_notes' } (api_schema, action_keys), kwargs = \ mockRestApiClientClass.return_value.client.action.call_args self.assertTrue( set(kwargs['params'].keys()).issubset(api_fields), str(set(kwargs['params'].keys())) + ' not in ' + str(api_fields))
def test_send_researcher_to_portal(self, mockRestApiClientClass): # create the groups of users and their permissions exec(open('add_initial_data.py').read()) research_project = ObjectsFactory.create_research_project() experiment = ObjectsFactory.create_experiment(research_project) researcher = ObjectsFactory.create_experiment_researcher(experiment) send_researcher_to_portal(research_project.id, researcher.researcher) api_fields = {'id', 'first_name', 'last_name', 'email', 'citation_name'} (api_schema, action_keys), kwargs = \ mockRestApiClientClass.return_value.client.action.call_args self.assertTrue( set(kwargs['params'].keys()).issubset(api_fields), str(set(kwargs['params'].keys())) + ' not in ' + str(api_fields) )
def setUp(self): exec(open('add_initial_data.py').read()) self.user = User.objects.create_user(username='******', email='*****@*****.**', password='******') user_profile = self.user.user_profile user_profile.login_enabled = True user_profile.force_password_change = False user_profile.save() for group in Group.objects.all(): # for group in Group.objects.filter(name='Attendant'): group.user_set.add(self.user) self.client.login(username=self.user.username, password='******') self.research_project = ObjectsFactory.create_research_project() self.experiment = ObjectsFactory.create_experiment( self.research_project)
def test_send_researcher_to_portal(self, mockRestApiClientClass): # create the groups of users and their permissions exec(open('add_initial_data.py').read()) research_project = ObjectsFactory.create_research_project() experiment = ObjectsFactory.create_experiment(research_project) researcher = ObjectsFactory.create_experiment_researcher(experiment) send_researcher_to_portal(research_project.id, researcher.researcher) api_fields = { 'id', 'first_name', 'last_name', 'email', 'citation_name' } (api_schema, action_keys), kwargs = \ mockRestApiClientClass.return_value.client.action.call_args self.assertTrue( set(kwargs['params'].keys()).issubset(api_fields), str(set(kwargs['params'].keys())) + ' not in ' + str(api_fields))
def test_Schedule_of_Sending_List_is_valid(self): # Check if list of research projects is empty before inserting any. response = self.client.get(reverse('research_project_list')) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context['research_projects']), 0) ObjectsFactory.create_research_project() # Check if list of research projects returns one item after inserting one. response = self.client.get(reverse('research_project_list')) self.assertEqual(response.status_code, 200) self.assertEqual(len(response.context['research_projects']), 1) can_send_to_portal = False if settings.PORTAL_API['URL'] and settings.SHOW_SEND_TO_PORTAL_BUTTON: can_send_to_portal = True # Check if list of research projects returns one item after inserting one. response = self.client.get(reverse('schedule_of_sending_list')) self.assertEqual(response.status_code, 200)
def setUp(self): # create the groups of users and their permissions exec(open('add_initial_data.py').read()) # return user password to use when necessary in subclasses self.user, self.user_passwd = create_user(Group.objects.all()) self.client.login( username=self.user.username, password=self.user_passwd ) # create experiment/experimental protocol/group self.experiment = ObjectsFactory.create_experiment( ObjectsFactory.create_research_project(self.user) ) self.root_component = ObjectsFactory.create_block(self.experiment) self.group = ObjectsFactory.create_group( self.experiment, self.root_component ) # create patient/subject/subject_of_group self.patient = UtilTests().create_patient(changed_by=self.user) subject = ObjectsFactory.create_subject(self.patient) self.subject_of_group = \ ObjectsFactory.create_subject_of_group(self.group, subject)
def setUp(self): # create the groups of users and their permissions exec(open('add_initial_data.py').read()) # return user password to use when necessary in subclasses self.user, self.user_passwd = create_user(Group.objects.all()) self.client.login( username=self.user.username, password=self.user_passwd ) # create experiment/experimental protocol/group self.experiment = ObjectsFactory.create_experiment( ObjectsFactory.create_research_project(self.user) ) self.root_component = ObjectsFactory.create_block(self.experiment) self.group = ObjectsFactory.create_group( self.experiment, self.root_component ) # create patient/subject/subject_of_group self.patient = UtilTests().create_patient_mock(changed_by=self.user) subject = ObjectsFactory.create_subject(self.patient) self.subject_of_group = \ ObjectsFactory.create_subject_of_group(self.group, subject)
def setUp(self): logged, self.user, self.factory = ObjectsFactory.system_authentication( self) self.assertEqual(logged, True)
def test_send_questionnaire_to_portal_has_correct_metadata_columns( self, mockServerClass, mockRestApiClientClass): # Create the groups of users and their permissions exec(open('add_initial_data.py').read()) # Create objects necessary to send questionnaire step to portal research_project = ObjectsFactory.create_research_project() experiment = ObjectsFactory.create_experiment(research_project) experimental_protocol = ObjectsFactory.create_block(experiment) group = ObjectsFactory.create_group(experiment, experimental_protocol) survey = create_survey(212121) # fake number questionnaire_step = ObjectsFactory.create_component( experiment, Component.QUESTIONNAIRE, kwargs={'survey': survey}) ObjectsFactory.create_component_configuration(experimental_protocol, questionnaire_step) tree = get_block_tree(group.experimental_protocol, 'en') # Mock methods used in test calling methods survey_languages = {'language': 'en', 'additional_languages': None} mockServerClass.return_value.get_survey_properties.return_value = survey_languages mockServerClass.return_value.export_responses.return_value = \ b'ImlkIiwic3VibWl0ZGF0ZSIsImxhc3RwYWdlIiwic3RhcnRsYW5ndWFn' \ b'ZSIsInRva2VuIiwicmVzcG9uc2libGVpZCIsImZha2VRdWVzdGlvbiIKI' \ b'jgiLCIxOTgwLTAxLTAxIDAwOjAwOjAwIiwiMiIsImVuIiwieDQ0cmRxeT' \ b'RhMGxoYjRMIiwiMiIsNSIsInRleHRvIGxvbmdvIgoK' mockServerClass.return_value.get_language_properties.return_value = \ {'surveyls_title': 'Ein wunderbar Titel'} mockServerClass.return_value.list_questions.return_value = [{ 'id': { 'qid': 1 } }] # Mock get_question_properties LimeSurvey API method using # ABCSearchEngine.QUESTION_PROPERTIES constant list with fake values question_order = 21 group_id = 981 question_properties = dict( zip(ABCSearchEngine.QUESTION_PROPERTIES, [ group_id, 'Question Title', question_order, 'No available answers', 'No available answer options', 'fakeQuestion', 'N', 'No available attributes', {'hidden', '1'}, 'N' ])) mockServerClass.return_value.get_question_properties.return_value = \ question_properties # mock list_groups LimeSurvey API method (fake values) language = 'en' mockServerClass.return_value.list_groups.return_value = [{ 'randomization_group': '', 'id': { 'gid': group_id, 'language': language }, 'group_name': 'Grupo 1', 'description': '', 'group_order': 1, 'sid': survey.lime_survey_id, 'gid': group_id, 'language': language, 'grelevance': '' }] send_steps_to_portal(21, tree, None, None, None, None, 'en') # use mockRestApiClientClass to get metadata value that will be sent (api_schema, action_keys), kwargs = \ mockRestApiClientClass.return_value.client.action.call_args for field in HEADER_EXPLANATION_FIELDS: self.assertIn(field, kwargs['params']['survey_metadata']) survey_metadata = csv.reader( StringIO(kwargs['params']['survey_metadata'])) for row in survey_metadata: self.assertEqual(len(row), len(HEADER_EXPLANATION_FIELDS))
def test_send_questionnaire_to_portal_has_correct_metadata_columns( self, mockServerClass, mockRestApiClientClass): # create the groups of users and their permissions exec(open('add_initial_data.py').read()) # create objects necessary to send questionnaire step to portal research_project = ObjectsFactory.create_research_project() experiment = ObjectsFactory.create_experiment(research_project) experimental_protocol = ObjectsFactory.create_block(experiment) group = ObjectsFactory.create_group(experiment, experimental_protocol) survey = create_survey(212121) # fake number questionnaire_step = ObjectsFactory.create_component( experiment, Component.QUESTIONNAIRE, kwargs={'sid': survey.id}) ObjectsFactory.create_component_configuration(experimental_protocol, questionnaire_step) tree = get_block_tree(group.experimental_protocol, 'en') # mock methods used in test calling methods survey_languages = {'language': 'en', 'additional_languages': None} mockServerClass.return_value.get_survey_properties.return_value = \ survey_languages mockServerClass.return_value.export_responses.return_value = \ b'"id","submitdate","lastpage","startlanguage","token",' \ b'"responsibleid","fakeQuestion"\n' \ b'"8","1980-01-01 00:00:00","2","en","x44rdqy4a0lhb4L","2",' \ b'"5","texto longo"\n\n' mockServerClass.return_value.get_language_properties.return_value = \ {'surveyls_title': 'Ein wunderbar Titel'} mockServerClass.return_value.list_questions.return_value = [{ 'id': { 'qid': 1 } }] # Mock get_question_properties LimeSurvey API method using # ABCSearchEngine.QUESTION_PROPERTIES constant list with fake values question_order = 21 group_id = 981 question_properties = dict( zip(ABCSearchEngine.QUESTION_PROPERTIES, [ group_id, 'Question Title', question_order, 'No available answers', 'No available answer options', 'fakeQuestion', 'N', 'No available attributes', {'hidden', '1'}, 'N' ])) mockServerClass.return_value.get_question_properties.return_value = \ question_properties # mock list_groups LimeSurvey API method (fake values) language = 'en' mockServerClass.return_value.list_groups.return_value = \ [{'randomization_group': '', 'id': {'gid': group_id, 'language': language}, 'group_name': 'Grupo 1', 'description': '', 'group_order': 1, 'sid': survey.lime_survey_id, 'gid': group_id, 'language': language, 'grelevance': ''}] send_steps_to_portal(21, tree, None, None, None, None, 'en') # use mockRestApiClientClass to get metadata value that will be sent (api_schema, action_keys), kwargs = \ mockRestApiClientClass.return_value.client.action.call_args for field in HEADER_EXPLANATION_FIELDS: self.assertIn(field, kwargs['params']['survey_metadata']) survey_metadata = csv.reader( StringIO(kwargs['params']['survey_metadata'])) for row in survey_metadata: self.assertEqual(len(row), len(HEADER_EXPLANATION_FIELDS))
def test_send_questionnaire_to_portal_has_correct_metadata_columns( self, mockServerClass, mockRestApiClientClass): # create the groups of users and their permissions exec(open('add_initial_data.py').read()) # create objects necessary to send questionnaire step to portal research_project = ObjectsFactory.create_research_project() experiment = ObjectsFactory.create_experiment(research_project) experimental_protocol = ObjectsFactory.create_block(experiment) group = ObjectsFactory.create_group(experiment, experimental_protocol) survey = create_survey(212121) # fake number questionnaire_step = ObjectsFactory.create_component( experiment, Component.QUESTIONNAIRE, kwargs={'survey': survey} ) ObjectsFactory.create_component_configuration( experimental_protocol, questionnaire_step ) tree = get_block_tree(group.experimental_protocol, 'en') # mock methods used in test calling methods survey_languages = {'language': 'en', 'additional_languages': None} mockServerClass.return_value.get_survey_properties.return_value = \ survey_languages mockServerClass.return_value.export_responses.return_value = \ b'"id","submitdate","lastpage","startlanguage","token",' \ b'"responsibleid","fakeQuestion"\n' \ b'"8","1980-01-01 00:00:00","2","en","x44rdqy4a0lhb4L","2",' \ b'"5","texto longo"\n\n' mockServerClass.return_value.get_language_properties.return_value = \ {'surveyls_title': 'Ein wunderbar Titel'} mockServerClass.return_value.list_questions.return_value = [ {'id': {'qid': 1}} ] # Mock get_question_properties LimeSurvey API method using # ABCSearchEngine.QUESTION_PROPERTIES constant list with fake values question_order = 21 group_id = 981 question_properties = dict( zip( ABCSearchEngine.QUESTION_PROPERTIES, [group_id, 'Question Title', question_order, 'No available answers', 'No available answer options', 'fakeQuestion', 'N', 'No available attributes', {'hidden', '1'}, 'N'] ) ) mockServerClass.return_value.get_question_properties.return_value = \ question_properties # mock list_groups LimeSurvey API method (fake values) language = 'en' mockServerClass.return_value.list_groups.return_value = \ [{'randomization_group': '', 'id': {'gid': group_id, 'language': language}, 'group_name': 'Grupo 1', 'description': '', 'group_order': 1, 'sid': survey.lime_survey_id, 'gid': group_id, 'language': language, 'grelevance': ''}] send_steps_to_portal(21, tree, None, None, None, None, 'en') # use mockRestApiClientClass to get metadata value that will be sent (api_schema, action_keys), kwargs = \ mockRestApiClientClass.return_value.client.action.call_args for field in HEADER_EXPLANATION_FIELDS: self.assertIn(field, kwargs['params']['survey_metadata']) survey_metadata = csv.reader( StringIO(kwargs['params']['survey_metadata']) ) for row in survey_metadata: self.assertEqual(len(row), len(HEADER_EXPLANATION_FIELDS))