Example #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)
Example #2
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)
Example #3
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)
Example #4
0
 def setUp(self):
     super().setUp()
     self.user = create_new_user()
     self.detail_view_user = create_new_user(id=2,
                                             email='*****@*****.**',
                                             firstname='abc',
                                             lastname='cde')
     self.url = self.live_server_url + reverse(
         'user_details', kwargs={'pk': self.detail_view_user.id})
Example #5
0
 def setUp(self):
     super().setUp()
     self.user = create_new_user()
     self.detail_view_user = create_new_user(
         id=2, email='*****@*****.**', firstname='abc', lastname='cde'
     )
     self.url = self.live_server_url + reverse(
         'user_details', kwargs={'pk': self.detail_view_user.id}
     )
Example #6
0
    def test_unccd_flag_elasticsearch(self):
        unccd_user = create_new_user(id=1, email='*****@*****.**')
        unccd_user.update(usergroups=[{
            'name': 'UNCCD Focal Point',
            'unccd_country': 'CHE',
        }])
        user_publisher = create_new_user(id=2, email='*****@*****.**')
        user_publisher.groups = [
            Group.objects.get(pk=3),
            Group.objects.get(pk=4)
        ]
        user_publisher.save()

        # Alice logs in as UNCCD focal point
        self.doLogin(user=unccd_user)

        # She flags a questionnaire
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_details, kwargs={'identifier': 'sample_1'}))
        self.review_action('flag-unccd')
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')

        # A publisher publishes it
        self.doLogin(user=user_publisher)
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_details, kwargs={'identifier': 'sample_1'}))
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')
        self.findBy('xpath', '//a[contains(@href, "sample/edit/")]')
        self.review_action('publish')
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')

        # He sees the questionnaire is in the list, with the flag visible
        self.browser.get(self.live_server_url +
                         reverse(route_questionnaire_list))
        self.findBy(
            'xpath', '(//article[contains(@class, "tech-item")])[2]'
            '//span[contains(@class, "is-unccd_bp")]')

        # He goes to the page where he sees the questionnaires of user UNCCD
        # and sees the flag there as well.
        # self.browser.get(self.live_server_url + reverse(
        #     accounts_route_questionnaires, kwargs={'user_id': unccd_user.id}))
        # self.findBy(
        #     'xpath', '(//article[contains(@class, "tech-item")])[1]'
        #              '//span[contains(@class, "is-unccd_bp")]')

        # UNCCD user logs in and goes to the page where he sees his own
        # questionnaires (this one queries the database) and sees the
        # questionnaire with the flag there as well.
        self.doLogin(user=unccd_user)
        self.browser.get(self.live_server_url +
                         reverse(accounts_route_questionnaires))
        self.findBy(
            'xpath', '(//article[contains(@class, "tech-item")])[1]'
            '//span[contains(@class, "is-unccd_bp")]')
Example #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)
Example #8
0
 def test_get_roles_permissions_returns_empty(self):
     other_user = create_new_user(
         id=2, email='*****@*****.**', lastname='faz', firstname='taz')
     questionnaire = get_valid_questionnaire(other_user)
     roles, permissions = questionnaire.get_roles_permissions(self.user)
     self.assertEqual(roles, [])
     self.assertEqual(permissions, [])
Example #9
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))
Example #10
0
 def doLogin(self, user=None):
     """
     A user is required for the login, this is a convenience wrapper to
     login a non-specified user.
     """
     self.doLogout()
     self._doLogin(user or create_new_user())
Example #11
0
    def test_admin_page_wocat_secretariat(self):
        user = create_new_user(id=2, email='*****@*****.**')
        user.groups.add(Group.objects.filter(name='WOCAT Secretariat').first())
        user.save()

        # Alice logs in
        self.doLogin(user=user)

        # She sees the admin button in the top navigation bar and clicks on it
        self.clickUserMenu(user)
        navbar = self.findBy('class_name', 'top-bar')
        navbar.find_element_by_link_text('Administration').click()

        # She sees that she can edit projects in the admin section
        self.findBy('xpath', '//h2[contains(text(), "Configuration")]')
        self.findBy('xpath', '//strong[contains(text(), "Projects")]')

        # She clicks to add a new project and sees that she can edit the ID as
        # well
        self.findBy(
            'xpath', '//a[contains(@href, "/admin/configuration/project'
            '/add/")]').click()

        textfields = self.findManyBy('xpath', '//input[@type="text"]')
        self.assertEqual(len(textfields), 2)

        # She goes back to the admin page
        self.browser.execute_script("window.history.go(-1)")

        # She can no longer edit institutions (they are managed in the CMS)
        self.findByNot('xpath', '//strong[contains(text(), "Institutions")]')
