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


Python base.oauth2Header函数代码示例

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


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

示例1: test_change_restricted_context_to_susbcribed_maintain_write_veto

    def test_change_restricted_context_to_susbcribed_maintain_write_veto(self):
        """
            Create a write restricted context, admin subscribes the user to context, but he cannot write.
            Admin also adds a persistent "don't write" veto to this user.
            Change the context to write subscribed, and user still can't write.
        """
        from .mockers import create_context
        from .mockers import subscribe_context
        from .mockers import user_status_context

        url_hash = sha1(create_context["url"]).hexdigest()
        username = "messi"
        self.create_user(username)
        self.create_context(
            create_context,
            permissions=dict(read="subscribed", write="restricted", subscribe="restricted", invite="restricted"),
        )
        self.admin_subscribe_user_to_context(username, subscribe_context, expect=201)

        permission = "write"
        res = self.testapp.delete(
            "/contexts/%s/permissions/%s/%s?permanent=1" % (url_hash, username, permission),
            "",
            oauth2Header(test_manager),
            status=201,
        )

        data = json.dumps({"permissions": {"write": "subscribed"}})
        res = self.testapp.put("/contexts/%s" % url_hash, data, oauth2Header(test_manager), status=200)
        self.assertEqual(res.json["permissions"]["read"], "subscribed")
        self.assertEqual(res.json["permissions"]["write"], "subscribed")
        res = self.create_activity(username, user_status_context, expect=403)
开发者ID:UPCnet,项目名称:max,代码行数:32,代码来源:test_subscriptions.py

示例2: test_get_message_file_as_non_participant

    def test_get_message_file_as_non_participant(self):
        """
            Given i'm nota regular user
            And i'm not a conversation participant
            When i try to view a file attachment
            Then i get a Forbidden Exception
        """
        from max.tests.mockers import message
        from max.tests.mockers import message_with_file
        sender = 'messi'
        recipient = 'xavi'
        recipient2 = 'shakira'

        self.create_user(sender)
        self.create_user(recipient)
        self.create_user(recipient2)

        res = self.testapp.post('/conversations', json.dumps(message), oauth2Header(sender), status=201)
        cid = res.json['contexts'][0]['id']

        thefile = open(os.path.join(self.conf_dir, "map.pdf"), "rb")
        files = [('file', 'map.pdf', thefile.read(), 'application/pdf')]

        res = self.testapp.post('/conversations', json.dumps(message), oauth2Header(sender), status=201)
        cid = str(res.json['contexts'][0]['id'])
        message_id = self.testapp.post('/conversations/%s/messages' % cid, dict(json_data=json.dumps(message_with_file)), oauth2Header(sender), upload_files=files, status=201).json['id']
        self.testapp.get('/messages/%s/file/download' % (message_id), headers=oauth2Header(recipient2), status=403)
开发者ID:UPCnet,项目名称:max,代码行数:27,代码来源:test_messages_acls.py

示例3: test_post_message_with_image_to_an_already_existing_conversation

    def test_post_message_with_image_to_an_already_existing_conversation(self):
        from .mockers import message, message_with_image
        sender = 'messi'
        recipient = 'xavi'
        self.create_user(sender)
        self.create_user(recipient)

        thefile = open(os.path.join(os.path.dirname(__file__), "avatar.png"), "rb")
        files = [('file', 'avatar.png', thefile.read(), 'image/png')]

        res = self.testapp.post('/conversations', json.dumps(message), oauth2Header(sender), status=201)
        cid = str(res.json['contexts'][0]['id'])
        self.testapp.post('/conversations/%s/messages' % cid, dict(json_data=json.dumps(message_with_image)), oauth2Header(sender), upload_files=files, status=201)

        res = self.testapp.get('/conversations/%s/messages' % cid, "", oauth2Header(sender), status=200)
        result = json.loads(res.text)

        self.assertEqual(len(result), 2)
        self.assertEqual(result[0].get("contexts", None)[0].get("id", None), cid)
        self.assertEqual(result[0].get("contexts", None)[0].get("objectType", None), "conversation")
        self.assertEqual(result[0].get("objectType", None), "message")
        self.assertEqual(result[1]['object'].get('fullURL'), u'/messages/{}/image/full'.format(result[1]['id']))
        self.assertEqual(result[1]['object'].get('thumbURL'), u'/messages/{}/image/thumb'.format(result[1]['id']))

        full_url = result[1]['object'].get('fullURL')
        res = self.testapp.get(full_url, '', oauth2Header(sender), status=200)
