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


Python MaxTestApp.delete方法代码示例

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


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

示例1: SecurityACLTests

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

    def setUp(self):
        conf_dir = os.path.dirname(os.path.dirname(__file__))

        self.app = loadapp('config:tests.ini', relative_to=conf_dir)
        self.app.registry.max_store.drop_collection('users')
        self.app.registry.max_store.drop_collection('activity')
        self.app.registry.max_store.drop_collection('contexts')
        self.app.registry.max_store.drop_collection('security')
        self.app.registry.max_store.drop_collection('conversations')
        self.app.registry.max_store.drop_collection('messages')
        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)

    def test_forbidden_access_to_security_settings(self):
        """
            Given i'm a regular user
            When i try to interact with security endpoints
            Then i get a Forbidden Exception
        """
        username = 'sheldon'

        self.testapp.get('/admin/security', headers=oauth2Header(username), status=403)
        self.testapp.get('/admin/security/users', headers=oauth2Header(username), status=403)
        self.testapp.get('/admin/security/roles/Manager/users/test_manager', headers=oauth2Header(username), status=403)
        self.testapp.post('/admin/security/roles/Manager/users/test_manager', headers=oauth2Header(username), status=403)
        self.testapp.delete('/admin/security/roles/Manager/users/test_manager', headers=oauth2Header(username), status=403)

    def test_access_to_security_settings(self):
        """
            Given i'm a Manager user
            When i try to interact with security endpoints
            Then i suceed
        """
        self.testapp.get('/admin/security', headers=oauth2Header(test_manager), status=200)
        self.testapp.get('/admin/security/users', headers=oauth2Header(test_manager), status=200)
        self.testapp.get('/admin/security/roles/Manager/users/test_manager', headers=oauth2Header(test_manager), status=200)
        self.testapp.post('/admin/security/roles/Manager/users/test_manager', headers=oauth2Header(test_manager), status=200)
        self.testapp.delete('/admin/security/roles/Manager/users/test_manager', headers=oauth2Header(test_manager), status=204)
开发者ID:UPCnet,项目名称:max,代码行数:46,代码来源:test_security_acls.py

示例2: DeprecationTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import delete [as 别名]
class DeprecationTests(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)

    # Test deprecated Add people

    def test_deprecated_request_create_user(self):
        """
            Given a request to the deprecated POST /people/{username}
            When the request is processed
            Then the request is rewrited as POST /people
            And the username is now in the body
            And the displayName is preserved in the body
        """
        res = self.testapp.post('/people/sheldon', json.dumps({"displayName": 'Sheldon'}), headers=oauth2Header(test_manager), status=201)

        rewrited_request = res.request
        rewrited_request_url = urlparse.urlparse(rewrited_request.url).path

        self.assertEqual(rewrited_request_url, '/people')
        self.assertEqual(res.json['username'], 'sheldon')
        self.assertEqual(res.json['displayName'], 'Sheldon')

    # Test deprecated subscribe user

    def test_deprecated_subscribe_user(self):
        """
            Given a request to the deprecated POST /people/{username}/subscriptions
            When the request is processed
            Then the request is rewrited as POST /contexts/{hash}/subscriptions
            And the actor now is in the body
        """
        from max.tests.mockers import create_context, subscribe_context
        username = 'sheldon'

        self.create_user(username)
        res = self.create_context(create_context)
        context_hash = res.json['hash']

        res = self.testapp.post('/people/%s/subscriptions' % username, json.dumps(subscribe_context), oauth2Header(test_manager), status=201)

        rewrited_request = res.request
        rewrited_request_url = urlparse.urlparse(rewrited_request.url).path

        self.assertEqual(rewrited_request_url, '/contexts/{}/subscriptions'.format(context_hash))
        self.assertEqual(res.json['actor']['username'], 'sheldon')
        self.assertEqual(res.json['actor']['objectType'], 'person')

    # Test deprecated unsubscribe user

    def test_deprecated_unsubscribe_user(self):
        """
            Given a request to the deprecated DELETE /people/{username}/subscriptions
            When the request is processed
            Then the request is rewrited as DELETE /contexts/{hash}/subscriptions
            And the actor now is in the body
        """
        from max.tests.mockers import create_context, subscribe_context
        username = 'sheldon'

        self.create_user(username)
        res = self.create_context(create_context)
        context_hash = res.json['hash']

        self.admin_subscribe_user_to_context(username, subscribe_context)
        res = self.testapp.delete('/people/%s/subscriptions/%s' % (username, context_hash), "", oauth2Header(test_manager), status=204)

        rewrited_request = res.request
        rewrited_request_url = urlparse.urlparse(rewrited_request.url).path

        self.assertEqual(rewrited_request_url, '/contexts/{}/subscriptions/{}'.format(context_hash, username))

    # Test deprecated create context activity

    def test_deprecated_user_post_activity_to_context(self):
        """
            Given a request to the deprecated POST /people/{username}/activities
            And the request has a "contexts" parameter
            When the request is processed
            Then the request is rewrited as POST /contexts/{hash}/activities
            And the actor is in the body
            and object is preserved in the body
        """
        from max.tests.mockers import create_context, subscribe_context
        from max.tests.mockers import user_status_context as activity

        username = 'sheldon'

        self.create_user(username)
        res = self.create_context(create_context)
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_deprecations.py