Example #12
0
 def setUp(self):
     view = QuestionnaireEditView(url_namespace='sample')
     self.request = RequestFactory().get('/en/sample/edit/app_1')
     self.request.user = create_new_user()
     self.request.session = dict()
     self.request._messages = MagicMock()
     self.view = self.setup_view(view, self.request, identifier='sample_1')
Example #13
0
 def doLogin(self, user=None):
     """
     A user is required for the login, this is a convenience wrapper to
     login a non-specified user.
     """
     self.doLogout()
     self._doLogin(user or create_new_user())
Example #14
0
 def test_renders_correct_template(self):
     request = self.factory.get(self.url)
     request.user = create_new_user()
     request.user.is_superuser = True
     request.session = {}
     res = admin(request)
     self.assertEqual(res.status_code, 200)
Example #15
0
 def setUp(self):
     super(SearchTestAdmin, self).setUp()
     create_temp_indices([('sample', '2015')])
     user = create_new_user()
     user.is_superuser = True
     user.save()
     self.user = user
Example #16
0
 def setUp(self):
     view = QuestionnaireEditView(url_namespace='sample')
     self.request = RequestFactory().get('/en/sample/edit/app_1')
     self.request.user = create_new_user()
     self.request.session = dict()
     self.request._messages = MagicMock()
     self.view = self.setup_view(view, self.request, identifier='sample_1')
Example #17
0
 def test_renders_correct_template(self):
     request = self.factory.get(self.url)
     request.user = create_new_user()
     request.user.is_superuser = True
     request.session = {}
     res = admin(request)
     self.assertEqual(res.status_code, 200)
Example #18
0
    def test_admin_page_wocat_secretariat(self):
        user = create_new_user(id=2, email='*****@*****.**')
        user.groups.add(Group.objects.filter(name='WOCAT Secretariat').first())
        user.save()

        # Alice logs in
        self.doLogin(user=user)

        # She sees the admin button in the top navigation bar and clicks on it
        self.clickUserMenu(user)
        navbar = self.findBy('class_name', 'top-bar')
        navbar.find_element_by_link_text('Administration').click()

        # She sees that she can edit projects in the admin section
        self.findBy('xpath', '//h2[contains(text(), "Configuration")]')
        self.findBy('xpath', '//strong[contains(text(), "Projects")]')

        # She clicks to add a new project and sees that she can edit the ID as
        # well
        self.findBy('xpath', '//a[contains(@href, "/admin/configuration/project'
                             '/add/")]').click()

        textfields = self.findManyBy('xpath', '//input[@type="text"]')
        self.assertEqual(len(textfields), 2)

        # She goes back to the admin page
        self.browser.execute_script("window.history.go(-1)")

        # She can no longer edit institutions (they are managed in the CMS)
        self.findByNot('xpath', '//strong[contains(text(), "Institutions")]')
Example #19
0
 def setUp(self):
     self.factory = RequestFactory()
     view = QuestionnaireStepView(url_namespace='sample')
     self.request = self.factory.get('/en/sample/view/app_1/cat_0/')
     self.request.user = create_new_user()
     self.request._messages = MagicMock()
     self.view = self.setup_view(view, self.request, identifier='sample_1', step='cat_0')
     self.view.form_has_errors = False
Example #20
0
 def setUp(self):
     self.factory = RequestFactory()
     self.url = reverse(route_search_delete_all)
     user = create_new_user()
     user.is_superuser = True
     self.request = self.factory.get(self.url)
     self.request.user = user
     self.request.session = {}
Example #21
0
 def setUp(self):
     view = QuestionnaireView(url_namespace='sample')
     self.request = RequestFactory().get('/en/sample/view/app_1')
     self.request.user = create_new_user()
     self.request.session = dict()
     self.request._messages = MagicMock()
     self.view = self.setup_view(view, self.request, identifier='sample_1')
     get_cached_configuration.cache_clear()
Example #22
0
 def setUp(self):
     view = QuestionnaireView(url_namespace='sample')
     self.request = RequestFactory().get('/en/sample/view/app_1')
     self.request.user = create_new_user()
     self.request.session = dict()
     self.request._messages = MagicMock()
     self.view = self.setup_view(view, self.request, identifier='sample_1')
     get_cached_configuration.cache_clear()