开发者ID:UPCnet,项目名称:max,代码行数:26,代码来源:test_files.py

示例4: test_unfavorite_activity_get_other_favorites

    def test_unfavorite_activity_get_other_favorites(self):
        """
           Given a plain user
           and a regular context
           When i post an activity in a context
           And varius users favorite it
           And someone unfavorite it
           Then someone who unfavorite this activity
           and the rest of favorites remains
        """
        from .mockers import user_status_context
        from .mockers import subscribe_context, create_context
        username = 'messi'
        username_not_me = 'xavi'
        self.create_user(username)
        self.create_user(username_not_me)
        self.create_context(create_context)
        self.admin_subscribe_user_to_context(username, subscribe_context)
        self.admin_subscribe_user_to_context(username_not_me, subscribe_context)
        res = self.create_activity(username, user_status_context)
        activity_id = res.json['id']
        res = self.testapp.post('/activities/%s/favorites' % activity_id, '', oauth2Header(username_not_me), status=201)
        res = self.testapp.post('/activities/%s/favorites' % activity_id, '', oauth2Header(username), status=201)
        res = self.testapp.delete('/activities/%s/favorites/%s' % (activity_id, username_not_me), '', oauth2Header(username_not_me), status=200)

        self.assertEqual(res.json['object']['favorites'][0]['username'], username)
        self.assertEqual(res.json['object']['favorited'], False)
        self.assertEqual(res.json['object']['favoritesCount'], 1)
开发者ID:UPCnet,项目名称:max,代码行数:28,代码来源:test_favorites.py

示例5: test_unflag_flagged_activity_subscribed_no_flag_permission

    def test_unflag_flagged_activity_subscribed_no_flag_permission(self):
        """
            Given i'm a regular user
            And i'm subscribed to the activity context
            And i don't have the flag permission on the context
            When I try to unflag a flagged activity
            Then I get a Forbidden Exception
        """
        from max.tests.mockers import user_status_context
        from max.tests.mockers import subscribe_context, create_context
        from hashlib import sha1

        username = "sheldon"
        username_not_me = "penny"
        self.create_user(username)
        self.create_user(username_not_me)
        self.create_context(create_context)
        chash = sha1(create_context["url"]).hexdigest()
        self.admin_subscribe_user_to_context(username, subscribe_context)
        self.admin_subscribe_user_to_context(username_not_me, subscribe_context)
        self.grant_permission(chash, username, "flag")

        res = self.create_activity(username, user_status_context)
        activity_id = res.json["id"]
        res = self.testapp.post("/activities/%s/flag" % activity_id, "", oauth2Header(username), status=201)
        res = self.testapp.delete("/activities/%s/flag" % activity_id, "", oauth2Header(username_not_me), status=403)
开发者ID:UPCnet,项目名称:max,代码行数:26,代码来源:test_social_acls.py

示例6: test_get_message_image_as_participant

    def test_get_message_image_as_participant(self):
        """
            Given i'm a regular user
            And i'm a conversation participant
            When i try to view a message image attachment
            Then i succeed
        """
        from max.tests.mockers import message
        from max.tests.mockers import message_with_image
        sender = 'messi'
        recipient = 'xavi'

        self.create_user(sender)
        self.create_user(recipient)

        res = self.testapp.post('/conversations', json.dumps(message), oauth2Header(sender), status=201)
        cid = res.json['contexts'][0]['id']

        thefile = open(os.path.join(self.conf_dir, "avatar.png"), "rb")
        files = [('file', 'avatar.png', thefile.read(), 'image/png')]

        res = self.testapp.post('/conversations', json.dumps(message), oauth2Header(sender), status=201)
        cid = str(res.json['contexts'][0]['id'])
        message_id = self.testapp.post('/conversations/%s/messages' % cid, dict(json_data=json.dumps(message_with_image)), oauth2Header(sender), upload_files=files, status=201).json['id']
        self.testapp.get('/messages/%s/image' % (message_id), headers=oauth2Header(recipient), status=200)
