当前位置: 首页>>代码示例>>Python>>正文


Python ProjectViewSet.as_view方法代码示例

本文整理汇总了Python中onadata.apps.api.viewsets.project_viewset.ProjectViewSet.as_view方法的典型用法代码示例。如果您正苦于以下问题:Python ProjectViewSet.as_view方法的具体用法?Python ProjectViewSet.as_view怎么用?Python ProjectViewSet.as_view使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在onadata.apps.api.viewsets.project_viewset.ProjectViewSet的用法示例。


在下文中一共展示了ProjectViewSet.as_view方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_project_share_remove_user

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_project_share_remove_user(self):
        self._project_create()
        alice_data = {'username': 'alice', 'email': '[email protected]'}
        alice_profile = self._create_user_profile(alice_data)
        view = ProjectViewSet.as_view({
            'post': 'share'
        })
        projectid = self.project.pk
        role_class = ReadOnlyRole
        data = {'username': 'alice', 'role': role_class.name}
        request = self.factory.post('/', data=data, **self.extra)
        response = view(request, pk=projectid)

        self.assertEqual(response.status_code, 204)
        self.assertTrue(role_class.user_has_role(alice_profile.user,
                                                 self.project))

        view = ProjectViewSet.as_view({
            'post': 'share'
        })
        data['remove'] = True
        request = self.factory.post('/', data=data, **self.extra)
        response = view(request, pk=projectid)
        self.assertEqual(response.status_code, 204)
        self.assertFalse(role_class.user_has_role(alice_profile.user,
                                                  self.project))
开发者ID:CharaD7,项目名称:kobocat,代码行数:28,代码来源:test_project_viewset.py

示例2: test_project_share_endpoint

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_project_share_endpoint(self):
        self._project_create()
        alice_data = {'username': 'alice', 'email': '[email protected]'}
        alice_profile = self._create_user_profile(alice_data)
        view = ProjectViewSet.as_view({
            'post': 'share'
        })
        projectid = self.project.pk

        ROLES = [ReadOnlyRole,
                 DataEntryRole,
                 EditorRole,
                 ManagerRole,
                 OwnerRole]
        for role_class in ROLES:
            self.assertFalse(role_class.user_has_role(alice_profile.user,
                                                      self.project))

            data = {'username': 'alice', 'role': role_class.name}
            request = self.factory.post('/', data=data, **self.extra)
            response = view(request, pk=projectid)

            self.assertEqual(response.status_code, 204)
            self.assertTrue(role_class.user_has_role(alice_profile.user,
                                                     self.project))

            data = {'username': 'alice', 'role': ''}
            request = self.factory.post('/', data=data, **self.extra)
            response = view(request, pk=projectid)

            self.assertEqual(response.status_code, 400)
开发者ID:okal,项目名称:onadata,代码行数:33,代码来源:test_project_viewset.py

示例3: test_get_starred_projects

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_get_starred_projects(self):
        self._project_create()

        # add star as bob
        view = ProjectViewSet.as_view({
            'get': 'star',
            'post': 'star'
        })
        request = self.factory.post('/', **self.extra)
        response = view(request, pk=self.project.pk)

        # get starred projects
        view = ConnectViewSet.as_view({
            'get': 'starred',
        })
        request = self.factory.get('/', **self.extra)
        response = view(request, user=self.user)

        self.assertEqual(response.status_code, 200)
        self.project.refresh_from_db()
        request.user = self.user
        self.project_data = ProjectSerializer(
            self.project, context={'request': request}).data
        del self.project_data['date_modified']
        del response.data[0]['date_modified']
        self.assertEqual(len(response.data), 1)
        self.assertDictEqual(dict(response.data[0]), dict(self.project_data))
开发者ID:onaio,项目名称:onadata,代码行数:29,代码来源:test_connect_viewset.py