示例3: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import delete [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_get_activities_order_sorted_by_last_comment_publish_date(self):
        """
            Given a plain user
            When I post activities on a context
            and I comment on an old activity
            Then in the comment-sorted activities, the commented activity becomes the first
        """
        from .mockers import user_comment
        from .mockers import user_status_context
        from .mockers import subscribe_context, create_context
        from .mockers import context_query

        username = 'messi'
        self.create_user(username)
        self.create_context(create_context)
        self.admin_subscribe_user_to_context(username, subscribe_context)
        activity_0_id = self.create_activity(username, user_status_context).json['id']
        activity_1_id = self.create_activity(username, user_status_context, note='Second').json['id']
        activity_2_id = self.create_activity(username, user_status_context, note='Third').json['id']
        res = self.testapp.post('/activities/%s/comments' % str(activity_1_id), json.dumps(user_comment), oauth2Header(username), status=201)

        res = self.testapp.get('/contexts/%s/activities?sort=published' % (context_query['context']), '', oauth2Header(username), status=200)

        self.assertEqual(len(res.json), 3)
        self.assertEqual(res.json[0].get('id', None), activity_2_id)
        self.assertEqual(res.json[1].get('id', None), activity_1_id)
        self.assertEqual(res.json[2].get('id', None), activity_0_id)

    def test_timeline_order_sorted_by_last_comment_publish_date(self):
        """
            Given a plain user
            When I post activities
            and I comment on an old activity
            Then in the comment-sorted timeline, the commented activity becomes the first
        """
        from .mockers import user_status, user_comment
        username = 'messi'
        self.create_user(username)
        activity_ids = []
        # Create 7 activities to overpass limit of 5
        for i in range(7):
            activity_ids.append(self.create_activity(username, user_status, note=str(i)).json['id'])
        res = self.testapp.post('/activities/%s/comments' % str(activity_ids[0]), json.dumps(user_comment), oauth2Header(username), status=201)
        # Get first 5 results
        res = self.testapp.get('/people/%s/timeline?sort=published&priority=comments&limit=5' % username, "", oauth2Header(username), status=200)
        self.assertEqual(len(res.json), 5)

        self.assertEqual(res.json[0].get('id', None), activity_ids[0])
        self.assertEqual(res.json[1].get('id', None), activity_ids[6])
        self.assertEqual(res.json[2].get('id', None), activity_ids[5])
        self.assertEqual(res.json[3].get('id', None), activity_ids[4])
        self.assertEqual(res.json[4].get('id', None), activity_ids[3])

        # get next 2 results
        res = self.testapp.get('/people/%s/timeline?sort=published&priority=comments&limit=5&before=%s' % (username, activity_ids[3]), "", oauth2Header(username), status=200)
        self.assertEqual(len(res.json), 2)

        self.assertEqual(res.json[0].get('id', None), activity_ids[2])
        self.assertEqual(res.json[1].get('id', None), activity_ids[1])

    def test_timeline_order_sorted_by_last_comment_publish_date_when_delete_comment(self):
        """
            Given a plain user
            When I post activities
            and I comment on an old activity
            and I delete comment on an old activity
            Then in the comment-sorted timeline
        """
        from .mockers import user_status, user_comment
        username = 'messi'
        self.create_user(username)
        activity_ids = []
        # Create 7 activities to overpass limit of 5
        for i in range(7):
            activity_ids.append(self.create_activity(username, user_status, note=str(i)).json['id'])
        res = self.testapp.post('/activities/%s/comments' % str(activity_ids[0]), json.dumps(user_comment), oauth2Header(username), status=201)
        comment_id = res.json['id']

        # Delete comment
        res = self.testapp.delete('/activities/%s/comments/%s' % (str(activity_ids[0]), comment_id), '', oauth2Header(username), status=204)

        # Get first 5 results
        res = self.testapp.get('/people/%s/timeline?sort=published&priority=comments&limit=5' % username, "", oauth2Header(username), status=200)
        self.assertEqual(len(res.json), 5)
        self.assertEqual(res.json[0].get('id', None), activity_ids[6])
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_sorting.py

示例4: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import delete [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_has_remaining_items(self):
        """
            Given there are more than 10 users
            When i query 10 users
            I get a X-Has-Remaining-Items header
        """
        # Create 9 users +  1 already existing (test_manager)
        for i in range(10):
            self.create_user('user-{}'.format(i))

        res = self.testapp.get('/people', headers=oauth2Header(test_manager), status=200)
        self.assertEqual(len(res.json), 10)
        self.assertEqual(res.headers['X-Has-Remaining-Items'], '1')

    def test_not_has_remaining_items_wihout_limit(self):
        """
            Given there are more than 10 users
            When i query unlimited users
            I don't get a X-Has-Remaining-Items header
        """
        # Create 9 users +  1 already existing (test_manager)
        for i in range(10):
            self.create_user('user-{}'.format(i))

        res = self.testapp.get('/people?limit=0', headers=oauth2Header(test_manager), status=200)
        self.assertEqual(len(res.json), 11)
        self.assertNotIn('X-Has-Remaining-Items', res.headers)

    def test_not_has_remaining_items(self):
        """
            Given there are exactly 10 users
            When i query 10 users
            I don't get a X-Has-Remaining-Items header
        """
        # Create 9 users +  1 already existing (test_manager)
        for i in range(9):
            self.create_user('user-{}'.format(i))

        res = self.testapp.get('/people', headers=oauth2Header(test_manager), status=200)
        self.assertEqual(len(res.json), 10)
        self.assertNotIn('X-Has-Remaining-Items', res.headers)

    def test_activities_keyword_generation(self):
        """
                Tests that all words passing regex are included in keywords
                Tests that username that creates the activity is included in keywords
                Tests that displayName of user that creates the activity is included in keywords
                Tests that username that creates the comment is included in keywords
                Tests that displayName of user that creates the comment is included in keywords
                Tests that a keyword of a comment is included in keywords
        """
        from .mockers import create_context
        from .mockers import subscribe_context, user_status_context, user_comment

        username = 'messi'
        username2 = 'xavi'
        self.create_user(username, displayName="Lionel Messi")
        self.create_user(username2, displayName="Xavi Hernandez")
        self.create_context(create_context, permissions=dict(read='public', write='subscribed', subscribe='restricted', invite='restricted'))
        self.admin_subscribe_user_to_context(username, subscribe_context)
        self.admin_subscribe_user_to_context(username2, subscribe_context)
        activity = self.create_activity(username, user_status_context).json
        res = self.testapp.post('/activities/%s/comments' % str(activity['id']), json.dumps(user_comment), oauth2Header(username2), status=201)
        res = self.testapp.get('/activities/%s' % str(activity['id']), json.dumps({}), oauth2Header(username), status=200)
        expected_keywords = [u'activitat', u'canvi', u'comentari', u'creaci\xf3', u'estatus', u'hernandez', u'lionel', u'messi', u'nou', u'testejant', u'una', u'xavi']
        response_keywords = res.json['keywords']
        response_keywords.sort()
        self.assertListEqual(response_keywords, expected_keywords)

    def test_activities_keyword_generation_after_comment_delete(self):
        """
            test that the keywords supplied by a comment disappers from activity when deleting the comment
        """
        from .mockers import create_context
        from .mockers import subscribe_context, user_status_context, user_comment

        username = 'messi'
        username2 = 'xavi'
        self.create_user(username, displayName="Lionel Messi")
        self.create_user(username2, displayName="Xavi Hernandez")
        self.create_context(create_context, permissions=dict(read='public', write='subscribed', subscribe='restricted', invite='restricted'))
        self.admin_subscribe_user_to_context(username, subscribe_context)
        self.admin_subscribe_user_to_context(username2, subscribe_context)
        activity = self.create_activity(username, user_status_context).json
        res = self.testapp.post('/activities/%s/comments' % str(activity['id']), json.dumps(user_comment), oauth2Header(username2), status=201)
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_search.py

示例5: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import delete [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_favorite_activity(self):
        """
           Given a plain user
           and a regular context
           When i post an activity in a context
           Then someone else can favorite 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)
        activity = self.testapp.get('/activities/%s' % activity_id, '', oauth2Header(username), status=200)

        self.assertEqual(res.json['object']['favorites'][0]['username'], username_not_me)
        self.assertEqual(res.json['object']['favorited'], True)
        self.assertEqual(res.json['object']['favoritesCount'], 1)

        self.assertEqual(activity.json['favorites'][0]['username'], username_not_me)
        self.assertEqual(activity.json['favorited'], False)
        self.assertEqual(activity.json['favoritesCount'], 1)

    def test_favorite_already_favorited_activity(self):
        """
           Given a plain user
           and a regular context
           When i post an activity in a context
           And someone favorites this activity
           Then this someone else can't favorite twice 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.post('/activities/%s/favorites' % activity_id, '', oauth2Header(username_not_me), status=200)

        self.assertEqual(res.json['object']['favorites'][0]['username'], username_not_me)
        self.assertEqual(res.json['object']['favorited'], True)
        self.assertEqual(res.json['object']['favoritesCount'], 1)

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

示例6: FunctionalTests

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

#.........这里部分代码省略.........
        """
        from .mockers import create_context, create_contextA

        username = "messi"
        self.create_user(username)
        self.create_context(
            create_context,
            permissions=dict(read="subscribed", write="subscribed", subscribe="public", invite="restricted"),
        )
        self.create_context(
            create_contextA,
            permissions=dict(read="subscribed", write="subscribed", subscribe="restricted", invite="restricted"),
        )
        res = self.testapp.get("/contexts/public", {}, oauth2Header(username), status=200)
        result = json.loads(res.text)
        self.assertEqual(len(result), 1)

    def test_unsubscribe_from_inexistent_subscription_as_plain_user(self):
        """
            Given a plain user
            When I try to unsubscribe from a context
            And I'm not subscribed to that context
            Then I get a not found error
        """
        from .mockers import create_context

        username = "messi"
        self.create_user(username)
        self.create_context(
            create_context,
            permissions=dict(read="subscribed", write="subscribed", subscribe="public", invite="restricted"),
        )
        url_hash = sha1(create_context["url"]).hexdigest()
        self.testapp.delete(
            "/people/%s/subscriptions/%s" % (username, url_hash), {}, oauth2Header(username), status=403
        )

    def test_unsubscribe_from_inexistent_subscription_as_admin(self):
        """
            As an admin user
            When I try to unsubscribe a user from a context
            And the user is not subscribed to that context
            Then I get a not found error
        """
        from .mockers import create_context

        username = "messi"
        self.create_user(username)
        self.create_context(
            create_context,
            permissions=dict(read="subscribed", write="subscribed", subscribe="public", invite="restricted"),
        )
        url_hash = sha1(create_context["url"]).hexdigest()
        self.testapp.delete(
            "/people/%s/subscriptions/%s" % (username, url_hash), {}, oauth2Header(test_manager), status=404
        )

    def test_unsubscribe_from_restricted_context_as_plain_user(self):
        """
            Given a plain user
            When I try to unsubscribe from a restricted subscription context
            Then i get an authorization error
        """
        from .mockers import create_context
        from .mockers import subscribe_context
开发者ID:UPCnet,项目名称:max,代码行数:69,代码来源:test_subscriptions.py

示例7: PeopleACLTests

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

#.........这里部分代码省略.........
        """
            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):
        """
            Given i'm a user that has the Manager role
            When i try to delete a user
            I succeed
        """
        username = 'sheldon'

        self.create_user(test_manager)
        self.create_user(username)
        self.testapp.delete('/people/{}'.format(username), headers=oauth2Header(test_manager), status=204)

    def test_delete_person_as_non_manager_neither_owner(self):
        """
            Given i'm a user that doesn't have the Manager role
            When i try to delete a user
            I get a Forbidden Exception
        """
        username = 'sheldon'
        other = 'penny'

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

    def test_delete_person_as_owner(self):
        """
            Given i'm a user that doesn't have the Manager role
            When i try to delete myself
            I get a Forbidden Exception
        """
        username = 'sheldon'

        self.create_user(test_manager)
        self.create_user(username)
        self.testapp.delete('/people/{}'.format(username), headers=oauth2Header(username), status=403)
开发者ID:UPCnet,项目名称:max,代码行数:104,代码来源:test_people_acls.py

示例8: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import delete [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)

    def tearDown(self):
        import pyramid.testing
        pyramid.testing.tearDown()

    # BEGIN TESTS

    def test_add_device_token_ios(self):
        username = 'messi'
        token = {'platform': 'ios', 'token': '12345678901234567890123456789012'}
        self.create_user(username)
        res = self.testapp.post('/tokens', json.dumps(token), oauth2Header(username), status=201)
        result = json.loads(res.text)
        self.assertEqual(result.get('token', ''), token['token'])
        self.assertEqual(result.get('platform', ''), token['platform'])

    def test_add_device_token_android(self):
        username = 'messi'
        self.create_user(username)
        token = {'platform': 'android', 'token': '12345678901234567890123456789012klhsdflajshdfkjashdfoq'}
        res = self.testapp.post('/tokens', json.dumps(token), oauth2Header(username), status=201)
        result = json.loads(res.text)
        self.assertEqual(result.get('token', ''), token['token'])
        self.assertEqual(result.get('platform', ''), token['platform'])

    def test_add_device_invalid_platform(self):
        username = 'messi'
        token = {'platform': 'blackberry', 'token': '12345678901234567890123456789012klhsdflajshdfkjashdfoq'}
        self.create_user(username)
        self.testapp.post('/tokens', json.dumps(token), oauth2Header(username), status=400)

    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)

    def test_add_duplicated_token(self):
        """
            Given i'm a regular user

        """
        sender = 'messi'
        recipient = 'xavi'
        self.create_user(sender)
        self.create_user(recipient)

        token = {'platform': 'ios', 'token': '12345678901234567890123456789012'}

        self.testapp.post('/tokens', json.dumps(token), oauth2Header(sender), status=201)
        sender_tokens = self.testapp.get('/people/{}/tokens/platforms/{}'.format(sender, token['platform']), "", headers=oauth2Header(sender), status=200).json

        self.assertEqual(len(sender_tokens), 1)
        self.testapp.post('/tokens', json.dumps(token), oauth2Header(recipient), status=201)

        sender_tokens = self.testapp.get('/people/{}/tokens/platforms/{}'.format(sender, token['platform']), "", headers=oauth2Header(sender), status=200).json
        recipient_tokens = self.testapp.get('/people/{}/tokens/platforms/{}'.format(recipient, token['platform']), "", headers=oauth2Header(recipient), status=200).json

        self.assertEqual(len(sender_tokens), 0)
        self.assertEqual(len(recipient_tokens), 1)

    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')
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_tokens.py

示例9: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import delete [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_create_context_with_notifications(self):
        """ doctests .. http:post:: /contexts"""
        from .mockers import create_context_post_notifications as create_context
        new_context = dict(create_context)
        res = self.testapp.post('/contexts', json.dumps(new_context), oauth2Header(test_manager), status=201)
        self.assertEqual(res.json['notifications'], 'posts')

    def test_delete_context_with_notifications_removes_subscriptions(self):
        """
        """
        from .mockers import subscribe_context
        from .mockers import create_context_post_notifications as create_context
        from .mockers import user_status_context
        from hashlib import sha1

        username = 'messi'
        self.create_user(username)
        self.create_context(create_context)
        self.admin_subscribe_user_to_context(username, subscribe_context)
        self.create_activity(username, user_status_context)

        url_hash = sha1(create_context['url']).hexdigest()
        self.testapp.delete('/contexts/%s' % url_hash, "", oauth2Header(test_manager), status=204)

        res = self.testapp.get('/people/%s' % username, "", oauth2Header(username))
        result = json.loads(res.text)
        self.assertEqual(result.get('username', None), 'messi')
        self.assertEqual(len(result.get('subscribedTo', [])), 0)

        return url_hash

    def test_subscribe_user_to_context_with_notifications(self):
        """
        """
        from .mockers import create_context_post_notifications as create_context
        from .mockers import subscribe_context
        from hashlib import sha1

        username = 'messi'
        url_hash = sha1(create_context['url']).hexdigest()

        self.create_user(username)
        self.create_context(create_context, permissions=dict(read='public', write='restricted', subscribe='restricted', invite='restricted'))
        self.testapp.post('/people/%s/subscriptions' % username, json.dumps(subscribe_context), oauth2Header(test_manager), status=201)
        res = self.testapp.get('/people/%s/subscriptions' % username, json.dumps(subscribe_context), oauth2Header(username), status=200)

        self.assertEqual(res.json[0]['notifications'], 'posts')
        return url_hash, username

    def test_unsubscribe_user_from_context_with_notifications(self):
        """
        """
        from .mockers import create_context_post_notifications as create_context
        from .mockers import subscribe_context
        from hashlib import sha1

        username = 'messi'
        url_hash = sha1(create_context['url']).hexdigest()

        self.create_user(username)
        self.create_context(create_context, permissions=dict(read='public', write='restricted', subscribe='restricted', invite='restricted'))
        self.testapp.post('/people/%s/subscriptions' % username, json.dumps(subscribe_context), oauth2Header(test_manager), status=201)

        res = self.testapp.delete('/people/%s/subscriptions/%s' % (username, url_hash), {}, oauth2Header(test_manager), status=204)

        res = self.testapp.get('/people/%s/subscriptions' % username, json.dumps(subscribe_context), oauth2Header(username), status=200)

        self.assertEqual(len(res.json), 0)
        return url_hash, username

    def test_post_activity_on_context_with_notifications(self):
        """ Post an activity to a context which needs the user to be subscribed to read and write
            and we have previously subscribed the user.
        """
        from .mockers import subscribe_context
        from .mockers import create_context_post_notifications as create_context
        from .mockers import user_status_context
        from hashlib import sha1

        username = 'messi'
        url_hash = sha1(create_context['url']).hexdigest()

        self.create_user(username)
        context_permissions = dict(read='subscribed', write='subscribed', subscribe='restricted', invite='restricted')
        self.create_context(create_context, permissions=context_permissions)
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_contexts_notifications.py

示例10: ActivitiesACLTests

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

    def setUp(self):
        conf_dir = os.path.dirname(os.path.dirname(__file__))

        self.app = loadapp('config:tests.ini', relative_to=conf_dir)
        self.app.registry.max_store.drop_collection('users')
        self.app.registry.max_store.drop_collection('activity')
        self.app.registry.max_store.drop_collection('contexts')
        self.app.registry.max_store.drop_collection('security')
        self.app.registry.max_store.drop_collection('conversations')
        self.app.registry.max_store.drop_collection('messages')
        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)

    # Favorite activities tests

    def test_favorite(self):
        """
            Given i'm a regular user
            When i try to favorite an activity
            I succeed
        """
        from max.tests.mockers import user_status
        username = 'messi'
        username_not_me = 'xavi'
        self.create_user(username)
        self.create_user(username_not_me)
        res = self.create_activity(username, user_status)
        activity_id = res.json['id']
        self.testapp.post('/activities/%s/favorites' % activity_id, '', oauth2Header(username_not_me), status=201)

    def test_favorite_impersonate(self):
        """
            Given i'm a regular user
            When i try to favorite an activity impersonated as another user
            I get a Forbidden Exception
        """
        from max.tests.mockers import user_status
        username = 'messi'
        username_not_me = 'xavi'
        self.create_user(username)
        self.create_user(username_not_me)
        res = self.create_activity(username, user_status)
        activity_id = res.json['id']
        impersonated_actor = {'actor': {'objectType': 'person', 'username': username}}
        self.testapp.post('/activities/%s/favorites' % activity_id, json.dumps(impersonated_actor), oauth2Header(username_not_me), status=403)

    def test_favorite_impersonate_as_manager(self):
        """
            Given i'm a Manager user
            When i try to favorite an activity impersonated as another user
            I get a Forbidden Exception
        """
        from max.tests.mockers import user_status
        username = 'messi'
        username_not_me = 'xavi'
        self.create_user(username)
        self.create_user(username_not_me)
        res = self.create_activity(username, user_status)
        activity_id = res.json['id']
        impersonated_actor = {'actor': {'objectType': 'person', 'username': username}}
        self.testapp.post('/activities/%s/favorites' % activity_id, json.dumps(impersonated_actor), oauth2Header(test_manager), status=201)

    # Unfavorite activities tests

    def test_unfavorite(self):
        """
            Given i'm a regular user
            When i try to unfavorite an activity
            I succeed
        """
        from max.tests.mockers import user_status
        username = 'messi'
        username_not_me = 'xavi'
        self.create_user(username)
        self.create_user(username_not_me)
        res = self.create_activity(username, user_status)
        activity_id = res.json['id']
        self.testapp.post('/activities/%s/favorites' % activity_id, '', oauth2Header(username_not_me), status=201)
        self.testapp.delete('/activities/%s/favorites/%s' % (activity_id, username_not_me), '', oauth2Header(username_not_me), status=200)

    def test_unfavorite_impersonate(self):
        """
            Given i'm a regular user
            When i try to unfavorite an activity imperonsated as another user
            I get a Forbidden Exception
        """
        from max.tests.mockers import user_status
        username = 'messi'
        username_not_me = 'xavi'
        self.create_user(username)
        self.create_user(username_not_me)
        res = self.create_activity(username, user_status)
        activity_id = res.json['id']
        self.testapp.post('/activities/%s/favorites' % activity_id, '', oauth2Header(username_not_me), status=201)
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_favorites_acls.py

示例11: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import delete [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_like_activity(self):
        """
           Given a plain user
           and a regular context
           When i post an activity in a context
           Then someone else can like 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/likes' % activity_id, '', oauth2Header(username_not_me), status=201)
        activity = self.testapp.get('/activities/%s' % activity_id, '', oauth2Header(username), status=200)

        self.assertEqual(res.json['object']['likes'][0]['username'], username_not_me)
        self.assertEqual(res.json['object']['liked'], True)
        self.assertEqual(res.json['object']['likesCount'], 1)

        self.assertEqual(activity.json['likes'][0]['username'], username_not_me)
        self.assertEqual(activity.json['liked'], False)
        self.assertEqual(activity.json['likesCount'], 1)

    def test_like_already_liked_activity(self):
        """
           Given a plain user
           and a regular context
           When i post an activity in a context
           And someone likes this activity
           Then this someone else can't like twice 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/likes' % activity_id, '', oauth2Header(username_not_me), status=201)
        res = self.testapp.post('/activities/%s/likes' % activity_id, '', oauth2Header(username_not_me), status=200)

        self.assertEqual(res.json['object']['likes'][0]['username'], username_not_me)
        self.assertEqual(res.json['object']['liked'], True)
        self.assertEqual(res.json['object']['likesCount'], 1)

    def test_unlike_activity(self):
        """
           Given a plain user
           and a regular context
           When i post an activity in a context
           Then i can remove previously like 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']
        self.testapp.post('/activities/%s/likes' % activity_id, '', oauth2Header(username_not_me), status=201)
        self.testapp.delete('/activities/%s/likes/%s' % (activity_id, username_not_me), '', oauth2Header(username_not_me), status=204)
        activity = self.testapp.get('/activities/%s' % activity_id, '', oauth2Header(username), status=200)

        self.assertEqual(activity.json['likes'], [])
        self.assertEqual(activity.json['liked'], False)
        self.assertEqual(activity.json['likesCount'], 0)

    def test_like_activity_by_various(self):
        """
           Given a plain user
           and a regular context
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_likes.py

示例12: ConversationsACLTests

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

#.........这里部分代码省略.........
        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(recipient), status=403)

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

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

    # Delete conversation tests

    def test_delete_conversation_as_manager(self):
        """
            Given i'm a Manager
            When I try to delete 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.delete('/conversations/{}'.format(cid), '', oauth2Header(test_manager), status=204)

    def test_delete_conversation_as_owner(self):
        """
            Given i'm a regular user
            And i'm the owner of the conversation
            When I try to delete 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'])