开发者ID:UPCnet,项目名称:max,代码行数:25,代码来源:test_messages_acls.py

示例7: test_change_public_context_to_restricted_preserve_granted_write_permission

    def test_change_public_context_to_restricted_preserve_granted_write_permission(self):
        """
            Create a public context, user subscribes to context.
            Extra grant write permission to the user
            Change the context to write=restricted, and user still have the write permission
        """
        from .mockers import create_context
        from .mockers import subscribe_context
        from .mockers import user_status_context

        url_hash = sha1(create_context["url"]).hexdigest()
        username = "messi"
        self.create_user(username)
        self.create_context(
            create_context,
            permissions=dict(read="subscribed", write="subscribed", subscribe="public", invite="restricted"),
        )
        self.user_subscribe_user_to_context(username, subscribe_context, expect=201)
        permission = "write"
        res = self.testapp.put(
            "/contexts/%s/permissions/%s/%s?permanent=1" % (url_hash, username, permission),
            "",
            oauth2Header(test_manager),
            status=201,
        )
        data = json.dumps({"permissions": {"write": "restricted"}})
        res = self.testapp.put("/contexts/%s" % url_hash, data, oauth2Header(test_manager), status=200)
        self.assertEqual(res.json["permissions"]["read"], "subscribed")
        self.assertEqual(res.json["permissions"]["write"], "restricted")
        res = self.create_activity(username, user_status_context, expect=201)
开发者ID:UPCnet,项目名称:max,代码行数:30,代码来源:test_subscriptions.py

示例8: test_delete_device_token

    def test_delete_device_token(self):
        username = 'messi'
        token = {'platform': 'ios', 'token': '12345678901234567890123456789012'}

        self.create_user(username)
        self.testapp.post('/tokens', json.dumps(token), oauth2Header(username), status=201)
        self.testapp.delete('/tokens/%s' % (token['token']), "", oauth2Header(username), status=204)
开发者ID:UPCnet,项目名称:max,代码行数:7,代码来源:test_tokens.py

示例9: test_maintenance_subscriptions

    def test_maintenance_subscriptions(self):
        from .mockers import create_context
        from .mockers import subscribe_context, user_status_context
        from hashlib import sha1

        username = 'messi'
        self.create_user(username)
        self.create_context(create_context, permissions=dict(read='subscribed', write='subscribed', subscribe='restricted', invite='restricted'))
        chash = sha1(create_context['url']).hexdigest()
        self.admin_subscribe_user_to_context(username, subscribe_context)
        self.create_activity(username, user_status_context)

        # Hard modify context directly on mongo to simulate changed permissions, displayName and tags
        contexts = self.exec_mongo_query('contexts', 'find', {'hash': chash})
        context = contexts[0]
        context['permissions']['write'] = 'restricted'
        context['displayName'] = 'Changed Name'
        context['tags'].append('new tag')
        self.exec_mongo_query('contexts', 'update', {'_id': context['_id']}, context)
        self.testapp.post('/admin/maintenance/subscriptions', "", oauth2Header(test_manager), status=200)

        # Check user subscription is updated
        res = self.testapp.get('/people/{}'.format(username), "", oauth2Header(username), status=200)
        self.assertEqual(res.json['subscribedTo'][0]['displayName'], 'Changed Name')
        self.assertListEqual(res.json['subscribedTo'][0]['tags'], ['Assignatura', 'new tag'])
        self.assertListEqual(res.json['subscribedTo'][0]['permissions'], ['read'])

        # Check user activity is updated
        res = self.testapp.get('/people/{}/timeline'.format(username), "", oauth2Header(username), status=200)
        self.assertEqual(res.json[0]['contexts'][0]['displayName'], 'Changed Name')
        self.assertListEqual(res.json[0]['contexts'][0]['tags'], ['Assignatura', 'new tag'])