示例4: _publish_xls_form_to_project

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
 def _publish_xls_form_to_project(self):
     self._project_create()
     view = ProjectViewSet.as_view({
         'post': 'forms'
     })
     project_id = self.project.pk
     data = {
         'owner': 'http://testserver/api/v1/users/bob',
         'public': False,
         'public_data': False,
         'description': u'',
         'downloadable': True,
         'is_crowd_form': False,
         'allows_sms': False,
         'encrypted': False,
         'sms_id_string': u'transportation_2011_07_25',
         'id_string': u'transportation_2011_07_25',
         'title': u'transportation_2011_07_25',
         'bamboo_dataset': u''
     }
     path = os.path.join(
         settings.PROJECT_ROOT, "apps", "main", "tests", "fixtures",
         "transportation", "transportation.xls")
     with open(path) as xls_file:
         post_data = {'xls_file': xls_file}
         request = self.factory.post('/', data=post_data, **self.extra)
         response = view(request, owner='bob', pk=project_id)
         self.assertEqual(response.status_code, 201)
         self.xform = self.user.xforms.all()[0]
         data.update({
             'url':
             'http://testserver/api/v1/forms/bob/%s' % self.xform.pk
         })
         self.assertDictContainsSubset(data, response.data)
         self.form_data = response.data
开发者ID:cagulas,项目名称:onadata,代码行数:37,代码来源:test_abstract_viewset.py

示例5: _project_create

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def _project_create(self, project_data={}, merge=True):
        view = ProjectViewSet.as_view({
            'post': 'create'
        })

        if merge:
            data = {
                'name': u'demo',
                'owner':
                'http://testserver/api/v1/users/%s' % self.user.username,
                'metadata': {'description': 'Some description',
                             'location': 'Naivasha, Kenya',
                             'category': 'governance'},
                'public': False
            }
            data.update(project_data)
        else:
            data = project_data

        request = self.factory.post(
            '/', data=json.dumps(data),
            content_type="application/json", **self.extra)
        response = view(request, owner=self.user.username)
        self.assertEqual(response.status_code, 201)
        self.project = Project.objects.filter(
            name=data['name'], created_by=self.user)[0]
        data['url'] = 'http://testserver/api/v1/projects/%s'\
            % self.project.pk
        self.assertDictContainsSubset(data, response.data)
        self.project_data = ProjectSerializer(
            self.project, context={'request': request}).data
开发者ID:iMMAP,项目名称:onadata,代码行数:33,代码来源:test_abstract_viewset.py

示例6: test_project_share_readonly

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_project_share_readonly(self):
        # create project and publish form to project
        self._publish_xls_form_to_project()
        alice_data = {'username': 'alice', 'email': '[email protected]lhost.com'}
        alice_profile = self._create_user_profile(alice_data)
        projectid = self.project.pk

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

        data = {'username': 'alice', 'role': ReadOnlyRole.name}
        request = self.factory.put('/', data=data, **self.extra)

        view = ProjectViewSet.as_view({
            'put': 'share'
        })
        response = view(request, pk=projectid)

        self.assertEqual(response.status_code, 204)

        self.assertTrue(ReadOnlyRole.user_has_role(alice_profile.user,
                                                   self.project))
        self.assertTrue(ReadOnlyRole.user_has_role(alice_profile.user,
                                                   self.xform))

        perms = role.get_object_users_with_permissions(self.project)
        for p in perms:
            user = p.get('user')

            if user == alice_profile.user:
                r = p.get('role')
                self.assertEquals(r, ReadOnlyRole.name)
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:34,代码来源:test_project_viewset.py

示例7: test_data_in_public_project

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_data_in_public_project(self):
        self._make_submissions()

        view = DataViewSet.as_view({'get': 'list'})
        request = self.factory.get('/', **self.extra)
        formid = self.xform.pk
        response = view(request, pk=formid)
        self.assertEquals(response.status_code, 200)
        self.assertEqual(len(response.data), 4)
        # get project id
        projectid = self.xform.project.pk

        view = ProjectViewSet.as_view({
            'put': 'update'
        })

        data = {'shared': True,
                'name': 'test project',
                'owner': 'http://testserver/api/v1/users/%s'
                % self.user.username}
        request = self.factory.put('/', data=data, **self.extra)
        response = view(request, pk=projectid)

        self.assertEqual(response.status_code, 200)

        # anonymous user
        view = DataViewSet.as_view({'get': 'list'})
        request = self.factory.get('/')
        formid = self.xform.pk
        response = view(request, pk=formid)

        self.assertEquals(response.status_code, 200)
        self.assertEqual(len(response.data), 4)
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:35,代码来源:test_data_viewset.py