Example #23
0
 def setUp(self):
     self.factory = RequestFactory()
     self.url = reverse(
         route_questionnaire_new_step, kwargs={
             'identifier': 'new', 'step': get_categories()[0][0]})
     self.request = self.factory.get(self.url)
     self.request.user = create_new_user()
     self.request.session = {}
Example #24
0
 def setUp(self):
     self.factory = RequestFactory()
     self.url = reverse(route_search_delete_all)
     user = create_new_user()
     user.is_superuser = True
     self.request = self.factory.get(self.url)
     self.request.user = user
     self.request.session = {}
Example #25
0
    def test_enter_translation_in_review_process(self):
        # Alice logs in
        user_alice = create_new_user()
        user_alice.groups = [Group.objects.get(pk=3), Group.objects.get(pk=4)]
        self.doLogin(user=user_alice)

        # She goes to the form to enter a new Questionnaire
        self.browser.get(self.live_server_url +
                         reverse(route_questionnaire_new))

        # She enters a questionnaire in English
        self.click_edit_section('cat_1')
        self.findBy(
            'name',
            'qg_1-0-original_key_1').send_keys('Foo content in English')

        # She submits the step and sees the values were transmitted correctly.
        self.submit_form_step()
        self.findBy('xpath',
                    '//*[text()[contains(.,"Foo content in English")]]')

        # She submits the questionnaire
        self.review_action('submit')
        self.findBy('xpath',
                    '//*[text()[contains(.,"Foo content in English")]]')

        # She is also moderator and edits the questionnaire again
        self.findBy('xpath', '//a[text()="Edit" and @type="submit"]').click()

        # She changes the language to Spanish
        self.changeLanguage('es')

        # She edits the first section
        self.click_edit_section('cat_1')

        # She sees a warning that she is about to create a new translation
        step_page = SampleStepPage(self)
        assert step_page.has_translation_warning()
        step_page.translation_warning_click_continue()

        # She sees that the field already contains the original value
        text_field = self.findBy('name', 'qg_1-0-translation_key_1')
        self.assertEqual(text_field.get_attribute('value'),
                         'Foo content in English')

        # She changes the value to its Spanish translation
        text_field.clear()
        text_field.send_keys('Foo content in Spanish')

        # She submits the step and sees the values were transmitted correctly.
        step_page.submit_step(confirm_add_translation=True)
        self.findBy('xpath',
                    '//*[text()[contains(.,"Foo content in Spanish")]]')

        # She sees that both languages are available in the tech info metadata
        translations = self.findManyBy(
            'xpath', '//ul[contains(@class, "tech-lang-list")]/li')
        self.assertEqual(len(translations), 2)
Example #26
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))
Example #27
0
 def test_get_roles_permissions_returns_empty(self):
     other_user = create_new_user(id=2,
                                  email='*****@*****.**',
                                  lastname='faz',
                                  firstname='taz')
     questionnaire = get_valid_questionnaire(other_user)
     roles, permissions = questionnaire.get_roles_permissions(self.user)
     self.assertEqual(roles, [])
     self.assertEqual(permissions, [])
Example #28
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)
Example #29
0
 def test_update_users_from_data_removes_user_from_data(self):
     questionnaire = get_valid_questionnaire(self.user)
     user_2 = create_new_user(id=2, email='*****@*****.**')
     questionnaire.add_user(user_2, 'landuser')
     questionnaire.update_users_from_data('sample')
     users = questionnaire.get_users()
     self.assertEqual(len(users), 1)
     self.assertEqual(users[0][0], 'compiler')
     self.assertEqual(users[0][1], self.user)
Example #30
0
 def setUp(self):
     super(SearchTestAdmin, self).setUp()
     create_temp_indices([
         ('sample', '2015')
     ])
     user = create_new_user()
     user.is_superuser = True
     user.save()
     self.user = user