开发者ID:UPCnet,项目名称:max,代码行数:31,代码来源:test_maintenance.py

示例10: test_get_pushtokens_for_given_conversations

    def test_get_pushtokens_for_given_conversations(self):
        """ doctest .. http:get:: /conversations/{id}/tokens """
        from .mockers import message
        sender = 'messi'
        recipient = 'xavi'
        self.create_user(sender)
        self.create_user(recipient)

        platform = 'ios'
        token_sender = '12345678901234567890123456789012'
        token_recipient = '12345678901234567890123456789013'
        self.testapp.post('/people/%s/device/%s/%s' % (sender, platform, token_sender), "", oauth2Header(sender), status=201)
        self.testapp.post('/people/%s/device/%s/%s' % (recipient, platform, token_recipient), "", oauth2Header(recipient), status=201)

        res = self.testapp.post('/conversations', json.dumps(message), oauth2Header(sender), status=201)
        conversation_id = res.json['contexts'][0]['id']

        res = self.testapp.get('/conversations/%s/tokens' % (conversation_id), '', oauth2Header(test_manager), status=200)
        self.assertEqual(res.json[0]['platform'], u'ios')
        self.assertEqual(res.json[0]['token'], u'12345678901234567890123456789013')
        self.assertEqual(res.json[0]['username'], u'xavi')

        self.assertEqual(res.json[1]['platform'], u'ios')
        self.assertEqual(res.json[1]['token'], u'12345678901234567890123456789012')
        self.assertEqual(res.json[1]['username'], u'messi')
        self.assertEqual(len(res.json), 2)
开发者ID:UPCnet,项目名称:max,代码行数:26,代码来源:test_tokens.py

示例11: test_security_remove_user_from_role_check_security_reloaded

 def test_security_remove_user_from_role_check_security_reloaded(self):
     test_manager2 = 'messi'
     self.create_user(test_manager2)
     self.testapp.post('/admin/security/roles/%s/users/%s' % ('Manager', test_manager2), "", oauth2Header(test_manager), status=201)
     self.testapp.get('/activities', "", oauth2Header(test_manager2), status=200)
     self.testapp.delete('/admin/security/roles/%s/users/%s' % ('Manager', test_manager2), "", oauth2Header(test_manager), status=204)
     self.testapp.get('/activities', "", oauth2Header(test_manager2), status=403)
开发者ID:UPCnet,项目名称:max,代码行数:7,代码来源:test_security.py

示例12: test_remove_context_tag

 def test_remove_context_tag(self):
     from hashlib import sha1
     from .mockers import create_context
     self.create_context(create_context)
     url_hash = sha1(create_context['url']).hexdigest()
     self.testapp.put('/contexts/%s/tags' % url_hash, json.dumps(['prova']), oauth2Header(test_manager), status=200)
     self.testapp.delete('/contexts/%s/tags/%s' % (url_hash, 'Assignatura'), "", oauth2Header(test_manager), status=204)
开发者ID:UPCnet,项目名称:max,代码行数:7,代码来源:test_contexts.py