示例8: test_project_all_users_can_share_remove_themselves

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_project_all_users_can_share_remove_themselves(self):
        self._publish_xls_form_to_project()
        alice_data = {'username': 'alice', 'email': '[email protected]'}
        self._login_user_and_profile(alice_data)

        view = ProjectViewSet.as_view({
            'put': 'share'
        })

        data = {'username': 'alice', 'remove': True}
        for role_name, role_class in role.ROLES.iteritems():

            ShareProject(self.project, 'alice', role_name).save()

            self.assertTrue(role_class.user_has_role(self.user,
                                                     self.project))
            self.assertTrue(role_class.user_has_role(self.user,
                                                     self.xform))
            data['role'] = role_name

            request = self.factory.put('/', data=data, **self.extra)
            response = view(request, pk=self.project.pk)

            self.assertEqual(response.status_code, 204)

            self.assertFalse(role_class.user_has_role(self.user,
                                                      self.project))
            self.assertFalse(role_class.user_has_role(self.user,
                                                      self.xform))
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:31,代码来源:test_project_viewset.py

示例9: test_assign_form_to_project

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_assign_form_to_project(self):
        view = ProjectViewSet.as_view({
            'post': 'forms',
            'get': 'retrieve'
        })
        self._publish_xls_form_to_project()
        formid = self.xform.pk
        old_project = self.project
        project_name = u'another project'
        self._project_create({'name': project_name})
        self.assertTrue(self.project.name == project_name)

        project_id = self.project.pk
        post_data = {'formid': formid}
        request = self.factory.post('/', data=post_data, **self.extra)
        response = view(request, pk=project_id)
        self.assertEqual(response.status_code, 201)
        self.assertTrue(self.project.projectxform_set.filter(xform=self.xform))
        self.assertFalse(old_project.projectxform_set.filter(xform=self.xform))

        # check if form added appears in the project details
        request = self.factory.get('/', **self.extra)
        response = view(request, pk=self.project.pk)
        self.assertIn('forms', response.data.keys())
        self.assertEqual(len(response.data['forms']), 1)
开发者ID:CharaD7,项目名称:kobocat,代码行数:27,代码来源:test_project_viewset.py

示例10: test_move_project_owner

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_move_project_owner(self):
        # create project and publish form to project
        self._publish_xls_form_to_project()

        alice_data = {'username': 'alice', 'email': '[email protected]'}
        alice_profile = self._create_user_profile(alice_data)
        alice = alice_profile.user
        projectid = self.project.pk

        self.assertFalse(OwnerRole.user_has_role(alice, self.project))

        view = ProjectViewSet.as_view({
            'patch': 'partial_update'
        })

        data_patch = {
            'owner': 'http://testserver/api/v1/users/%s' % alice.username
        }
        request = self.factory.patch('/', data=data_patch, **self.extra)
        response = view(request, pk=projectid)

        self.project.reload()
        self.assertEqual(response.status_code, 200)
        self.assertEquals(self.project.organization, alice)
        self.assertTrue(OwnerRole.user_has_role(alice, self.project))
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:27,代码来源:test_project_viewset.py

示例11: test_project_get_starred_by

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_project_get_starred_by(self):
        self._project_create()

        # add star as bob
        view = ProjectViewSet.as_view({
            'get': 'star',
            'post': 'star'
        })
        request = self.factory.post('/', **self.extra)
        response = view(request, pk=self.project.pk)

        # ensure email not shared
        user_profile_data = self.user_profile_data()
        del user_profile_data['email']

        alice_data = {'username': 'alice', 'email': '[email protected]'}
        self._login_user_and_profile(alice_data)

        # add star as alice
        request = self.factory.post('/', **self.extra)
        response = view(request, pk=self.project.pk)

        # get star users as alice
        request = self.factory.get('/', **self.extra)
        response = view(request, pk=self.project.pk)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 2)

        alice_profile, bob_profile = sorted(response.data,
                                            key=itemgetter('username'))
        self.assertEquals(sorted(bob_profile.items()),
                          sorted(user_profile_data.items()))
        self.assertEqual(alice_profile['username'], 'alice')
开发者ID:CharaD7,项目名称:kobocat,代码行数:36,代码来源:test_project_viewset.py

