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


Python MaxTestApp.put方法代码示例

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


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

示例1: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import put [as 别名]

#.........这里部分代码省略.........

        """
        from .mockers import user_status
        from .mockers import subscribe_context, subscribe_contextA
        from .mockers import create_context, create_contextA
        from .mockers import user_status_context, user_status_contextA

        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)
        url_hash = sha1(create_context['url']).hexdigest()

        self.create_context(create_contextA, permissions=dict(read='subscribed', write='subscribed', subscribe='restricted', invite='restricted'))
        self.admin_subscribe_user_to_context(username, subscribe_contextA)
        url_hashA = sha1(create_contextA['url']).hexdigest()

        self.create_activity(username, user_status_context)
        self.create_activity(username, user_status_contextA)
        self.create_activity(username, user_status)

        res = self.testapp.get('/contexts/%s/activities' % url_hash, {}, oauth2Header(test_manager), status=200)
        result = json.loads(res.text)
        self.assertEqual(len(result), 2)

        res = self.testapp.get('/contexts/%s/activities' % url_hashA, {}, oauth2Header(test_manager), status=200)
        result = json.loads(res.text)
        self.assertEqual(len(result), 1)

    # def test_admin_post_activity_with_unauthorized_context_type_as_actor(self):
    #     from .mockers import create_unauthorized_context
    #     from hashlib import sha1

    #     result = self.create_context(create_invalid_context, expect=201)
        # url_hash = sha1(create_invalid_context['object']['url']).hexdigest()
        # res = self.testapp.post('/contexts/%s/activities' % url_hash, json.dumps(user_status_context), oauth2Header(test_manager))
        # result = json.loads(res.text)
        # self.assertEqual(result.get('actor', None).get('hash', None), url_hash)
        # self.assertEqual(result.get('object', None).get('objectType', None), 'note')
        # self.assertEqual(result.get('contexts', None)[0], subscribe_context['object'])

    def test_get_users_twitter_enabled(self):
        """ Doctest .. http:get:: /people """
        username = 'messi'
        username2 = 'xavi'
        self.create_user(username)
        self.create_user(username2)
        self.modify_user(username, {"twitterUsername": "messipowah"})
        res = self.testapp.get('/people', {"twitter_enabled": True}, oauth2Header(test_manager), status=200)

        self.assertEqual(len(res.json), 1)
        self.assertIn('twitterUsername', res.json[0])

    def test_get_context_twitter_enabled(self):
        from .mockers import create_context, create_contextA
        self.create_context(create_context)
        self.create_context(create_contextA)
        self.modify_context(create_context['url'], {"twitterHashtag": "assignatura1", "twitterUsername": "maxupcnet"})

        res = self.testapp.get('/contexts', {"twitter_enabled": True}, oauth2Header(test_manager), status=200)

        self.assertEqual(len(res.json), 1)

    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,代码行数:104,代码来源:test_admin.py

示例2: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import put [as 别名]
class FunctionalTests(unittest.TestCase, MaxTestBase):

    def setUp(self):
        conf_dir = os.path.dirname(__file__)
        self.app = loadapp('config:tests.ini', relative_to=conf_dir)
        self.reset_database(self.app)
        self.app.registry.max_store.security.insert(test_default_security)
        self.patched_post = patch('requests.post', new=partial(mock_post, self))
        self.patched_post.start()
        self.testapp = MaxTestApp(self)

        self.create_user(test_manager)
    # BEGIN TESTS

    def test_invalid_token(self):
        username = 'messi'
        res = self.testapp.post('/people/%s' % username, json.dumps({}), oauth2Header(test_manager, token='bad token'), status=401)
        self.assertEqual(res.json['error_description'], 'Invalid token.')

    def test_invalid_token_TEMPORARY(self):
        from hashlib import sha1
        from .mockers import create_context

        mindundi = 'messi'
        self.create_user(mindundi)
        self.create_context(create_context, owner=mindundi)
        url_hash = sha1(create_context['url']).hexdigest()
        res = self.testapp.put('/contexts/%s' % url_hash, json.dumps({"twitterHashtag": "assignatura1"}), oauth2Header(mindundi, token='bad token'), status=401)
        self.assertEqual(res.json['error_description'], 'Invalid token.')

    def test_invalid_scope(self):
        username = 'messi'
        headers = oauth2Header(test_manager)
        headers['X-Oauth-Scope'] = 'Invalid scope'
        res = self.testapp.post('/people/%s' % username, "", headers, status=401)
        self.assertEqual(res.json['error_description'], 'The specified scope is not allowed for this resource.')

    def test_invalid_scope_TEMPORARY(self):
        from hashlib import sha1
        from .mockers import create_context

        mindundi = 'messi'
        headers = oauth2Header(test_manager)
        headers['X-Oauth-Scope'] = 'Invalid scope'
        self.create_user(mindundi)
        self.create_context(create_context, owner=mindundi)
        url_hash = sha1(create_context['url']).hexdigest()
        res = self.testapp.put('/contexts/%s' % url_hash, json.dumps({"twitterHashtag": "assignatura1"}), headers, status=401)
        self.assertEqual(res.json['error_description'], 'The specified scope is not allowed for this resource.')

    def test_required_user_not_found(self):
        from hashlib import sha1
        from .mockers import create_context

        mindundi = 'messi'
        self.create_context(create_context, owner=mindundi)
        url_hash = sha1(create_context['url']).hexdigest()
        res = self.testapp.put('/contexts/%s' % url_hash, json.dumps({"twitterHashtag": "assignatura1"}), oauth2Header(mindundi), status=400)
        self.assertEqual(res.json['error_description'], 'Unknown actor identified by: messi')

    def test_post_activity_no_auth_headers(self):
        from .mockers import user_status
        username = 'messi'
        self.create_user(username)
        res = self.testapp.post('/people/%s/activities' % username, json.dumps(user_status), status=401)
        result = json.loads(res.text)
        self.assertEqual(result.get('error', None), 'Unauthorized')
开发者ID:UPCnet,项目名称:max,代码行数:69,代码来源:test_auth.py

示例3: PeopleACLTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import put [as 别名]

#.........这里部分代码省略.........
    def test_get_all_people_as_manager(self):
        """
            Given i'm a user that has the Manager role
            When i try to get all people
            I succeed
        """
        self.create_user(test_manager)
        self.testapp.get('/people', "", headers=oauth2Header(test_manager), status=200)

    def test_get_all_people_as_non_manager(self):
        """
            Given i'm a user that doesn't have the Manager role
            When i try to get a visible people listing
            I suceed
        """
        username = 'sheldon'

        self.create_user(test_manager)
        self.create_user(username)
        self.testapp.get('/people', "", headers=oauth2Header(username), status=200)

    # Modify user tests

    def test_modify_person_as_manager(self):
        """
            Given i'm a user that has the Manager role
            When i try to modify a user profile
            I succeed
        """
        username = 'sheldon'

        self.create_user(test_manager)
        self.create_user(username)
        self.testapp.put('/people/{}'.format(username), "", headers=oauth2Header(test_manager), status=200)

    def test_modify_person_as_non_manager_neither_owner(self):
        """
            Given i'm a user that doesn't have the Manager role
            When i try to modify a user profile
            And that person is not me
            I get a Forbidden Exception
        """
        username = 'sheldon'
        other = 'penny'

        self.create_user(test_manager)
        self.create_user(username)
        self.create_user(other)
        self.testapp.put('/people/{}'.format(other), "", headers=oauth2Header(username), status=403)

    def test_modify_person_as_owner(self):
        """
            Given i'm a user that doesn't have the Manager role
            When i try to modify my own profile
            I succeed
        """
        username = 'sheldon'

        self.create_user(test_manager)
        self.create_user(username)
        self.testapp.put('/people/{}'.format(username), "", headers=oauth2Header(username), status=200)

    # Delete user tests

    def test_delete_person_as_manager(self):
        """
