Exemplo n.º 1
4
def get_valid_questionnaire(user=None):
    """
    Assumes fixture 'sample.json' is loaded
    """
    if user is None:
        user = create_new_user()
    return Questionnaire.create_new(
        configuration_code='sample', data={'foo': 'bar'},
        user=user)
Exemplo n.º 2
3
 def test_create_new_sets_correct_version(self):
     q_1 = get_valid_questionnaire(self.user)
     q_1.status = 4
     q_1.save()
     # Create a new version
     q_2 = Questionnaire.create_new(
         configuration_code='sample', data={'faz': 'taz'}, user=self.user,
         previous_version=q_1)
     # Version 2 is deleted
     q_2.is_deleted = True
     q_2.save()
     # Create a new version based on v1
     q_3 = Questionnaire.create_new(
         configuration_code='sample', data={'faz': 'taz'}, user=self.user,
         previous_version=q_1)
     self.assertEqual(q_3.version, 3)
Exemplo n.º 3
1
 def test_protect_published_item(self, mock_update_geometry):
     questionnaire = Questionnaire.create_new(
         configuration_code='sample', data={}, user=self.user, status=4
     )
     self.assertEqual(questionnaire.status, 4)
     questionnaire.data = {'foo': 'bar'}
     self.assertRaises(ValidationError, lambda: questionnaire.save())
Exemplo n.º 4
0
 def test_previous_version_only_allows_certain_status(self):
     previous = Questionnaire(status=2)
     with self.assertRaises(ValidationError):
         Questionnaire.create_new(configuration_code='sample',
                                  data={},
                                  user=self.user,
                                  previous_version=previous)
Exemplo n.º 5
0
 def create_questionnaire(self, status, user=None):
     Questionnaire.create_new(
         configuration_code='sample',
         data={'foo': 'bar'},
         user=user or self.user,
         status=status
     )
Exemplo n.º 6
0
 def setUp(self):
     view = QuestionnaireLinkSearchView(configuration_code='approaches')
     self.request = RequestFactory().get(
         reverse('approaches:questionnaire_link_search'),
         HTTP_X_REQUESTED_WITH='XMLHttpRequest')
     user1 = create_new_user()
     user2 = create_new_user(id=2, email='*****@*****.**')
     self.request.user = user1
     self.view = self.setup_view(view, self.request)
     self.q1 = Questionnaire.create_new(
         configuration_code='technologies',
         data={'qg_name': [{'name': {'en': 'Tech 1'}}]}, user=user1)
     self.q2 = Questionnaire.create_new(
         configuration_code='approaches',
         data={'qg_name': [{'name': {'en': 'App 2'}}]}, user=user1)
     self.q3 = Questionnaire.create_new(
         configuration_code='approaches',
         data={'qg_name': [{'name': {'en': 'App 3'}}]}, user=user1)
     self.q3.status = 4
     self.q3.save()
     self.q4 = Questionnaire.create_new(
         configuration_code='approaches',
         data={'qg_name': [{'name': {'en': 'App 4'}}]}, user=user2)
     self.q4.status = 4
     self.q4.save()
     self.q5 = Questionnaire.create_new(
         configuration_code='approaches',
         data={'qg_name': [{'name': {'en': 'App 5'}}]}, user=user2)
Exemplo n.º 7
0
 def setUp(self):
     view = QuestionnaireLinkSearchView(configuration_code='approaches')
     self.request = RequestFactory().get(
         reverse('approaches:questionnaire_link_search'),
         HTTP_X_REQUESTED_WITH='XMLHttpRequest')
     user1 = create_new_user()
     user2 = create_new_user(id=2, email='*****@*****.**')
     self.request.user = user1
     self.view = self.setup_view(view, self.request)
     self.q1 = Questionnaire.create_new(
         configuration_code='technologies',
         data={'qg_name': [{
             'name': {
                 'en': 'Tech 1'
             }
         }]},
         user=user1)
     self.q2 = Questionnaire.create_new(
         configuration_code='approaches',
         data={'qg_name': [{
             'name': {
                 'en': 'App 2'
             }
         }]},
         user=user1)
     self.q3 = Questionnaire.create_new(
         configuration_code='approaches',
         data={'qg_name': [{
             'name': {
                 'en': 'App 3'
             }
         }]},
         user=user1)
     self.q3.status = 4
     self.q3.save()
     self.q4 = Questionnaire.create_new(
         configuration_code='approaches',
         data={'qg_name': [{
             'name': {
                 'en': 'App 4'
             }
         }]},
         user=user2)
     self.q4.status = 4
     self.q4.save()
     self.q5 = Questionnaire.create_new(
         configuration_code='approaches',
         data={'qg_name': [{
             'name': {
                 'en': 'App 5'
             }
         }]},
         user=user2)