示例12: test_publish_xlsform_using_url_upload

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_publish_xlsform_using_url_upload(self,  mock_urlopen):
        with HTTMock(enketo_mock):
            self._project_create()
            view = ProjectViewSet.as_view({
                'post': 'forms'
            })

            pre_count = XForm.objects.count()
            project_id = self.project.pk
            xls_url = 'https://ona.io/examples/forms/tutorial/form.xlsx'
            path = os.path.join(
                settings.PROJECT_ROOT, "apps", "main", "tests", "fixtures",
                "transportation", "transportation_different_id_string.xlsx")

            xls_file = open(path)
            mock_urlopen.return_value = xls_file

            post_data = {'xls_url': xls_url}
            request = self.factory.post('/', data=post_data, **self.extra)
            response = view(request, pk=project_id)

            mock_urlopen.assert_called_with(xls_url)
            xls_file.close()
            self.assertEqual(response.status_code, 201)
            self.assertEqual(XForm.objects.count(), pre_count + 1)
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:27,代码来源:test_project_viewset.py

示例13: test_project_manager_can_assign_form_to_project_no_perm

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_project_manager_can_assign_form_to_project_no_perm(self):
        # user must have owner/manager permissions
        view = ProjectViewSet.as_view({
            'post': 'forms',
            'get': 'retrieve'
        })
        self._publish_xls_form_to_project()
        # alice user is not manager to both projects
        alice_data = {'username': 'alice', 'email': '[email protected]'}
        alice_profile = self._create_user_profile(alice_data)
        self.assertFalse(ManagerRole.user_has_role(alice_profile.user,
                                                   self.project))

        formid = self.xform.pk
        project_name = u'another project'
        self._project_create({'name': project_name})
        self.assertTrue(self.project.name == project_name)
        ManagerRole.add(alice_profile.user, self.project)
        self.assertTrue(ManagerRole.user_has_role(alice_profile.user,
                                                  self.project))
        self._login_user_and_profile(alice_data)

        project_id = self.project.pk
        post_data = {'formid': formid}
        request = self.factory.post('/', data=post_data, **self.extra)
        response = view(request, pk=project_id)
        self.assertEqual(response.status_code, 403)
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:29,代码来源:test_project_viewset.py

示例14: test_forms_endpoint_with_metadata

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_forms_endpoint_with_metadata(self):
        date_modified = self.xform.date_modified
        for data_type in ['supporting_doc', 'media', 'source']:
            self._add_form_metadata(self.xform, data_type,
                                    self.data_value, self.path)
            self.xform.refresh_from_db()
            self.assertNotEqual(date_modified, self.xform.date_modified)

        # /forms
        view = XFormViewSet.as_view({
            'get': 'retrieve'
        })
        formid = self.xform.pk
        request = self.factory.get('/', **self.extra)
        response = view(request, pk=formid)
        self.assertEqual(response.status_code, 200)
        data = XFormSerializer(self.xform, context={'request': request}).data
        self.assertEqual(response.data, data)

        # /projects/[pk]/forms
        view = ProjectViewSet.as_view({
            'get': 'forms'
        })
        request = self.factory.get('/', **self.extra)
        response = view(request, pk=self.project.pk)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, [data])
开发者ID:onaio,项目名称:onadata,代码行数:29,代码来源:test_metadata_viewset.py

示例15: test_project_share_inactive_user

# 需要导入模块: from onadata.apps.api.viewsets.project_viewset import ProjectViewSet [as 别名]
# 或者: from onadata.apps.api.viewsets.project_viewset.ProjectViewSet import as_view [as 别名]
    def test_project_share_inactive_user(self):
        # create project and publish form to project
        self._publish_xls_form_to_project()
        alice_data = {'username': 'alice', 'email': '[email protected]'}
        alice_profile = self._create_user_profile(alice_data)

        # set the user inactive
        self.assertTrue(alice_profile.user.is_active)
        alice_profile.user.is_active = False
        alice_profile.user.save()

        projectid = self.project.pk

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

        data = {'username': 'alice', 'role': ReadOnlyRole.name}
        request = self.factory.put('/', data=data, **self.extra)

        view = ProjectViewSet.as_view({
            'put': 'share'
        })
        response = view(request, pk=projectid)

        self.assertEqual(response.status_code, 400)
        self.assertEqual(response.data, {'username': [u'User is not active']})

        self.assertFalse(ReadOnlyRole.user_has_role(alice_profile.user,
                                                    self.project))
        self.assertFalse(ReadOnlyRole.user_has_role(alice_profile.user,
                                                    self.xform))
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:33,代码来源:test_project_viewset.py


注:本文中的onadata.apps.api.viewsets.project_viewset.ProjectViewSet.as_view方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。