开发者ID:UPCnet,项目名称:max,代码行数:70,代码来源:test_people_acls.py

示例4: ContextACLTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import put [as 别名]

#.........这里部分代码省略.........
        from max.tests.mockers import create_context

        self.create_user(test_manager)
        self.create_context(create_context)
        self.testapp.get('/contexts', "", oauth2Header(test_manager), status=200)

    def test_get_all_contexts_as_non_manager(self):
        """
            Given a user that doesn't have the Manager role
            When i try to get all contexts
            I get a Forbidden exception
        """
        from max.tests.mockers import create_context
        username = 'sheldon'

        self.create_user(test_manager)
        self.create_user(username)
        self.create_context(create_context)
        self.testapp.get('/contexts', "", oauth2Header(username), status=403)

    # Modify context tests

    def test_modify_context_as_manager(self):
        """
            Given i'm a user that has the Manager role
            When i try to update any context
            I succeed
        """

        from max.tests.mockers import create_context
        self.create_user(test_manager)
        res = self.create_context(create_context)
        chash = res.json['hash']
        self.testapp.put('/contexts/%s' % chash, json.dumps({"twitterHashtag": "testhashtag"}), oauth2Header(test_manager), status=200)

    def test_modify_context_as_manager_non_owner(self):
        """
            Given i'm a user that has the Manager role
            And i'm not the owner of the context
            When i try to update any context
            I succeed
        """

        from max.tests.mockers import create_context
        self.create_user(test_manager)
        self.create_user(test_manager2)
        res = self.create_context(create_context)
        chash = res.json['hash']
        self.testapp.put('/contexts/%s' % chash, json.dumps({"twitterHashtag": "testhashtag"}), oauth2Header(test_manager2), status=200)

    def test_modify_context_as_owner(self):
        """
            Given i'm a user that don't jave the Manager role
            And is the owner of the context
            When i try to update the context
            I succeed
        """
        from max.tests.mockers import create_context
        username = 'sheldon'

        self.create_user(test_manager)
        self.create_user(username)
        res = self.create_context(create_context, owner=username)
        chash = res.json['hash']
        self.testapp.put('/contexts/%s' % chash, json.dumps({"twitterHashtag": "testhashtag"}), oauth2Header(username), status=200)