Example #31
0
    def test_enter_translation_in_review_process(self):
        # Alice logs in
        user_alice = create_new_user()
        user_alice.groups = [Group.objects.get(pk=3), Group.objects.get(pk=4)]
        self.doLogin(user=user_alice)

        # She goes to the form to enter a new Questionnaire
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_new))

        # She enters a questionnaire in English
        self.click_edit_section('cat_1')
        self.findBy('name', 'qg_1-0-original_key_1').send_keys(
            'Foo content in English')

        # She submits the step and sees the values were transmitted correctly.
        self.submit_form_step()
        self.findBy(
            'xpath', '//*[text()[contains(.,"Foo content in English")]]')

        # She submits the questionnaire
        self.review_action('submit')
        self.findBy(
            'xpath', '//*[text()[contains(.,"Foo content in English")]]')

        # She is also moderator and edits the questionnaire again
        self.findBy('xpath', '//a[text()="Edit" and @type="submit"]').click()

        # She changes the language to Spanish
        self.changeLanguage('es')

        # She edits the first section
        self.click_edit_section('cat_1')

        # She sees a warning that she is about to create a new translation
        step_page = SampleStepPage(self)
        assert step_page.has_translation_warning()
        step_page.translation_warning_click_continue()

        # She sees that the field already contains the original value
        text_field = self.findBy('name', 'qg_1-0-translation_key_1')
        self.assertEqual(
            text_field.get_attribute('value'), 'Foo content in English')

        # She changes the value to its Spanish translation
        text_field.clear()
        text_field.send_keys('Foo content in Spanish')

        # She submits the step and sees the values were transmitted correctly.
        step_page.submit_step(confirm_add_translation=True)
        self.findBy(
            'xpath', '//*[text()[contains(.,"Foo content in Spanish")]]')

        # She sees that both languages are available in the tech info metadata
        translations = self.findManyBy(
            'xpath', '//ul[contains(@class, "tech-lang-list")]/li')
        self.assertEqual(len(translations), 2)
Example #32
0
 def test_update_users_from_data_removes_user_from_data(self):
     questionnaire = get_valid_questionnaire(self.user)
     user_2 = create_new_user(id=2, email='*****@*****.**')
     questionnaire.add_user(user_2, 'landuser')
     questionnaire.update_users_from_data('sample')
     users = questionnaire.get_users()
     self.assertEqual(len(users), 1)
     self.assertEqual(users[0][0], 'compiler')
     self.assertEqual(users[0][1], self.user)
Example #33
0
 def setUp(self):
     self.factory = RequestFactory()
     self.url = reverse(
         route_search_index,
         kwargs={'configuration': 'sample', 'edition': '2015'})
     user = create_new_user()
     user.is_superuser = True
     self.request = self.factory.get(self.url)
     self.request.user = user
     self.request.session = {}
Example #34
0
 def test_update_users_from_data_adds_user_from_data(self):
     questionnaire = get_valid_questionnaire(self.user)
     user_2 = create_new_user(id=2, email='*****@*****.**')
     questionnaire.data = {'qg_31': [{'key_39': '2', 'key_40': 'Foo Bar'}]}
     questionnaire.update_users_from_data('sample')
     users = questionnaire.get_users()
     self.assertEqual(len(users), 2)
     for role, user in users:
         self.assertIn(role, ['compiler', 'landuser'])
         self.assertIn(user, [self.user, user_2])
Example #35
0
 def test_update_users_from_data_adds_user_from_data(self):
     questionnaire = get_valid_questionnaire(self.user)
     user_2 = create_new_user(id=2, email='*****@*****.**')
     questionnaire.data = {'qg_31': [{'key_39': '2', 'key_40': 'Foo Bar'}]}
     questionnaire.update_users_from_data('sample')
     users = questionnaire.get_users()
     self.assertEqual(len(users), 2)
     for role, user in users:
         self.assertIn(role, ['compiler', 'landuser'])
         self.assertIn(user, [self.user, user_2])
Example #36
0
 def setUp(self):
     self.factory = RequestFactory()
     view = QuestionnaireStepView(url_namespace='sample')
     self.request = self.factory.get('/en/sample/view/app_1/cat_0/')
     self.request.user = create_new_user()
     self.request._messages = MagicMock()
     self.view = self.setup_view(view,
                                 self.request,
                                 identifier='sample_1',
                                 step='cat_0')
     self.view.form_has_errors = False
Example #37
0
 def setUp(self):
     self.factory = RequestFactory()
     self.url = reverse(file_upload_route)
     self.request = self.factory.post(self.url)
     self.request.user = create_new_user()
     self.request.session = {}
     self.mock_request = Mock()
     self.mock_request.method = 'POST'
     self.mock_request.session = {}
     self.mock_request.user = self.request.user
     self.mock_request.FILES.getlist.return_value = [Mock()]
Example #38
0
 def setUp(self):
     self.factory = RequestFactory()
     self.url = reverse(file_upload_route)
     self.request = self.factory.post(self.url)
     self.request.user = create_new_user()
     self.request.session = {}
     self.mock_request = Mock()
     self.mock_request.method = 'POST'
     self.mock_request.session = {}
     self.mock_request.user = self.request.user
     self.mock_request.FILES.getlist.return_value = [Mock()]