Exemplo n.º 8
0
 def test_create_new_keeps_users_from_previous_version(self):
     user2 = create_new_user(id=2,
                             email='*****@*****.**',
                             lastname='foo2',
                             firstname='bar2')
     user3 = create_new_user(id=3,
                             email='*****@*****.**',
                             lastname='foo3',
                             firstname='bar3')
     previous = get_valid_questionnaire(self.user)
     previous.status = 4
     previous.add_user(user2, settings.QUESTIONNAIRE_EDITOR)
     previous.add_user(user3, settings.QUESTIONNAIRE_REVIEWER)
     previous_users = previous.get_users()
     self.assertEqual(len(previous_users), 3)
     self.assertIn((settings.QUESTIONNAIRE_COMPILER, self.user),
                   previous_users)
     self.assertIn((settings.QUESTIONNAIRE_EDITOR, user2), previous_users)
     self.assertIn((settings.QUESTIONNAIRE_REVIEWER, user3), previous_users)
     # Compiler starts a new version
     q = Questionnaire.create_new(configuration_code='sample',
                                  data={},
                                  user=user2,
                                  previous_version=previous)
     current_users = q.get_users()
     self.assertEqual(len(current_users), 3)
     self.assertEqual(current_users, previous_users)
Exemplo n.º 9
0
 def test_create_new_sets_created(self):
     date = datetime.now()
     questionnaire = Questionnaire.create_new(configuration_code='sample',
                                              data={},
                                              user=self.user,
                                              created=date)
     self.assertEqual(questionnaire.created, date)
Exemplo n.º 10
0
 def test_allow_changes_unpublished_item(self):
     questionnaire = Questionnaire.create_new(
         configuration_code='sample', data={}, user=self.user, status=1
     )
     questionnaire.data = {'foo': 'bar'}
     questionnaire.save()
     self.assertEqual(questionnaire.data, {'foo': 'bar'})
Exemplo n.º 11
0
 def test_create_new_adds_language(self):
     language = 'en'
     ret = Questionnaire.create_new(
         configuration_code='sample', data={}, user=self.user)
     ret_languages = ret.questionnairetranslation_set.all()
     self.assertEqual(len(ret_languages), 1)
     self.assertEqual(ret_languages[0].language, language)
Exemplo n.º 12
0
 def test_protect_published_item(self, mock_update_geometry):
     questionnaire = Questionnaire.create_new(configuration_code='sample',
                                              data={},
                                              user=self.user,
                                              status=4)
     self.assertEqual(questionnaire.status, 4)
     questionnaire.data = {'foo': 'bar'}
     self.assertRaises(ValidationError, lambda: questionnaire.save())
Exemplo n.º 13
0
 def test_create_new_adds_language(self):
     language = 'en'
     ret = Questionnaire.create_new(configuration_code='sample',
                                    data={},
                                    user=self.user)
     ret_languages = ret.questionnairetranslation_set.all()
     self.assertEqual(len(ret_languages), 1)
     self.assertEqual(ret_languages[0].language, language)
Exemplo n.º 14
0
 def test_allow_changes_unpublished_item(self):
     questionnaire = Questionnaire.create_new(configuration_code='sample',
                                              data={},
                                              user=self.user,
                                              status=1)
     questionnaire.data = {'foo': 'bar'}
     questionnaire.save()
     self.assertEqual(questionnaire.data, {'foo': 'bar'})
Exemplo n.º 15
0
 def test_previous_version_pending_updates_same_questionnaire(self):
     previous = get_valid_questionnaire(self.user)
     previous.status = 1
     q = Questionnaire.create_new(configuration_code='sample',
                                  data={'faz': 'taz'},
                                  user=self.user,
                                  previous_version=previous)
     self.assertEqual(q, previous)
     self.assertEqual(previous.data, {'faz': 'taz'})
