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 survey_list(request, template_name='survey/survey_list.html'): surveys = Questionnaires() limesurvey_available = check_limesurvey_access(request, surveys) questionnaires_list = [] language_code = request.LANGUAGE_CODE for survey in Survey.objects.all(): language = get_questionnaire_language(surveys, survey.lime_survey_id, language_code) questionnaires_list.append( { 'id': survey.id, 'lime_survey_id': survey.lime_survey_id, 'title': surveys.get_survey_title(survey.lime_survey_id, language), 'is_initial_evaluation': survey.is_initial_evaluation, 'is_active': surveys.get_survey_properties(survey.lime_survey_id, 'active'), } ) surveys.release_session_key() questionnaires_list = sorted(questionnaires_list, key=itemgetter('title')) context = { 'questionnaires_list': questionnaires_list, 'limesurvey_available': limesurvey_available, } return render(request, template_name, context)
def survey_list(request, template_name='survey/survey_list.html'): surveys = Questionnaires() limesurvey_available = check_limesurvey_access(request, surveys) questionnaires_list = [] language_code = request.LANGUAGE_CODE update = False if request.method == "POST": if request.POST['action'] == "update": update = True for survey in Survey.objects.all(): survey_title = get_survey_title_based_on_the_user_language(survey, language_code, update) # Get the status of the survey # If there's any inactive survey, search LimeSurvey to see if there's any change in that matter # and update the fields in the database is_active = survey.is_active if not is_active or update: status = surveys.get_survey_properties(survey.lime_survey_id, 'active') if status == 'Y': survey.is_active = True else: survey.is_active = False survey.save() questionnaires_list.append( { 'id': survey.id, 'lime_survey_id': survey.lime_survey_id, 'title': survey_title, 'is_initial_evaluation': survey.is_initial_evaluation, 'is_active': survey.is_active, } ) surveys.release_session_key() questionnaires_list = sorted(questionnaires_list, key=itemgetter('title')) context = { 'questionnaires_list': questionnaires_list, 'limesurvey_available': limesurvey_available, } return render(request, template_name, context)
def survey_list(request, template_name='survey/survey_list.html'): surveys = Questionnaires() limesurvey_available = check_limesurvey_access(request, surveys) questionnaires_list = [] language_code = request.LANGUAGE_CODE update = False if request.method == "POST": if request.POST['action'] == "update": update = True for survey in Survey.objects.all(): survey_title = get_survey_title_based_on_the_user_language(survey, language_code, update) # Get the status of the survey # If there's any inactive survey, search LimeSurvey to see if there's any change in that matter # and update the fields in the database is_active = survey.is_active if not is_active or update: status = surveys.get_survey_properties(survey.lime_survey_id, 'active') if status == 'Y': survey.is_active = True else: survey.is_active = False survey.save() questionnaires_list.append( { 'id': survey.id, 'lime_survey_id': survey.lime_survey_id, 'title': survey_title, 'is_initial_evaluation': survey.is_initial_evaluation, 'is_active': survey.is_active, } ) surveys.release_session_key() questionnaires_list = sorted(questionnaires_list, key=itemgetter('title')) context = { 'questionnaires_list': questionnaires_list, 'limesurvey_available': limesurvey_available, } return render(request, template_name, context)
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')