Example #39
0
    def test_user_questionnaires_no_duplicates(self):

        # Alice logs in
        user = create_new_user()
        user.groups = [Group.objects.get(pk=3), Group.objects.get(pk=4)]
        user.save()
        self.doLogin(user=user)

        # She goes directly to the Sample questionnaire
        self.browser.get(self.live_server_url +
                         reverse(route_questionnaire_new_step,
                                 kwargs={
                                     'identifier': 'new',
                                     'step': 'cat_1'
                                 }))
        self.findBy(
            'xpath',
            '//input[@name="qg_1-0-original_key_1"]').send_keys('Foo 1')
        self.submit_form_step()
        self.review_action('view')

        details_url = self.browser.current_url

        # She goes to the list of her own questionnaires and sees it.
        self.clickUserMenu(user)
        self.findBy(
            'xpath', '//li[contains(@class, "has-dropdown")]/ul/li/a['
            'contains(@href, "accounts/questionnaires")]').click()
        list_entries = self.findManyBy(
            'xpath', '//article[contains(@class, "tech-item")]')
        self.assertEqual(len(list_entries), 1)
        self.findBy(
            'xpath', '(//article[contains(@class, "tech-item")])[1]//a['
            'contains(text(), "Foo 1")]')

        # She submits, reviews and publishes the questionnaire
        self.browser.get(details_url)
        self.review_action('submit')
        self.review_action('review')
        self.review_action('publish')

        # Back on the list of her own questionnaires, she sees it only once
        self.clickUserMenu(user)
        self.findBy(
            'xpath', '//li[contains(@class, "has-dropdown")]/ul/li/a['
            'contains(@href, "accounts/questionnaires")]').click()

        list_entries = self.findManyBy(
            'xpath', '//article[contains(@class, "tech-item")]')
        self.assertEqual(len(list_entries), 1)
        self.findBy(
            'xpath', '(//article[contains(@class, "tech-item")])[1]//a['
            'contains(text(), "Foo 1")]')
Example #40
0
 def setUp(self):
     self.factory = RequestFactory()
     self.url = reverse(route_search_index,
                        kwargs={
                            'configuration': 'sample',
                            'edition': '2015'
                        })
     user = create_new_user()
     user.is_superuser = True
     self.request = self.factory.get(self.url)
     self.request.user = user
     self.request.session = {}
Example #41
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)
Example #42
0
    def test_user_questionnaires_no_duplicates(self):

        # Alice logs in
        user = create_new_user()
        user.groups = [
            Group.objects.get(pk=3), Group.objects.get(pk=4)]
        user.save()
        self.doLogin(user=user)

        # She goes directly to the Sample questionnaire
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_new_step,
            kwargs={'identifier': 'new', 'step': 'cat_1'}))
        self.findBy(
            'xpath', '//input[@name="qg_1-0-original_key_1"]').send_keys(
                'Foo 1')
        self.submit_form_step()
        self.review_action('view')

        details_url = self.browser.current_url

        # She goes to the list of her own questionnaires and sees it.
        self.clickUserMenu(user)
        self.findBy(
            'xpath', '//li[contains(@class, "has-dropdown")]/ul/li/a['
                     'contains(@href, "accounts/questionnaires")]').click()
        list_entries = self.findManyBy(
            'xpath', '//article[contains(@class, "tech-item")]')
        self.assertEqual(len(list_entries), 1)
        self.findBy(
            'xpath', '(//article[contains(@class, "tech-item")])[1]//a['
            'contains(text(), "Foo 1")]')

        # She submits, reviews and publishes the questionnaire
        self.browser.get(details_url)
        self.review_action('submit')
        self.review_action('review')
        self.review_action('publish')

        # Back on the list of her own questionnaires, she sees it only once
        self.clickUserMenu(user)
        self.findBy(
            'xpath', '//li[contains(@class, "has-dropdown")]/ul/li/a['
                     'contains(@href, "accounts/questionnaires")]').click()

        list_entries = self.findManyBy(
            'xpath', '//article[contains(@class, "tech-item")]')
        self.assertEqual(len(list_entries), 1)
        self.findBy(
            'xpath', '(//article[contains(@class, "tech-item")])[1]//a['
            'contains(text(), "Foo 1")]')