示例13: test_rename_context_url

    def test_rename_context_url(self):
        from .mockers import create_context
        from .mockers import subscribe_context, user_status_context
        from hashlib import sha1

        username = 'messi'
        self.create_user(username)
        self.create_context(create_context, permissions=dict(read='subscribed', write='subscribed', subscribe='restricted', invite='restricted'))
        self.admin_subscribe_user_to_context(username, subscribe_context)
        activity = self.create_activity(username, user_status_context)

        url_hash = sha1(create_context['url']).hexdigest()
        res = self.testapp.put('/contexts/%s' % url_hash, json.dumps({"url": "http://new.url"}), oauth2Header(test_manager), status=200)

        # Test context is updated
        new_url_hash = sha1('http://new.url').hexdigest()
        res = self.testapp.get('/contexts/%s' % new_url_hash, "", oauth2Header(test_manager), status=200)
        self.assertEqual(res.json['url'], 'http://new.url')
        self.assertEqual(res.json['hash'], new_url_hash)

        # Test user subscription is updated
        res = self.testapp.get('/people/%s' % username, "", oauth2Header(test_manager), status=200)
        self.assertEqual(res.json['subscribedTo'][0]['url'], 'http://new.url')
        self.assertEqual(res.json['subscribedTo'][0]['hash'], new_url_hash)

        # Test user original subscription activity is updated
        subscription_activity = self.exec_mongo_query('activity', 'find', {'object.hash': new_url_hash, 'object.url': "http://new.url", 'actor.username': username})
        self.assertNotEqual(subscription_activity, [])
        self.assertEqual(subscription_activity[0]['object']['hash'], new_url_hash)
        self.assertEqual(subscription_activity[0]['object']['url'], 'http://new.url')

        # Test user activity is updated
        res = self.testapp.get('/activities/%s' % activity.json['id'], "", oauth2Header(test_manager), status=200)
        self.assertEqual(res.json['contexts'][0]['url'], 'http://new.url')
        self.assertEqual(res.json['contexts'][0]['hash'], new_url_hash)
开发者ID:UPCnet,项目名称:max,代码行数:35,代码来源:test_admin.py

示例14: test_like_activity_by_various

    def test_like_activity_by_various(self):
        """
           Given a plain user
           and a regular context
           When i post an activity in a context
           Then someone else can like this activity
           and i also can like it
        """
        from .mockers import user_status_context
        from .mockers import subscribe_context, create_context
        username = 'messi'
        username_not_me = 'xavi'
        self.create_user(username)
        self.create_user(username_not_me)
        self.create_context(create_context)
        self.admin_subscribe_user_to_context(username, subscribe_context)
        self.admin_subscribe_user_to_context(username_not_me, subscribe_context)
        res = self.create_activity(username, user_status_context)
        activity_id = res.json['id']
        res = self.testapp.post('/activities/%s/likes' % activity_id, '', oauth2Header(username_not_me), status=201)
        res = self.testapp.post('/activities/%s/likes' % activity_id, '', oauth2Header(username), status=201)

        self.assertEqual(res.json['object']['likes'][0]['username'], username_not_me)
        self.assertEqual(res.json['object']['likes'][1]['username'], username)
        self.assertEqual(res.json['object']['liked'], True)
        self.assertEqual(res.json['object']['likesCount'], 2)
开发者ID:UPCnet,项目名称:max,代码行数:26,代码来源:test_likes.py

示例15: test_unfavorite_activity

    def test_unfavorite_activity(self):
        """
           Given a plain user
           and a regular context
           When i post an activity in a context
           Then someone else can remove previously favorite mark from this activity
        """
        from .mockers import user_status_context
        from .mockers import subscribe_context, create_context
        username = 'messi'
        username_not_me = 'xavi'
        self.create_user(username)
        self.create_user(username_not_me)
        self.create_context(create_context)
        self.admin_subscribe_user_to_context(username, subscribe_context)
        self.admin_subscribe_user_to_context(username_not_me, subscribe_context)
        res = self.create_activity(username, user_status_context)
        activity_id = res.json['id']
        res = self.testapp.post('/activities/%s/favorites' % activity_id, '', oauth2Header(username_not_me), status=201)
        res = self.testapp.delete('/activities/%s/favorites/%s' % (activity_id, username_not_me), '', oauth2Header(username_not_me), status=200)
        activity = self.testapp.get('/activities/%s' % activity_id, '', oauth2Header(username), status=200)

        self.assertEqual(res.json['object']['favorites'], [])
        self.assertEqual(res.json['object']['favorited'], False)
        self.assertEqual(res.json['object']['favoritesCount'], 0)

        self.assertEqual(activity.json['favorites'], [])
        self.assertEqual(activity.json['favorited'], False)
        self.assertEqual(activity.json['favoritesCount'], 0)
开发者ID:UPCnet,项目名称:max,代码行数:29,代码来源:test_favorites.py


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