Exemplo n.º 16
0
def get_valid_questionnaire(user=None):
    """
    Assumes fixture 'sample.json' is loaded
    """
    if user is None:
        user = create_new_user()
    return Questionnaire.create_new(configuration_code='sample',
                                    data={'foo': 'bar'},
                                    user=user)
Exemplo n.º 17
0
 def test_create_new_sets_correct_version(self):
     q_1 = get_valid_questionnaire(self.user)
     q_1.status = 4
     q_1.save()
     # Create a new version
     q_2 = Questionnaire.create_new(configuration_code='sample',
                                    data={'faz': 'taz'},
                                    user=self.user,
                                    previous_version=q_1)
     # Version 2 is deleted
     q_2.is_deleted = True
     q_2.save()
     # Create a new version based on v1
     q_3 = Questionnaire.create_new(configuration_code='sample',
                                    data={'faz': 'taz'},
                                    user=self.user,
                                    previous_version=q_1)
     self.assertEqual(q_3.version, 3)
Exemplo n.º 18
0
 def test_previous_version_public_keeps_same_code(self):
     previous = get_valid_questionnaire(self.user)
     previous.status = 4
     q = Questionnaire.create_new(configuration_code='sample',
                                  data={'faz': 'taz'},
                                  user=self.user,
                                  previous_version=previous)
     self.assertNotEqual(q, previous)
     self.assertEqual(q.code, previous.code)
     self.assertEqual(q.version, previous.version + 1)
Exemplo n.º 19
0
Arquivo: views.py Projeto: maxatp/qcat
    def done(self, form_list, form_dict, **kwargs):

        baseConfig = BaseConfig()

        baseDict = {}
        for step, stepData in form_dict.items():
            baseDict[baseConfig.getConfigByStep(step)] = stepData.cleaned_data
        json = {'base': baseDict}
        questionnaire = Questionnaire.create_new(json=json)
        messages.success(
            self.request, _('The questionnaire was successfully submitted.'))
        return redirect(questionnaire)
Exemplo n.º 20
0
 def test_create_new_keeps_languages_from_previous_version(self):
     previous = get_valid_questionnaire(self.user)
     previous.status = 4
     previous.add_translation_language(language='fr')
     previous.add_translation_language(language='es')
     self.assertEqual(len(previous.translations), 3)
     self.assertEqual(previous.original_locale, 'en')
     q = Questionnaire.create_new(
         configuration_code='sample', data={}, user=self.user,
         previous_version=previous)
     self.assertEqual(len(q.translations), 3)
     self.assertEqual(q.original_locale, 'en')
     self.assertEqual(sorted(previous.translations), sorted(q.translations))
Exemplo n.º 21
0
 def test_create_new_keeps_languages_from_previous_version(self):
     previous = get_valid_questionnaire(self.user)
     previous.status = 4
     previous.add_translation_language(language='fr')
     previous.add_translation_language(language='es')
     self.assertEqual(len(previous.translations), 3)
     self.assertEqual(previous.original_locale, 'en')
     q = Questionnaire.create_new(configuration_code='sample',
                                  data={},
                                  user=self.user,
                                  previous_version=previous)
     self.assertEqual(len(q.translations), 3)
     self.assertEqual(q.original_locale, 'en')
     self.assertEqual(sorted(previous.translations), sorted(q.translations))
Exemplo n.º 22
0
 def test_create_new_copies_compilers(self):
     questionnaire = get_valid_questionnaire(self.user)
     user_2 = create_new_user(id=2, email='*****@*****.**')
     user_3 = create_new_user(id=3, email='*****@*****.**')
     questionnaire.add_user(user_2, 'compiler')
     questionnaire.add_user(user_3, 'editor')
     questionnaire.status = 4
     users = questionnaire.get_users()
     users_ids = [u[1].id for u in users]
     self.assertEqual(len(users_ids), 3)
     questionnaire_2 = Questionnaire.create_new(
         configuration_code='sample', data=questionnaire.data,
         user=self.user, previous_version=questionnaire)
     new_users = questionnaire_2.get_users()
     new_users_ids = [u[1].id for u in new_users]
     self.assertListEqual(sorted(users_ids), sorted(new_users_ids))