Example #43
0
 def test_logs_call(self):
     """
     Use the requestfactory from the rest-framework, as this handles the
     custom token authentication nicely.
     """
     user = create_new_user()
     request = APIRequestFactory().get(self.url)
     force_authenticate(request, user=user)
     with patch('api.models.RequestLog.save') as mock_save:
         view = QuestionnaireListView()
         view.configuration_code = 'sample'
         view.get_es_results = Mock()
         view.get_es_results.return_value = {}
         view.dispatch(request)
         mock_save.assert_called_once_with()
Example #44
0
 def test_logs_call(self):
     """
     Use the requestfactory from the rest-framework, as this handles the
     custom token authentication nicely.
     """
     user = create_new_user()
     request = APIRequestFactory().get(self.url)
     force_authenticate(request, user=user)
     with patch('api.models.RequestLog.save') as mock_save:
         view = QuestionnaireListView()
         view.configuration_code = 'sample'
         view.get_es_results = Mock()
         view.get_es_results.return_value = {}
         view.dispatch(request)
         mock_save.assert_called_once_with()
Example #45
0
    def test_administrators(self):

        user = create_new_user()
        user.groups = [Group.objects.get(pk=1)]

        self.doLogin(user)

        # Administrators see the link to the administration
        self.findBy(
            'xpath', '//ul[@class="dropdown"]/li/a[@href="/admin/"]')

        # Administrators do not see the link to the Dashboard
        self.findByNot(
            'xpath', '//ul[@class="dropdown"]/li/a[contains(@href, "search/'
            'admin")]')
Example #46
0
    def test_superusers(self):

        user = create_new_user()
        user.is_superuser = True
        user.save()

        self.doLogin(user)

        # Superusers see the link to the administration
        self.findBy(
            'xpath', '//ul[@class="dropdown"]/li/a[@href="/admin/"]')

        # Superusers see the link to the Dashboard
        self.findBy(
            'xpath', '//ul[@class="dropdown"]/li/a[contains(@href, "search/'
            'admin")]')
Example #47
0
    def test_admin_page_translators(self):

        user = create_new_user(id=2, email='*****@*****.**')
        user.groups.add(Group.objects.filter(name='Translators').first())
        user.save()

        # Alice logs in
        self.doLogin(user=user)

        # She sees the admin button in the top navigation bar and clicks on it
        self.clickUserMenu(user)
        navbar = self.findBy('class_name', 'top-bar')
        navbar.find_element_by_link_text('Administration').click()

        column_1 = self.findBy('id', 'column_1')
        with self.assertRaises(NoSuchElementException):
            column_1.find_element_by_id('module_2')
            column_1.find_element_by_id('module_6')
Example #48
0
    def test_admin_page_translators(self):

        user = create_new_user(id=2, email='*****@*****.**')
        user.groups.add(Group.objects.filter(name='Translators').first())
        user.save()

        # Alice logs in
        self.doLogin(user=user)

        # She sees the admin button in the top navigation bar and clicks on it
        self.clickUserMenu(user)
        navbar = self.findBy('class_name', 'top-bar')
        navbar.find_element_by_link_text('Administration').click()

        column_1 = self.findBy('id', 'column_1')
        with self.assertRaises(NoSuchElementException):
            column_1.find_element_by_id('module_2')
            column_1.find_element_by_id('module_6')
Example #49
0
    def test_unccd_focal_point(self):

        unccd_user = create_new_user()
        unccd_user.update(usergroups=[{
            'name': 'UNCCD Focal Point',
            'unccd_country': 'CHE',
        }])

        # Alice logs in
        self.doLogin(user=unccd_user)

        # She goes to her user profile and sees that she is identified as UNCCD
        # focal point for her country.
        self.browser.get(
            self.live_server_url +
            reverse(accounts_route_user, kwargs={'pk': unccd_user.id}))

        self.findBy('xpath', '//*[contains(text(), "UNCCD focal point")]')
        self.findBy('xpath', '//a[contains(text(), "Switzerland")]')
Example #50
0
 def setUp(self):
     super(AdminTest, self).setUp()
     user = create_new_user()
     user.is_superuser = True
     user.save()
     self.user = user
Example #51
0
 def setUp(self):
     self.factory = RequestFactory()
     self.url = reverse(route_questionnaire_new)
     self.request = self.factory.get(self.url)
     self.request.user = create_new_user()
     self.request.session = {}
