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


Python organization_profile_viewset.OrganizationProfileViewSet类代码示例

本文整理汇总了Python中onadata.apps.api.viewsets.organization_profile_viewset.OrganizationProfileViewSet的典型用法代码示例。如果您正苦于以下问题:Python OrganizationProfileViewSet类的具体用法?Python OrganizationProfileViewSet怎么用?Python OrganizationProfileViewSet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_orgs_non_creator_delete

    def test_orgs_non_creator_delete(self):
        self._org_create()

        view = OrganizationProfileViewSet.as_view({
            'delete': 'members',
            'post': 'members'
        })

        self.profile_data['username'] = "alice"
        self.profile_data['email'] = '[email protected]'
        self._create_user_profile()

        alice_data = {'username': 'alice', 'email': '[email protected]'}
        request = self.factory.post(
            '/', data=json.dumps(alice_data),
            content_type="application/json", **self.extra)

        response = view(request, user='denoinc')
        expected_results = [u'denoinc', u'alice']
        self.assertEqual(status.HTTP_201_CREATED, response.status_code)
        self.assertEqual(expected_results, response.data)

        self._login_user_and_profile(extra_post_data=alice_data)

        request = self.factory.delete('/', data=json.dumps(alice_data),
                                      content_type="application/json",
                                      **self.extra)
        response = view(request, user='denoinc')
        expected_results = [u'denoinc']
        self.assertEqual(expected_results, response.data)
开发者ID:onaio,项目名称:onadata,代码行数:30,代码来源:test_organization_profile_viewset.py

示例2: test_put_bad_role

    def test_put_bad_role(self):
        self._org_create()
        newname = 'aboy'
        view = OrganizationProfileViewSet.as_view({
            'get': 'retrieve',
            'post': 'members',
            'put': 'members'
        })

        User.objects.create(username=newname)
        data = {'username': newname}
        request = self.factory.post(
            '/', data=json.dumps(data),
            content_type="application/json", **self.extra)

        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 201)
        self.assertEqual(set(response.data), set([u'denoinc', newname]))

        data = {'username': newname, 'role': 42}
        request = self.factory.put(
            '/', data=json.dumps(data),
            content_type="application/json", **self.extra)

        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 400)
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:26,代码来源:test_organization_profile_viewset.py

示例3: setUp

 def setUp(self):
     super(self.__class__, self).setUp()
     self.view = OrganizationProfileViewSet.as_view({
         'get': 'list',
         'post': 'create',
         'patch': 'partial_update',
     })
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:7,代码来源:test_organization_profile_viewset.py

示例4: test_role_for_org_non_owner

    def test_role_for_org_non_owner(self):
        # creating org with member
        self._org_create()
        view = OrganizationProfileViewSet.as_view({
            'get': 'retrieve',
            'post': 'members'
        })

        self.profile_data['username'] = "aboy"
        self._create_user_profile()
        data = {'username': 'aboy'}
        user_role = 'member'
        request = self.factory.post(
            '/', data=json.dumps(data),
            content_type="application/json", **self.extra)
        response = view(request, user='denoinc')

        # getting profile
        request = self.factory.get('/', **self.extra)
        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 200)
        self.assertIn('users', response.data.keys())

        for user in response.data['users']:
            username = user['user']
            role = user['role']
            expected_role = 'owner' if username == 'denoinc' else user_role
            self.assertEqual(role, expected_role)
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:28,代码来源:test_organization_profile_viewset.py

示例5: test_remove_members_from_org

    def test_remove_members_from_org(self):
        self._org_create()
        newname = 'aboy'
        view = OrganizationProfileViewSet.as_view({
            'post': 'members',
            'delete': 'members'
        })

        User.objects.create(username=newname)
        data = {'username': newname}
        request = self.factory.post(
            '/', data=json.dumps(data),
            content_type="application/json", **self.extra)

        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 201)
        self.assertEqual(set(response.data), set([u'denoinc', newname]))

        request = self.factory.delete(
            '/', json.dumps(data),
            content_type="application/json", **self.extra)

        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data, [u'denoinc'])
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:25,代码来源:test_organization_profile_viewset.py