开发者ID:UPCnet,项目名称:max,代码行数:69,代码来源:test_conversations_acls.py

示例13: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import delete [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_create_activity_with_published_date(self):
        """ doctest .. http:post:: /people/{username}/activities """
        from .mockers import user_status as activity

        old_activity = deepcopy(activity)
        old_activity['published'] = '2010-01-01T00:01:30.000Z'
        username = 'messi'
        self.create_user(username)
        res = self.testapp.post('/people/%s/activities' % username, json.dumps(old_activity), oauth2Header(username), status=201)
        self.assertEqual(res.json['published'], '2010-01-01T00:01:30Z')

    def test_create_activity_with_invalid_json(self):
        """ doctest .. http:post:: /people/{username}/activities """
        from .mockers import user_status as activity
        username = 'messi'
        self.create_user(username)
        self.testapp.post('/people/%s/activities' % username, json.dumps(activity)[:-10], oauth2Header(username), status=400)

    def test_create_activity_check_ownership(self):
        """
            Given a plain user
            When I post an activity
            And I am authenticated as myself
            Then the actor,the creator and the owner must be the same
        """
        from .mockers import user_status as activity
        username = 'messi'
        self.create_user(username)
        res = self.testapp.post('/people/%s/activities' % username, json.dumps(activity), oauth2Header(username), status=201)
        self.assertEqual(res.json['actor']['username'], res.json['creator'])
        self.assertEqual(res.json['owner'], res.json['creator'])

    def test_get_deletable_mark_for_own_activity(self):
        """
           Given a plain user
           When i post an activity
           Then i have the permission to delete it
        """
        from .mockers import user_status as activity
        username = 'messi'
        self.create_user(username)
        res = self.testapp.post('/people/%s/activities' % username, json.dumps(activity), oauth2Header(username), status=201)
        res = self.testapp.get('/activities/%s' % res.json['id'], '', oauth2Header(username), status=200)
        self.assertEqual(res.json['deletable'], True)

    def test_get_deletable_mark_for_own_activity_in_context(self):
        """
           Given a plain user
           and a regular context
           When i post an activity in a context
           Then i have the permission to delete 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)
        res = self.testapp.get('/activities/%s' % res.json['id'], '', oauth2Header(username), status=200)
        self.assertEqual(res.json['deletable'], True)

    def test_get_deletable_mark_for_others_activity_in_context(self):
        """
           Given a plain user
           and a regular context
           When i post an activity in a context
           Then i don't have the permission to delete 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)
        res = self.testapp.get('/activities/%s' % res.json['id'], '', oauth2Header(username_not_me), status=200)
        self.assertEqual(res.json['deletable'], False)

#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_activities.py

示例14: FunctionalTests

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

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

        username = "messi"
        self.create_user(username)
        self.create_context(create_context)
        self.admin_subscribe_user_to_context(username, subscribe_context)

        activity = self.create_activity(username, user_status)
        activity = activity.json
        res = self.testapp.post(
            "/activities/%s/comments" % str(activity.get("id")),
            json.dumps(user_comment),
            oauth2Header(username),
            status=201,
        )

        activity2 = self.create_activity(username, user_status_context)
        activity2 = activity2.json
        res = self.testapp.post(
            "/activities/%s/comments" % str(activity2.get("id")),
            json.dumps(user_comment),
            oauth2Header(username),
            status=201,
        )

        res = self.testapp.get("/people/%s/comments" % username, "", oauth2Header(username), status=200)
        result = res.json
        self.assertEqual(len(result), 2)

        self.assertEqual(result[0].get("actor", None).get("username"), "messi")
        self.assertEqual(result[0].get("verb", None), "comment")
        self.assertEqual(result[1].get("actor", None).get("username"), "messi")
        self.assertEqual(result[1].get("verb", None), "comment")

    def test_delete_own_comment(self):
        """
            Given i'm plain user
            When i comment an activity
            Then i can delete it
        """
        from .mockers import user_status, user_comment

        username = "messi"
        self.create_user(username)
        activity = self.create_activity(username, user_status)
        activity = activity.json
        res = self.testapp.post(
            "/activities/%s/comments" % str(activity.get("id")),
            json.dumps(user_comment),
            oauth2Header(username),
            status=201,
        )
        comment_id = res.json["id"]
        res = self.testapp.delete(
            "/activities/%s/comments/%s" % (str(activity.get("id")), comment_id), "", oauth2Header(username), status=204
        )

    def test_delete_others_comment_in_own_activity(self):
        """
            Given i'm a plain user
            When someone else commments on an activity of mine
            Then I can delete it, 'cause the activity is mine
        """
        from .mockers import user_status, user_comment

        username = "messi"
        username_not_me = "xavi"
开发者ID:UPCnet,项目名称:max,代码行数:70,代码来源:test_comments.py

示例15: TokenACLTests

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

#.........这里部分代码省略.........
            Given i'm a regular user
            When i try to get al my tokens
            I succeed
        """
        username = 'sheldon'
        self.create_user(username)
        self.testapp.get('/people/{}/tokens/platforms/{}'.format(username, 'ios'), '', headers=oauth2Header(username), status=200)

    def test_get_user_platform_tokens_as_manager(self):
        """
            Given i'm a regular user
            When i try to get al my tokens
            I succeed
        """
        username = 'sheldon'
        self.create_user(username)
        self.testapp.get('/people/{}/tokens/platforms/{}'.format(username, 'ios'), '', headers=oauth2Header(test_manager), status=200)

    def test_get_user_platform_tokens_as_other(self):
        """
            Given i'm a regular user
            When i try to get al my tokens
            I get a Forbidden Exception
        """
        username = 'sheldon'
        other = 'penny'
        self.create_user(username)
        self.create_user(other)

        self.testapp.get('/people/{}/tokens/platforms/{}'.format(username, 'ios'), '', headers=oauth2Header(other), status=403)

    # Delete token test

    def test_delete_token(self):
        """
            Given i'm a regular user
            When i try to add delete a device token
            I succeed
        """
        from max.tests.mockers import token

        username = 'sheldon'
        self.create_user(username)

        self.testapp.post('/tokens', json.dumps(token), headers=oauth2Header(username), status=201)
        self.testapp.delete('/tokens/{}'.format(token['token']), '', headers=oauth2Header(username), status=204)

    def test_delete_ohers_token(self):
        """
            Given i'm a regular user
            When i try to delete someone else's device token
            I get a Forbidden Exception
        """
        from max.tests.mockers import token

        username = 'sheldon'
        username2 = 'penny'
        self.create_user(username)
        self.create_user(username2)

        self.testapp.post('/tokens', json.dumps(token), headers=oauth2Header(username), status=201)
        self.testapp.delete('/tokens/{}'.format(token['token']), '', headers=oauth2Header(username2), status=403)

    def test_delete_token_impersonated(self):
        """
            Given i'm a Manager user
开发者ID:UPCnet,项目名称:max,代码行数:70,代码来源:test_tokens_acls.py


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