Example #52
0
    def test_unccd_flag(self):

        unccd_user = create_new_user(id=1, email='*****@*****.**')
        unccd_user.update(usergroups=[{
            'name': 'UNCCD Focal Point',
            'unccd_country': 'CHE',
        }])
        user_editor = User.objects.get(pk=101)
        user_publisher = create_new_user(id=2, email='*****@*****.**')
        user_publisher.groups = [
            Group.objects.get(pk=3),
            Group.objects.get(pk=4)
        ]
        user_publisher.save()

        # Alice logs in
        self.doLogin(user=unccd_user)

        # She goes to a public Questionnaire which is NOT in her country where
        # she does NOT see a possibility to flag the questionnaire as UNCCD best
        # practice.
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_details, kwargs={'identifier': 'sample_3'}))
        self.findByNot('xpath', '//input[@name="flag-unccd"]')

        # She goes to a public Questionnaire which is in her country and now she
        # sees a possibility to flag it.
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_details, kwargs={'identifier': 'sample_1'}))

        # She flags the questionnaire
        self.review_action('flag-unccd')

        # She sees the new UNCCD flag
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')

        # She sees the status flag
        self.findBy('xpath', '//span[contains(@class, "is-reviewed")]')

        # She sees a notice that the new version is now reviewed and it is
        # waiting to be published
        self.findBy('xpath', '//div[contains(@class, "review-panel")]')
        self.findByNot('xpath', '//input[@name="publish"]')

        # An editor logs in and sees the flag. He cannot edit the questionnaire.
        self.doLogin(user=user_editor)
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_details, kwargs={'identifier': 'sample_1'}))
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')
        self.findByNot('xpath', '//a[contains(@href, "sample/edit/")]')

        # A publisher publishes the Questionnaire
        self.doLogin(user=user_publisher)
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_details, kwargs={'identifier': 'sample_1'}))
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')
        self.findBy('xpath', '//a[contains(@href, "sample/edit/")]')
        self.review_action('publish')

        # It is public and flagged
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')
        self.findByNot('xpath', '//span[contains(@class, "is-reviewed")]')

        # The UNCCD user logs in and does not see the option to flag the
        # questionnaire again
        self.doLogin(user=unccd_user)
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_details, kwargs={'identifier': 'sample_1'}))
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')
        self.findByNot('xpath', '//input[@name="flag-unccd"]')

        # However, he sees the option to unflag the Questionnaire
        self.review_action('unflag-unccd', exists_only=True)

        # An editor makes an edit on the Questionnaire
        self.doLogin(user=user_editor)
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_details, kwargs={'identifier': 'sample_1'}))
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')
        self.review_action('edit')
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')

        # He changes some values
        self.findBy('xpath',
                    '(//a[contains(text(), "Edit this section")])[2]').click()
        self.findBy('name', 'qg_1-0-original_key_1').clear()
        self.findBy('name', 'qg_1-0-original_key_1').send_keys('asdf')

        # She saves the step which creates a new version
        self.findBy('id', 'button-submit').click()
        self.findBy('xpath', '//div[contains(@class, "success")]')
        self.findBy('xpath', '//span[contains(@class, "is-draft")]')

        # She sees that the new version also has the UNCCD flag
        self.findBy('xpath', '//p[text()="asdf"]')
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')

        # He submits the Questionnaire
        self.review_action('submit')
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')
        self.findBy('xpath', '//span[contains(@class, "is-submitted")]')

        # The UNCCD user logs in and still sees the public version
        self.doLogin(user=unccd_user)
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_details, kwargs={'identifier': 'sample_1'}))
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')
        self.findByNot('xpath', '//span[contains(@class, "is-draft")]')

        # He cannot unflag the Questionnaire as it has a version in the review
        # cycle.
        self.review_action('unflag-unccd', expected_msg_class='error')

        # The UNCCD flag is still there
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')

        # A publisher publishes the Questionnaire
        self.doLogin(user=user_publisher)
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_details, kwargs={'identifier': 'sample_1'}))
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')
        self.findBy('xpath', '//a[contains(@href, "sample/edit/")]')
        self.review_action('review')
        self.review_action('publish')

        # UNCCD user comes along again and tries to unflag the questionnaire
        # again. This time, it works and the flag is removed.
        self.doLogin(user=unccd_user)
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_details, kwargs={'identifier': 'sample_1'}))
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')
        self.review_action('unflag-unccd')

        # As the user is not linked to the questionnaire anymore, he does not
        # see the reviewed version (no privileges). Instead, he sees the public
        # version
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')
        self.findByNot('xpath', '//span[contains(@class, "is-reviewed")]')

        # Although he sees the button to (again) unflag the questionnaire,
        # nothing happens if he clicks it
        self.review_action('unflag-unccd', expected_msg_class='error')
        self.findBy('xpath', '//span[contains(@class, "is-unccd_bp")]')

        # The publisher publishes the Questionnaire and now the flag is gone.
        self.doLogin(user=user_publisher)
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_details, kwargs={'identifier': 'sample_1'}))
        self.findByNot('xpath', '//span[contains(@class, "is-unccd_bp")]')
        self.findBy('xpath', '//a[contains(@href, "sample/edit/")]')
        self.review_action('publish')
        self.findByNot('xpath', '//span[contains(@class, "is-unccd_bp")]')
