def test_surveys_list_get_updated(self): lime_survey = Questionnaires() sid = None # Create a new survey at LimeSurvey with pt title try: pt_title_survey = 'Questionário Teste' sid = lime_survey.add_survey(9999, pt_title_survey, 'pt-BR', 'G') # Update the infos when viewed survey = Survey.objects.create(lime_survey_id=sid) # Check that pt_title is null self.assertIsNone(Survey.objects.last().pt_title) self.client.get(reverse('survey_list')) # Check that pt_title is updated self.assertEqual(Survey.objects.last().pt_title, pt_title_survey) # Simulate a discrepancy between the survey informations at limesurvey and NES survey.pt_title = "Título discrepante" survey.save() self.assertNotEqual(Survey.objects.last().pt_title, pt_title_survey) # Simulate clicking to update the list with new limesurvey information self.client.post(reverse('survey_list'), {'action': 'update'}, follow=True) # Check if the pt_title was updated properly self.assertEqual(Survey.objects.last().pt_title, pt_title_survey) finally: # Deletes the survey created at Lime Survey self.assertEqual(lime_survey.delete_survey(sid), 'OK')
def test_add_and_delete_survey_methods(self): questionnaires = Questionnaires() sid = questionnaires.add_survey('9999', 'Questionario de Teste', 'en', 'G') self.assertGreaterEqual(sid, 0) status = questionnaires.delete_survey(sid) self.assertEqual(status, 'OK')
def test_add_and_delete_survey_methods(self): questionnaires = Questionnaires() sid = questionnaires.add_survey('9999', 'Questionario de Teste', 'en', 'G') self.assertGreaterEqual(sid, 0) status = questionnaires.delete_survey(sid) self.assertEqual(status, 'OK')
def test_complete_survey(self): lime_survey = Questionnaires() sid = None try: # Cria uma nova survey no lime survey title_survey = 'Questionario de teste' sid = lime_survey.add_survey(9999, title_survey, 'en', 'G') # Obtenho o titulo da survey survey_title = lime_survey.get_survey_title(sid) self.assertEqual(survey_title, title_survey) # Verifica se esta ativa survey_active = lime_survey.get_survey_properties(sid, 'active') self.assertEqual(survey_active, 'N') # Obtem uma propriedade - Administrador da Survey survey_admin = lime_survey.get_survey_properties(sid, 'admin') self.assertEqual(survey_admin, None) # Importar grupo de questoes handle_file_import = \ open('quiz/static/quiz/tests/limesurvey_groups.lsg', 'r') questions_data = handle_file_import.read() questions_id = \ lime_survey.insert_questions(sid, questions_data, 'lsg') self.assertGreaterEqual(questions_id, 1) # Inicia tabela de tokens self.assertEqual(lime_survey.activate_tokens(sid), 'OK') # Ativar survey self.assertEqual(lime_survey.activate_survey(sid), 'OK') # Verifica se esta ativa survey_active = lime_survey.get_survey_properties(sid, 'active') self.assertEqual(survey_active, 'Y') # Adiciona participante e obtem o token result_token = lime_survey.add_participant(sid) # Verifica se o token está presente na tabela de participantes token = lime_survey.get_participant_properties( sid, result_token, "token") self.assertEqual(token, result_token['token']) finally: # Deleta a survey gerada no Lime Survey self.assertEqual(lime_survey.delete_survey(sid), 'OK')
def test_complete_survey(self): lime_survey = Questionnaires() sid = None try: # Cria uma nova survey no lime survey title_survey = 'Questionario de teste' sid = lime_survey.add_survey(9999, title_survey, 'en', 'G') # Obtenho o titulo da survey survey_title = lime_survey.get_survey_title(sid) self.assertEqual(survey_title, title_survey) # Verifica se esta ativa survey_active = lime_survey.get_survey_properties(sid, 'active') self.assertEqual(survey_active, 'N') # Obtem uma propriedade - Administrador da Survey survey_admin = lime_survey.get_survey_properties(sid, 'admin') self.assertEqual(survey_admin, None) # Importar grupo de questoes handle_file_import = \ open('quiz/static/quiz/tests/limesurvey_groups.lsg', 'r') questions_data = handle_file_import.read() questions_id = \ lime_survey.insert_questions(sid, questions_data, 'lsg') self.assertGreaterEqual(questions_id, 1) # Inicia tabela de tokens self.assertEqual(lime_survey.activate_tokens(sid), 'OK') # Ativar survey self.assertEqual(lime_survey.activate_survey(sid), 'OK') # Verifica se esta ativa survey_active = lime_survey.get_survey_properties(sid, 'active') self.assertEqual(survey_active, 'Y') # Adiciona participante e obtem o token result_token = lime_survey.add_participant(sid) # Verifica se o token está presente na tabela de participantes token = lime_survey.get_participant_properties(sid, result_token, "token") self.assertEqual(token, result_token['token']) finally: # Deleta a survey gerada no Lime Survey self.assertEqual(lime_survey.delete_survey(sid), 'OK')
def test_survey_without_pt_or_en_title_in_ls_returns_default_language_title_to_be_listed_but_dont_save(self): lime_survey = Questionnaires() sid = None # Create a new survey at LimeSurvey withou titles in pt or en languages try: fr_title_survey = 'Test Questionnaire in French' sid = lime_survey.add_survey(9999, fr_title_survey, 'fr', 'G') Survey.objects.create(lime_survey_id=sid) response = self.client.get(reverse('survey_list')) # Check if the page renders the fr title of the survey self.assertContains(response, fr_title_survey) # Check that pt_title and en_title remain null self.assertIsNone(Survey.objects.last().en_title) self.assertIsNone(Survey.objects.last().pt_title) finally: # Deletes the survey created at Lime Survey self.assertEqual(lime_survey.delete_survey(sid), 'OK')
def test_survey_without_pt_or_en_title_in_ls_returns_default_language_title_to_be_listed_but_dont_save( self): lime_survey = Questionnaires() sid = None # Create a new survey at LimeSurvey withou titles in pt or en languages try: fr_title_survey = 'Test Questionnaire in French' sid = lime_survey.add_survey(9999, fr_title_survey, 'fr', 'G') Survey.objects.create(lime_survey_id=sid) response = self.client.get(reverse('survey_list')) # Check if the page renders the fr title of the survey self.assertContains(response, fr_title_survey) # Check that pt_title and en_title remain null self.assertIsNone(Survey.objects.last().en_title) self.assertIsNone(Survey.objects.last().pt_title) finally: # Deletes the survey created at Lime Survey self.assertEqual(lime_survey.delete_survey(sid), 'OK')
def test_surveys_list_get_updated(self): lime_survey = Questionnaires() sid = None # Create a new survey at LimeSurvey with pt title try: pt_title_survey = 'Questionário Teste' sid = lime_survey.add_survey(9999, pt_title_survey, 'pt-BR', 'G') # Update the infos when viewed survey = Survey.objects.create(lime_survey_id=sid) # Check that pt_title is null self.assertIsNone(Survey.objects.last().pt_title) self.client.get(reverse('survey_list')) # Check that pt_title is updated self.assertEqual(Survey.objects.last().pt_title, pt_title_survey) # Simulate a discrepancy between the survey informations at limesurvey and NES survey.pt_title = "Título discrepante" survey.save() self.assertNotEqual(Survey.objects.last().pt_title, pt_title_survey) # Simulate clicking to update the list with new limesurvey information self.client.post(reverse('survey_list'), {'action': 'update'}, follow=True) # Check if the pt_title was updated properly self.assertEqual(Survey.objects.last().pt_title, pt_title_survey) finally: # Deletes the survey created at Lime Survey self.assertEqual(lime_survey.delete_survey(sid), 'OK')
def test_survey_create_with_fileupload_question(self): lime_survey = Questionnaires() sid = None try: # Cria uma nova survey no lime survey title_survey = 'Questionario de teste' sid = lime_survey.add_survey(9999, title_survey, 'en', 'G') # Obtenho o titulo da survey survey_title = lime_survey.get_survey_title(sid) self.assertEqual(survey_title, title_survey) # Verifica se esta ativa survey_active = lime_survey.get_survey_properties(sid, 'active') self.assertEqual(survey_active, 'N') # Obtem uma propriedade - Administrador da Survey survey_admin = lime_survey.get_survey_properties(sid, 'admin') self.assertEqual(survey_admin, None) # Importar grupo de questoes handle_file_import = \ open('quiz/static/quiz/tests/limesurvey_groups_with_fileupload.lsg', 'r') questions_data = handle_file_import.read() questions_id = \ lime_survey.insert_questions(sid, questions_data, 'lsg') self.assertGreaterEqual(questions_id, 1) # Inicia tabela de tokens self.assertEqual(lime_survey.activate_tokens(sid), 'OK') # Ativar survey self.assertEqual(lime_survey.activate_survey(sid), 'OK') # Verifica se esta ativa survey_active = lime_survey.get_survey_properties(sid, 'active') self.assertEqual(survey_active, 'Y') # Request the survey register screen response = self.client.get(reverse('survey_create')) self.assertEqual(response.status_code, 200) # Set survey data # self.data = {'action': 'save', 'title': 'Survey title'} self.data = {'action': 'save', 'questionnaire_selected': sid} # Count the number of surveys currently in database count_before_insert = Survey.objects.all().count() # Add the new survey response = self.client.post(reverse('survey_create'), self.data) self.assertEqual(response.status_code, 302) # Assert if the message is parsed self.assertEqual( response.wsgi_request._messages._queued_messages[0].message, 'O NES não importa arquivos carregados pelo Limesurvey através de questões do tipo \'Envio de arquivo\'. Veja \"Best Pratices and Recommendations\" em https://nes.rtfd.io para mais detalhes.' ) # Count the number of surveys currently in database count_after_insert = Survey.objects.all().count() # Check if it has increased self.assertEqual(count_after_insert, count_before_insert + 1) finally: # Deleta a survey gerada no Lime Survey self.assertEqual(lime_survey.delete_survey(sid), 'OK')