开发者ID:UPCnet,项目名称:max,代码行数:69,代码来源:test_contexts_acls.py

示例5: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import put [as 别名]

#.........这里部分代码省略.........

    def test_context_exists(self):
        """ doctest .. http:get:: /contexts/{hash} """
        from hashlib import sha1
        from .mockers import create_context
        url_hash = sha1(create_context['url']).hexdigest()
        self.create_context(create_context)
        res = self.testapp.get('/contexts/%s' % url_hash, "", oauth2Header(test_manager), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get('hash', None), url_hash)

    def test_context_informs_all_permissions(self):
        """ doctest .. http:get:: /contexts/{hash} """
        from hashlib import sha1
        from .mockers import create_context
        from max import DEFAULT_CONTEXT_PERMISSIONS
        url_hash = sha1(create_context['url']).hexdigest()
        self.create_context(create_context)
        res = self.testapp.get('/contexts/%s' % url_hash, "", oauth2Header(test_manager), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get('hash', None), url_hash)
        self.assertItemsEqual(result['permissions'].keys(), DEFAULT_CONTEXT_PERMISSIONS.keys())

    def test_create_context_that_already_exists(self):
        """ doctest .. http:get:: /contexts/{hash} """
        from hashlib import sha1
        from .mockers import create_context
        url_hash = sha1(create_context['url']).hexdigest()
        self.testapp.post('/contexts', json.dumps(create_context), oauth2Header(test_manager), status=201)
        res = self.testapp.post('/contexts', json.dumps(create_context), oauth2Header(test_manager), status=200)
        self.assertEqual(res.json.get('hash', None), url_hash)

    def test_modify_context(self):
        """ doctest .. http:put:: /contexts/{hash} """
        from hashlib import sha1
        from .mockers import create_context

        self.create_context(create_context)
        url_hash = sha1(create_context['url']).hexdigest()
        res = self.testapp.put('/contexts/%s' % url_hash, json.dumps({"twitterHashtag": "assignatura1"}), oauth2Header(test_manager), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get('hash', None), url_hash)
        self.assertEqual(result.get('twitterHashtag', None), 'assignatura1')

    def test_modify_context_with_owner(self):
        """ doctest .. http:put:: /contexts/{hash} """
        from hashlib import sha1
        from .mockers import create_context

        mindundi = 'messi'
        self.create_user(mindundi)
        self.create_context(create_context, owner=mindundi)
        url_hash = sha1(create_context['url']).hexdigest()
        res = self.testapp.put('/contexts/%s' % url_hash, json.dumps({"twitterHashtag": "assignatura1"}), oauth2Header(mindundi), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get('hash', None), url_hash)
        self.assertEqual(result.get('twitterHashtag', None), 'assignatura1')

    def test_modify_context_forbidden(self):
        """ doctest .. http:put:: /contexts/{hash} """
        from hashlib import sha1
        from .mockers import create_context

        mindundi = 'messi'
        self.create_user(mindundi)
        self.create_context(create_context)