Example #53
0
 def test_blocked_for_other_user(self):
     questionnaire = get_valid_questionnaire()
     questionnaire.lock_questionnaire(questionnaire.code, self.user)
     user_2 = create_new_user(id=2, email='*****@*****.**')
     self.assertFalse(questionnaire.can_edit(user_2))
Example #54
0
 def test_blocked_questionnaire_raises_exception(self):
     questionnaire = get_valid_questionnaire()
     questionnaire.lock_questionnaire(questionnaire.code, self.user)
     user_2 = create_new_user(id=2, email='*****@*****.**')
     with self.assertRaises(QuestionnaireLockedException):
         questionnaire.lock_questionnaire(questionnaire.code, user_2)
Example #55
0
 def setUp(self):
     self.user = create_new_user()
     get_cached_configuration.cache_clear()
Example #56
0
 def test_requires_superuser_permissions(self, mock_messages):
     request = self.factory.get(self.url)
     request.user = create_new_user(id=99, email='*****@*****.**')
     request.session = {}
     with self.assertRaises(PermissionDenied):
         index(request, 'foo', 'bar')
Example #57
0
 def setUp(self):
     self.factory = RequestFactory()
     self.url = reverse(route_questionnaire_new)
     self.request = self.factory.get(self.url)
     self.request.user = create_new_user()
     self.request.session = {}
Example #58
0
 def test_requires_superuser_permissions(self):
     request = self.factory.get(self.url)
     request.user = create_new_user()
     request.session = {}
     with self.assertRaises(PermissionDenied):
         admin(request)
Example #59
0
    def test_add_points(self):

        # cat_3_position = get_position_of_category('cat_3', start0=True)

        # Alice logs in
        user_moderator = create_new_user()
        user_moderator.groups = [
            Group.objects.get(pk=3), Group.objects.get(pk=4)]
        self.doLogin(user=user_moderator)

        # She starts editing a new questionnaire, no map is visible
        self.browser.get(self.live_server_url + reverse(
            route_questionnaire_new))
        self.findByNot('class_name', 'map-preview-container')

        # She goes to a step with the map and sets a point on the map
        self.click_edit_section('cat_3')
        map = self.findBy(
            'xpath', '//div[contains(@class, "map-form-container")]')
        self.scroll_to_element(map)
        import time; time.sleep(1)
        map.click()

        # She saves the step
        self.submit_form_step()

        # In the overview, she now sees a map with the point on it
        self.findBy('class_name', 'map-preview-container')

        # In the database, a geometry was added
        db_questionnaire = Questionnaire.objects.order_by('-id')[0]
        geom = db_questionnaire.geom
        self.assertIsNotNone(geom)

        self.click_edit_section('cat_0')
        self.select_chosen_element(
            'id_qg_location_0_country_chosen', 'Afghanistan')
        self.submit_form_step()

        # In the overview, there is still the map with the point.
        self.findBy('class_name', 'map-preview-container')

        # She edits the questionnaire and adds another point
        self.click_edit_section('cat_3')
        map = self.findBy(
            'xpath', '//div[contains(@class, "map-form-container")]')
        self.scroll_to_element(map)
        import time; time.sleep(1)
        self.findBy('xpath', '//label[@for="qg_39_1_1"]').click()
        self.findBy('xpath', '//label[@for="qg_39_1_1"]').click()
        action = webdriver.common.action_chains.ActionChains(self.browser)
        action.move_to_element_with_offset(map, 5, 5)
        action.click()
        action.perform()

        # She submits the step and sees the map on the overview is updated
        self.submit_form_step()
        self.findBy('class_name', 'map-preview-container')

        # In the database, the geometry was updated
        db_questionnaire = Questionnaire.objects.order_by('-id')[0]
        self.assertNotEqual(db_questionnaire.geom, geom)

        # She publishes the questionnaire
        self.rearrangeStickyMenu()
        self.review_action('submit')
        self.review_action('review')
        self.review_action('publish')

        # She sees that still, the map is there on the overview
        self.findBy('class_name', 'map-preview-container')