Exemplo n.º 23
0
 def test_create_new_copies_compilers(self):
     questionnaire = get_valid_questionnaire(self.user)
     user_2 = create_new_user(id=2, email='*****@*****.**')
     user_3 = create_new_user(id=3, email='*****@*****.**')
     questionnaire.add_user(user_2, 'compiler')
     questionnaire.add_user(user_3, 'editor')
     questionnaire.status = 4
     users = questionnaire.get_users()
     users_ids = [u[1].id for u in users]
     self.assertEqual(len(users_ids), 3)
     questionnaire_2 = Questionnaire.create_new(
         configuration_code='sample',
         data=questionnaire.data,
         user=self.user,
         previous_version=questionnaire)
     new_users = questionnaire_2.get_users()
     new_users_ids = [u[1].id for u in new_users]
     self.assertListEqual(sorted(users_ids), sorted(new_users_ids))
Exemplo n.º 24
0
 def test_get_metadata(self):
     questionnaire = Questionnaire.create_new(
         configuration_code='sample', data={}, user=self.user)
     metadata = questionnaire.get_metadata()
     self.assertIsInstance(metadata, dict)
     self.assertEqual(len(metadata), 11)
     self.assertEqual(metadata['created'], questionnaire.created)
     self.assertEqual(metadata['updated'], questionnaire.updated)
     self.assertEqual(
         metadata['compilers'],
         [{'id': self.user.id, 'name': str(self.user)}])
     self.assertEqual(metadata['editors'], [])
     self.assertEqual(metadata['code'], questionnaire.code)
     self.assertEqual(
         metadata['configuration'],
         Configuration.objects.get(code='sample', edition='2015'))
     self.assertEqual(metadata['translations'], ['en'])
     self.assertEqual(metadata['status'], ('draft', 'Draft'))
     self.assertEqual(metadata['flags'], [])
Exemplo n.º 25
0
 def test_get_metadata(self):
     questionnaire = Questionnaire.create_new(configuration_code='sample',
                                              data={},
                                              user=self.user)
     metadata = questionnaire.get_metadata()
     self.assertIsInstance(metadata, dict)
     self.assertEqual(len(metadata), 11)
     self.assertEqual(metadata['created'], questionnaire.created)
     self.assertEqual(metadata['updated'], questionnaire.updated)
     self.assertEqual(metadata['compilers'], [{
         'id': self.user.id,
         'name': str(self.user)
     }])
     self.assertEqual(metadata['editors'], [])
     self.assertEqual(metadata['code'], questionnaire.code)
     self.assertEqual(
         metadata['configuration'],
         Configuration.objects.get(code='sample', edition='2015'))
     self.assertEqual(metadata['translations'], ['en'])
     self.assertEqual(metadata['status'], ('draft', 'Draft'))
     self.assertEqual(metadata['flags'], [])
Exemplo n.º 26
0
 def test_create_new_keeps_users_from_previous_version(self):
     user2 = create_new_user(
         id=2, email='*****@*****.**', lastname='foo2', firstname='bar2')
     user3 = create_new_user(
         id=3, email='*****@*****.**', lastname='foo3', firstname='bar3')
     previous = get_valid_questionnaire(self.user)
     previous.status = 4
     previous.add_user(user2, settings.QUESTIONNAIRE_EDITOR)
     previous.add_user(user3, settings.QUESTIONNAIRE_REVIEWER)
     previous_users = previous.get_users()
     self.assertEqual(len(previous_users), 3)
     self.assertIn(
         (settings.QUESTIONNAIRE_COMPILER, self.user), previous_users)
     self.assertIn((settings.QUESTIONNAIRE_EDITOR, user2), previous_users)
     self.assertIn((settings.QUESTIONNAIRE_REVIEWER, user3), previous_users)
     # Compiler starts a new version
     q = Questionnaire.create_new(
         configuration_code='sample', data={}, user=user2,
         previous_version=previous)
     current_users = q.get_users()
     self.assertEqual(len(current_users), 3)
     self.assertEqual(current_users, previous_users)
Exemplo n.º 27
0
 def test_create_new_returns_new_object(self):
     returned = Questionnaire.create_new(
         configuration_code='sample', data={'foo': 'bar'}, user=self.user)
     new_questionnaire = Questionnaire.objects.get(pk=returned.id)
     self.assertEqual(returned, new_questionnaire)
Exemplo n.º 28
0
 def test_create_new_calls_get_language(self, mock_get_language):
     mock_get_language.return_value = 'en'
     Questionnaire.create_new(
         configuration_code='sample', data={}, user=self.user)
     mock_get_language.assert_called_once_with()
