Ejemplo n.º 1
0
    def test_read_only_users_get_non_empty_formlist_using_preview_formlist(
            self, mock_send_mail):
        alice_data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': 'alice',
            'password2': 'alice'
        }
        alice_profile = self._create_user_profile(alice_data)

        self.assertFalse(
            ReadOnlyRole.user_has_role(alice_profile.user, self.project))

        # share bob's project with alice
        data = {
            'username': '******',
            'role': ReadOnlyRole.name,
            'email_msg': 'I have shared the project with you'
        }
        request = self.factory.post('/', data=data, **self.extra)
        share_view = ProjectViewSet.as_view({'post': 'share'})
        projectid = self.project.pk
        response = share_view(request, pk=projectid)
        self.assertEqual(response.status_code, 204)
        self.assertTrue(mock_send_mail.called)
        self.assertTrue(
            ReadOnlyRole.user_has_role(alice_profile.user, self.project))

        # check that she can authenticate successfully
        request = self.factory.get('/')
        response = self.view(request)
        self.assertEqual(response.status_code, 401)
        auth = DigestAuth('alice', 'alice')
        request.META.update(auth(request.META, response))
        response = self.view(request, username='******')
        self.assertEqual(response.status_code, 200)
        # check that alice gets an empty response when requesting bob's
        # formlist
        self.assertEqual(response.data, [])

        # set endpoint to preview formList
        self.view = PreviewXFormListViewSet.as_view({"get": "list"})

        request = self.factory.get('/')
        response = self.view(request)
        self.assertEqual(response.status_code, 401)
        self.assertNotEqual(response.data, [])
        auth = DigestAuth('alice', 'alice')
        request.META.update(auth(request.META, response))
        response = self.view(request, username='******')
        self.assertEqual(response.status_code, 200)
        # check that alice does NOT get an empty response when requesting bob's
        # formlist when using the preview formlist endpoint
        self.assertNotEqual(response.data, [])
Ejemplo n.º 2
0
    def test_read_only_users_get_non_empty_formlist_using_preview_formlist(
            self, mock_send_mail):
        alice_data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': 'alice',
            'password2': 'alice'
        }
        alice_profile = self._create_user_profile(alice_data)

        self.assertFalse(
            ReadOnlyRole.user_has_role(alice_profile.user, self.project))

        # share bob's project with alice
        data = {
            'username': '******',
            'role': ReadOnlyRole.name,
            'email_msg': 'I have shared the project with you'
        }
        request = self.factory.post('/', data=data, **self.extra)
        share_view = ProjectViewSet.as_view({'post': 'share'})
        projectid = self.project.pk
        response = share_view(request, pk=projectid)
        self.assertEqual(response.status_code, 204)
        self.assertTrue(mock_send_mail.called)
        self.assertTrue(
            ReadOnlyRole.user_has_role(alice_profile.user, self.project))

        # check that she can authenticate successfully
        request = self.factory.get('/')
        response = self.view(request)
        self.assertEqual(response.status_code, 401)
        auth = DigestAuth('alice', 'alice')
        request.META.update(auth(request.META, response))
        response = self.view(request, username='******')
        self.assertEqual(response.status_code, 200)
        # check that alice gets an empty response when requesting bob's
        # formlist
        self.assertEqual(response.data, [])

        # set endpoint to preview formList
        self.view = PreviewXFormListViewSet.as_view({"get": "list"})

        request = self.factory.get('/')
        response = self.view(request)
        self.assertEqual(response.status_code, 401)
        self.assertNotEqual(response.data, [])
        auth = DigestAuth('alice', 'alice')
        request.META.update(auth(request.META, response))
        response = self.view(request, username='******')
        self.assertEqual(response.status_code, 200)
        # check that alice does NOT get an empty response when requesting bob's
        # formlist when using the preview formlist endpoint
        self.assertNotEqual(response.data, [])
Ejemplo n.º 3
0
         name='form-list'),
 re_path(r'^enketo/(?P<xform_pk>\w+)/formList$',
         XFormListViewSet.as_view({
             'get': 'list',
             'head': 'list'
         }),
         name='form-list'),
 re_path(r'^(?P<username>\w+)/(?P<xform_pk>\d+)/formList$',
         XFormListViewSet.as_view({
             'get': 'list',
             'head': 'list'
         }),
         name='form-list'),
 re_path(r'^preview/(?P<username>\w+)/(?P<xform_pk>\d+)/formList$',
         PreviewXFormListViewSet.as_view({
             'get': 'list',
             'head': 'list'
         }),
         name='form-list'),
 re_path(r'^preview/(?P<username>\w+)/formList$',
         PreviewXFormListViewSet.as_view({
             'get': 'list',
             'head': 'list'
         }),
         name='form-list'),
 re_path(r'^(?P<username>\w+)/xformsManifest/(?P<pk>[\d+^/]+)$',
         XFormListViewSet.as_view({
             'get': 'manifest',
             'head': 'manifest'
         }),
         name='manifest-url'),
 re_path(r'^xformsManifest/(?P<pk>[\d+^/]+)$',
Ejemplo n.º 4
0
    # odk data urls
    re_path(r'^submission$',
        XFormSubmissionViewSet.as_view({'post': 'create', 'head': 'create'}),
        name='submissions'),
    re_path(r'^formList$',
        XFormListViewSet.as_view({'get': 'list', 'head': 'list'}),
        name='form-list'),
    re_path(r'^(?P<username>\w+)/formList$',
        XFormListViewSet.as_view({'get': 'list', 'head': 'list'}),
        name='form-list'),
    re_path(r'^(?P<username>\w+)/(?P<xform_pk>\d+)/formList$',
        XFormListViewSet.as_view({'get': 'list', 'head': 'list'}),
        name='form-list'),
    re_path(r'^preview/(?P<username>\w+)/(?P<xform_pk>\d+)/formList$',
        PreviewXFormListViewSet.as_view({'get': 'list', 'head': 'list'}),
        name='form-list'),
    re_path(r'^preview/(?P<username>\w+)/formList$',
        PreviewXFormListViewSet.as_view({'get': 'list', 'head': 'list'}),
        name='form-list'),
    re_path(r'^(?P<username>\w+)/xformsManifest/(?P<pk>[\d+^/]+)$',
        XFormListViewSet.as_view({'get': 'manifest', 'head': 'manifest'}),
        name='manifest-url'),
    re_path(r'^xformsManifest/(?P<pk>[\d+^/]+)$',
        XFormListViewSet.as_view({'get': 'manifest', 'head': 'manifest'}),
        name='manifest-url'),
    re_path(r'^(?P<username>\w+)/xformsMedia/(?P<pk>[\d+^/]+)/(?P<metadata>[\d+^/.]+)$', # noqa
        XFormListViewSet.as_view({'get': 'media', 'head': 'media'}),
        name='xform-media'),
    re_path(r'^(?P<username>\w+)/xformsMedia/(?P<pk>[\d+^/]+)/(?P<metadata>[\d+^/.]+)\.(?P<format>([a-z]|[0-9])*)$',# noqa
        XFormListViewSet.as_view({'get': 'media', 'head': 'media'}),