示例6: test_member_sees_orgs_added_to

    def test_member_sees_orgs_added_to(self):
        self._org_create()
        view = OrganizationProfileViewSet.as_view({
            'get': 'list',
            'post': 'members'
        })

        member = 'aboy'
        expected_data = self.company_data
        expected_data['users'].append({'role': 'member', 'user': member})
        cur_username = self.profile_data['username']
        self.profile_data['username'] = member
        self._login_user_and_profile()
        self.profile_data['username'] = cur_username
        self._login_user_and_profile()

        data = {'username': member}
        request = self.factory.post(
            '/', data=json.dumps(data),
            content_type="application/json", **self.extra)
        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data, [u'denoinc', u'aboy'])

        self.profile_data['username'] = member
        self._login_user_and_profile()

        request = self.factory.get('/', **self.extra)
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, [expected_data])
开发者ID:larryweya,项目名称:onadata,代码行数:31,代码来源:test_organization_profile_viewset.py

示例7: test_add_members_to_org_with_role

    def test_add_members_to_org_with_role(self):
        self._org_create()
        view = OrganizationProfileViewSet.as_view({
            'post': 'members',
            'get': 'retrieve'
        })

        self.profile_data['username'] = "aboy"
        self._create_user_profile()
        data = {'username': 'aboy',
                'role': 'editor'}
        request = self.factory.post(
            '/', data=json.dumps(data),
            content_type="application/json", **self.extra)

        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 201)

        self.assertEqual(set(response.data), set([u'denoinc', u'aboy']))

        # getting profile
        request = self.factory.get('/', **self.extra)
        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['users'][1]['user'], 'aboy')
        self.assertEqual(response.data['users'][1]['role'], 'editor')
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:26,代码来源:test_organization_profile_viewset.py

示例8: test_org_members_added_to_projects

    def test_org_members_added_to_projects(self):
        # create org
        self._org_create()
        view = OrganizationProfileViewSet.as_view({
            'post': 'members',
            'get': 'retrieve',
            'put': 'members'
        })

        # create aboy
        self.profile_data['username'] = "aboy"
        aboy = self._create_user_profile().user

        data = {'username': 'aboy',
                'role': 'owner'}
        request = self.factory.post(
            '/', data=json.dumps(data),
            content_type="application/json", **self.extra)
        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 201)

        # create a proj
        project_data = {
            'owner': self.company_data['user']
        }
        self._project_create(project_data)
        self._publish_xls_form_to_project()

        # create alice
        self.profile_data['username'] = "alice"
        alice = self._create_user_profile().user
        alice_data = {'username': 'alice',
                      'role': 'owner'}
        request = self.factory.post(
            '/', data=json.dumps(alice_data),
            content_type="application/json", **self.extra)
        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 201)

        # Assert that user added in org is added to teams in proj
        self.assertTrue(OwnerRole.user_has_role(aboy, self.project))
        self.assertTrue(OwnerRole.user_has_role(alice, self.project))
        self.assertTrue(OwnerRole.user_has_role(aboy, self.xform))
        self.assertTrue(OwnerRole.user_has_role(alice, self.xform))

        # Org admins are added to owners in project
        projectView = ProjectViewSet.as_view({
            'get': 'retrieve'
        })
        request = self.factory.get('/', **self.extra)
        response = projectView(request, pk=self.project.pk)
        project_users = response.data.get('users')
        users_in_users = [user['user'] for user in project_users]

        self.assertIn('bob', users_in_users)
        self.assertIn('denoinc', users_in_users)
        self.assertIn('aboy', users_in_users)
        self.assertIn('alice', users_in_users)
开发者ID:onaio,项目名称:onadata,代码行数:58,代码来源:test_organization_profile_viewset.py