Exemplo n.º 29
0
 def test_create_new_adds_configuration(self):
     configuration = Configuration.latest_by_code('sample')
     ret = Questionnaire.create_new(
         configuration_code='sample', data={}, user=self.user)
     self.assertEqual(ret.configuration, configuration)
Exemplo n.º 30
0
 def test_create_new_raises_error_if_invalid_status(self):
     with self.assertRaises(ValidationError):
         Questionnaire.create_new(configuration_code='sample',
                                  data={},
                                  user=self.user,
                                  status=-1)
Exemplo n.º 31
0
 def test_create_new_calls_get_language(self, mock_get_language):
     mock_get_language.return_value = 'en'
     Questionnaire.create_new(configuration_code='sample',
                              data={},
                              user=self.user)
     mock_get_language.assert_called_once_with()
Exemplo n.º 32
0
 def test_create_new_sets_status(self):
     questionnaire = Questionnaire.create_new(configuration_code='sample',
                                              data={},
                                              user=self.user,
                                              status=2)
     self.assertEqual(questionnaire.status, 2)
Exemplo n.º 33
0
 def test_create_new_raises_error_if_invalid_status(self):
     with self.assertRaises(ValidationError):
         Questionnaire.create_new(
             configuration_code='sample', data={}, user=self.user,
             status=-1)
Exemplo n.º 34
0
 def test_create_new_adds_configuration(self):
     configuration = Configuration.latest_by_code('sample')
     ret = Questionnaire.create_new(configuration_code='sample',
                                    data={},
                                    user=self.user)
     self.assertEqual(ret.configuration, configuration)
Exemplo n.º 35
0
 def test_create_new_sets_status(self):
     questionnaire = Questionnaire.create_new(
         configuration_code='sample', data={}, user=self.user, status=2)
     self.assertEqual(questionnaire.status, 2)
Exemplo n.º 36
0
 def test_create_new_sets_data(self):
     questionnaire = Questionnaire.create_new(
         configuration_code='sample', data={}, user=self.user)
     self.assertEqual(questionnaire.data, {})
Exemplo n.º 37
0
 def test_create_new_returns_new_object(self):
     returned = Questionnaire.create_new(configuration_code='sample',
                                         data={'foo': 'bar'},
                                         user=self.user)
     new_questionnaire = Questionnaire.objects.get(pk=returned.id)
     self.assertEqual(returned, new_questionnaire)
Exemplo n.º 38
0
 def create_questionnaire(self, status, user=None):
     Questionnaire.create_new(configuration_code='sample',
                              data={'foo': 'bar'},
                              user=user or self.user,
                              status=status)
Exemplo n.º 39
0
 def test_create_new_sets_created(self):
     date = datetime.now()
     questionnaire = Questionnaire.create_new(
         configuration_code='sample', data={}, user=self.user, created=date)
     self.assertEqual(questionnaire.created, date)
Exemplo n.º 40
0
 def test_previous_version_only_allows_certain_status(self):
     previous = Questionnaire(status=2)
     with self.assertRaises(ValidationError):
         Questionnaire.create_new(
             configuration_code='sample', data={}, user=self.user,
             previous_version=previous)
Exemplo n.º 41
0
 def test_create_new_sets_data(self):
     questionnaire = Questionnaire.create_new(configuration_code='sample',
                                              data={},
                                              user=self.user)
     self.assertEqual(questionnaire.data, {})
Exemplo n.º 42
-2
 def test_previous_version_public_keeps_same_code(self):
     previous = get_valid_questionnaire(self.user)
     previous.status = 4
     q = Questionnaire.create_new(
         configuration_code='sample', data={'faz': 'taz'}, user=self.user,
         previous_version=previous)
     self.assertNotEqual(q, previous)
     self.assertEqual(q.code, previous.code)
     self.assertEqual(q.version, previous.version + 1)
Exemplo n.º 43
-4
 def test_previous_version_pending_updates_same_questionnaire(self):
     previous = get_valid_questionnaire(self.user)
     previous.status = 1
     q = Questionnaire.create_new(
         configuration_code='sample', data={'faz': 'taz'}, user=self.user,
         previous_version=previous)
     self.assertEqual(q, previous)
     self.assertEqual(previous.data, {'faz': 'taz'})