开发者ID:UPCnet,项目名称:max,代码行数:70,代码来源:test_contexts.py

示例6: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import put [as 别名]
class FunctionalTests(unittest.TestCase, MaxTestBase):

    def setUp(self):
        conf_dir = os.path.dirname(__file__)
        self.app = loadapp('config:tests.ini', relative_to=conf_dir)
        self.reset_database(self.app)
        self.app.registry.max_store.security.insert(test_default_security)
        self.patched_post = patch('requests.post', new=partial(mock_post, self))
        self.patched_post.start()
        self.testapp = MaxTestApp(self)

        self.create_user(test_manager)

    # BEGIN TESTS

    def test_add_public_context_with_valid_parameters_that_needs_formating(self):
        """
            Test formatters acting correctly by testing the extraction of the "@" and "#"
            on receiving a twitter @username and #hashtag containing extra chars (@,# and trailing/leading whitespace)
        """
        from .mockers import create_context_full

        new_context = dict(create_context_full)
        new_context['twitterUsername'] = '@%s ' % create_context_full['twitterUsername']
        new_context['twitterHashtag'] = '  #%s' % create_context_full['twitterHashtag']
        res = self.testapp.post('/contexts', json.dumps(new_context), oauth2Header(test_manager), status=201)
        result = json.loads(res.text)
        self.assertEqual(result.get('twitterUsername', None), create_context_full['twitterUsername'])
        self.assertEqual(result.get('twitterHashtag', None), create_context_full['twitterHashtag'])

    def test_modify_public_context_with_valid_parameters_that_need_formating(self):
        """
            Test validation failure on receiving a invalid twitter username
        """
        from .mockers import create_context_full
        from hashlib import sha1

        res = self.testapp.post('/contexts', json.dumps(create_context_full), oauth2Header(test_manager), status=201)
        url_hash = sha1(create_context_full['url']).hexdigest()
        res = self.testapp.put('/contexts/%s' % url_hash, json.dumps({"twitterUsername": "@maxupcnet", "twitterHashtag": "#atenea"}), oauth2Header(test_manager), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get('twitterUsername', None), 'maxupcnet')
        self.assertEqual(result.get('twitterHashtag', None), 'atenea')

    def test_add_public_context_with_bad_twitter_username(self):
        """
            Test validation failure on receiving a invalid twitter username
        """
        from .mockers import create_context_full
        bad_context = dict(create_context_full)
        bad_context['twitterUsername'] = '@@badusername'
        res = self.testapp.post('/contexts', json.dumps(bad_context), oauth2Header(test_manager), status=400)
        result = json.loads(res.text)
        self.assertEqual(result.get('error', None), 'ValidationError')

    def test_add_public_context_with_bad_hashtag(self):
        """
            Test validation failure on receiving a invalid twitter hashtag
        """

        from .mockers import create_context_full
        bad_context = dict(create_context_full)
        bad_context['twitterHashtag'] = '##badhashtag'
        res = self.testapp.post('/contexts', json.dumps(bad_context), oauth2Header(test_manager), status=400)
        result = json.loads(res.text)
        self.assertEqual(result.get('error', None), 'ValidationError')
开发者ID:UPCnet,项目名称:max,代码行数:68,代码来源:test_validations.py

示例7: SubscriptionsACLTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import put [as 别名]