示例9: test_orgs_members_list

    def test_orgs_members_list(self):
        self._org_create()
        view = OrganizationProfileViewSet.as_view({
            'get': 'members'
        })

        request = self.factory.get('/', **self.extra)
        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data, [u'denoinc'])
开发者ID:iMMAP,项目名称:onadata,代码行数:10,代码来源:test_organization_profile_viewset.py

示例10: test_add_members_to_org_username_required

 def test_add_members_to_org_username_required(self):
     self._org_create()
     view = OrganizationProfileViewSet.as_view({
         'post': 'members'
     })
     request = self.factory.post('/', data={}, **self.extra)
     response = view(request, user='denoinc')
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.data,
                      {u'username': [u"This field is required."]})
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:10,代码来源:test_organization_profile_viewset.py

示例11: test_orgs_get_anon

 def test_orgs_get_anon(self):
     self._org_create()
     view = OrganizationProfileViewSet.as_view({
         'get': 'retrieve'
     })
     request = self.factory.get('/')
     response = view(request, user='denoinc')
     self.assertNotEqual(response.get('Last-Modified'), None)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, self.company_data)
     self.assertIn('users', response.data.keys())
     for user in response.data['users']:
         self.assertEqual(user['role'], 'owner')
         self.assertEqual(type(user['user']), unicode)
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:14,代码来源:test_organization_profile_viewset.py

示例12: test_add_members_to_org_user_does_not_exist

    def test_add_members_to_org_user_does_not_exist(self):
        self._org_create()
        view = OrganizationProfileViewSet.as_view({
            'post': 'members'
        })
        data = {'username': 'aboy'}
        request = self.factory.post(
            '/', data=json.dumps(data),
            content_type="application/json", **self.extra)

        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 400)
        self.assertEqual(response.data,
                         {u'username': [u"User `aboy` does not exist."]})
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:14,代码来源:test_organization_profile_viewset.py

示例13: test_orgs_get

 def test_orgs_get(self):
     self._org_create()
     view = OrganizationProfileViewSet.as_view({
         'get': 'retrieve'
     })
     request = self.factory.get('/', **self.extra)
     response = view(request)
     self.assertEqual(response.status_code, 400)
     self.assertEqual(
         response.data, {'detail': 'Expected URL keyword argument `user`.'})
     request = self.factory.get('/', **self.extra)
     response = view(request, user='denoinc')
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.data, self.company_data)
开发者ID:eHealthAfrica,项目名称:onadata,代码行数:14,代码来源:test_organization_profile_viewset.py

示例14: test_orgs_get_anon

 def test_orgs_get_anon(self):
     self._org_create()
     view = OrganizationProfileViewSet.as_view({
         'get': 'retrieve'
     })
     request = self.factory.get('/')
     response = view(request, user='denoinc')
     self.assertNotEqual(response.get('Cache-Control'), None)
     self.assertEqual(response.status_code, 200)
     del self.company_data['metadata']
     self.assertEqual(response.data, self.company_data)
     self.assertIn('users', list(response.data))
     for user in response.data['users']:
         self.assertEqual(user['role'], 'owner')
         self.assertTrue(isinstance(user['user'], text))
开发者ID:onaio,项目名称:onadata,代码行数:15,代码来源:test_organization_profile_viewset.py

示例15: test_add_members_to_org_with_anonymous_user

    def test_add_members_to_org_with_anonymous_user(self):
        self._org_create()
        view = OrganizationProfileViewSet.as_view({
            'post': 'members'
        })

        User.objects.create(username='aboy')
        data = {'username': 'aboy'}
        request = self.factory.post(
            '/', data=json.dumps(data),
            content_type="application/json")

        response = view(request, user='denoinc')
        self.assertEqual(response.status_code, 401)
        self.assertNotEquals(set(response.data), set([u'denoinc', u'aboy']))
开发者ID:MichaelRoethlin,项目名称:onadata,代码行数:15,代码来源:test_organization_profile_viewset.py


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