#.........这里部分代码省略.........
        """
            Given i'm a user that doesn't have the Manager role
            When i try to get all subscriptions from another user
            I get a Forbidden Exception
        """
        from max.tests.mockers import create_context, subscribe_context
        username = 'sheldon'
        other = 'penny'

        self.create_user(username)
        self.create_user(other)

        self.create_context(create_context, permissions={'unsubscribe': 'restricted'}, owner=username)
        self.admin_subscribe_user_to_context(username, subscribe_context, expect=201)
        self.testapp.get('/people/{}/subscriptions'.format(username), "", headers=oauth2Header(other), status=403)

        # Test Grant subscription permissions

    def test_grant_permission_on_subscription_as_manager(self):
        """
            Given i'm a user that has the Manager role
            When i try to grant a permission on a user's suscription
            I succeed
        """
        from max.tests.mockers import create_context, subscribe_context

        url_hash = sha1(create_context['url']).hexdigest()
        username = 'sheldon'
        self.create_user(username)

        self.create_context(create_context, permissions={'read': 'subscribed'})
        self.admin_subscribe_user_to_context(username, subscribe_context, expect=201)
        permission = 'write'
        self.testapp.put('/contexts/%s/permissions/%s/%s?permanent=1' % (url_hash, username, permission), "", oauth2Header(test_manager), status=201)

    def test_grant_permission_on_subscription_as_context_owner(self):
        """
            Given i'm a user that don't have the Manager role
            And i'm the owner of the context
            When i try to grant a permission on a user's suscription
            I succeed
        """
        from max.tests.mockers import create_context, subscribe_context

        url_hash = sha1(create_context['url']).hexdigest()
        username = 'sheldon'
        other = 'penny'

        self.create_user(username)
        self.create_user(other)

        self.create_context(create_context, permissions={'read': 'subscribed'}, owner=username)
        self.admin_subscribe_user_to_context(other, subscribe_context, expect=201)
        permission = 'write'
        self.testapp.put('/contexts/%s/permissions/%s/%s?permanent=1' % (url_hash, other, permission), "", oauth2Header(username), status=201)

    def test_grant_permission_on_subscription_as_non_manager_nor_owner(self):
        """
            Given i'm a user that don't have the Manager role
            And i'm not the owner of the context
            When i try to grant a permission on a user's suscription
            I get a Forbidden Exception
        """
        from max.tests.mockers import create_context, subscribe_context

        url_hash = sha1(create_context['url']).hexdigest()
开发者ID:UPCnet,项目名称:max,代码行数:70,代码来源:test_subscriptions_acls.py

示例8: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import put [as 别名]

#.........这里部分代码省略.........
        self.assertEqual(result.get("username", None), "messi")

    def test_get_users_by_query_on_username(self):
        """ Doctest .. http:get:: /people """
        username = "messi"
        self.create_user(username)
        res = self.testapp.get("/people", json.dumps({"username": username}), oauth2Header(username), status=200)
        result = json.loads(res.text)

        self.assertEqual(len(result), 1)
        self.assertEqual(result[0].get("username", ""), username)
        self.assertEqual(len(result[0].keys()), 4)  # Check how many fields each result has

    def test_get_users_by_query_on_displayName(self):
        """ Doctest .. http:get:: /people """
        username = "messi"
        self.create_user(username, displayName="Lionel Messi")
        res = self.testapp.get("/people", json.dumps({"username": "lionel"}), oauth2Header(username), status=200)
        result = json.loads(res.text)

        self.assertEqual(len(result), 1)
        self.assertEqual(result[0].get("username", ""), username)
        self.assertEqual(len(result[0].keys()), 4)  # Check how many fields each result has

    def test_get_non_existent_user(self):
        username = "messi"
        res = self.testapp.get("/people/%s" % username, "", oauth2Header(username), status=400)
        result = json.loads(res.text)
        self.assertEqual(result.get("error", None), "UnknownUserError")

    def test_modify_user_one_parameter(self):
        username = "messi"
        self.create_user(username)
        res = self.testapp.put(
            "/people/%s" % username, json.dumps({"displayName": "Lionel Messi"}), oauth2Header(username)
        )
        result = json.loads(res.text)
        self.assertEqual(result.get("displayName", None), "Lionel Messi")

    def test_modify_user_several_parameters(self):
        """ Doctest .. http:put:: /people/{username} """
        username = "messi"
        self.create_user(username)
        res = self.testapp.put(
            "/people/%s" % username,
            json.dumps({"displayName": "Lionel Messi", "twitterUsername": "leomessi"}),
            oauth2Header(username),
        )
        result = json.loads(res.text)
        self.assertEqual(result.get("displayName", None), "Lionel Messi")
        self.assertEqual(result.get("twitterUsername", None), "leomessi")

    def test_modify_user_several_parameters_twice(self):
        username = "messi"
        self.create_user(username)
        self.modify_user(username, {"displayName": "Lionel Messi"})
        res = self.testapp.put(
            "/people/%s" % username, json.dumps({"twitterUsername": "leomessi"}), oauth2Header(username)
        )
        result = json.loads(res.text)
        self.assertEqual(result.get("displayName", None), "Lionel Messi")
        self.assertEqual(result.get("twitterUsername", None), "leomessi")

    def test_modify_non_existent_user(self):
        username = "messi"
        res = self.testapp.put(
开发者ID:UPCnet,项目名称:max,代码行数:70,代码来源:test_people.py

示例9: ConversationsACLTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import put [as 别名]

#.........这里部分代码省略.........
        """
            Given i'm a regular user
            And i'm a regular conversation participant
            When I try to list all conversations
            Then I succeed
        """
        from max.tests.mockers import message
        sender = 'messi'
        recipient = 'xavi'
        self.create_user(sender)
        self.create_user(recipient)

        self.testapp.post('/conversations', json.dumps(message), oauth2Header(sender), status=201)

        self.testapp.get('/conversations', '', oauth2Header(sender), status=200)

    # Modify conversation tests

    def test_modify_conversation_as_manager(self):
        """
            Given i'm a Manager
            When I try to modify a conversation
            Then I succeed
        """
        from max.tests.mockers import message
        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 = str(res.json['contexts'][0]['id'])

        self.testapp.put('/conversations/{}'.format(cid), '{"displayName": "Nou nom"}', oauth2Header(test_manager), status=200)

    def test_modify_conversation_as_owner(self):
        """
            Given i'm a regular user
            And i'm the owner of the conversation
            When I try to modify a conversation
            Then I succeed
        """
        from max.tests.mockers import message
        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 = str(res.json['contexts'][0]['id'])

        self.testapp.put('/conversations/{}'.format(cid), '{"displayName": "Nou nom"}', oauth2Header(sender), status=200)

    def test_modify_conversation_as_participant(self):
        """
            Given i'm a regular user
            And i'm a regular conversation participant
            When I try to modify a conversation
            Then I get a Forbidden Exception
        """
        from max.tests.mockers import message
        sender = 'messi'
        recipient = 'xavi'
        self.create_user(sender)
        self.create_user(recipient)
开发者ID:UPCnet,项目名称:max,代码行数:69,代码来源:test_conversations_acls.py

示例10: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import put [as 别名]

#.........这里部分代码省略.........

        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)
        url_hash = sha1(create_context["url"]).hexdigest()
        self.admin_unsubscribe_user_from_context(username, url_hash, expect=204)
        res = self.testapp.get("/people/%s/subscriptions" % username, {}, oauth2Header(username), status=200)
        result = json.loads(res.text)
        self.assertEqual(len(result), 0)

    def test_change_context_with_same_permissions(self):
        """
            Create a public context, user subscribes to context.
            Try to update the context with the same permissions.
            Permissions  remain the same

            NOTE: Test added to catch a bug where modifying a context with the same
            permissions would crash on a mongodb empty query
        """
        from .mockers import create_context
        from .mockers import subscribe_context

        url_hash = sha1(create_context["url"]).hexdigest()
        username = "messi"
        self.create_user(username)
        permissions = dict(read="subscribed", write="subscribed", subscribe="public", invite="restricted")
        self.create_context(create_context, permissions=permissions)
        self.user_subscribe_user_to_context(username, subscribe_context, expect=201)
        data = json.dumps({"permissions": permissions})
        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")
        self.assertEqual(res.json["permissions"]["subscribe"], "public")
        self.assertEqual(res.json["permissions"]["invite"], "restricted")

    def test_change_public_context_to_restricted(self):
        """
            Create a public context, user subscribes to context.
            Change the context to write=restricted, and user fails to write in the context.
        """
        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)
        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=403)

    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
开发者ID:UPCnet,项目名称:max,代码行数:70,代码来源:test_subscriptions.py


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