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


Python MaxTestApp.get方法代码示例

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


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

示例1: InfoACLTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import get [as 别名]
class InfoACLTests(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_get_public_settings(self):
        """
            Given i'm an unauthenticated user
            When i try to get max public settings
            Then i succeed
        """
        self.testapp.get('/info', status=200)

    def test_get_full_settings(self):
        """
            Given i'm an unauthenticated user
            When i try to get all max settings
            Then i get a Forbidden Error
        """
        self.testapp.get('/info/settings', status=401)

    def test_get_full_settings_authenticated(self):
        """
            Given i'm a regular user
            When i try to get all max settings
            Then i get a Forbidden Error
        """
        username = 'sheldon'
        self.create_user(username)
        self.testapp.get('/info/settings', headers=oauth2Header(username), status=403)

    def test_get_full_settings_as_manager(self):
        """
            Given i'm a Manager
            When i try to get all max settings
            Then i succeed
        """
        self.testapp.get('/info/settings', headers=oauth2Header(test_manager), status=200)

    def test_get_endpoints_info(self):
        """
            Given i'm an unauthenticated user
            When i try to get the endpoint definitions
            Then i succeed
        """
        self.testapp.get('/info/api', status=200)
开发者ID:UPCnet,项目名称:max,代码行数:62,代码来源:test_info_acls.py

示例2: FunctionalTests

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

    # BEGIN TESTS

    def test_follow_user(self):
        """
        """
        username = 'messi'
        username2 = 'xavi'

        self.create_user(username)
        self.create_user(username2)

        res = self.testapp.post('/people/%s/follows/%s' % (username, username2), '', oauth2Header(username), status=201)
        self.assertEqual(res.json['verb'], 'follow')

        res = self.testapp.get('/people/%s' % (username), '', oauth2Header(username), status=200)
        self.assertEqual(username2, res.json['following'][0]['username'])

    def test_user_sees_followed_activity(self):
        """
        """
        from .mockers import user_status

        username = 'messi'
        username2 = 'xavi'

        self.create_user(username)
        self.create_user(username2)

        self.create_activity(username, user_status)
        self.create_activity(username2, user_status)

        res = self.testapp.post('/people/%s/follows/%s' % (username, username2), '', oauth2Header(username), status=201)
        self.assertEqual(res.json['verb'], 'follow')

        res = self.testapp.get('/people/%s/timeline' % (username), '', oauth2Header(username), status=200)
        self.assertEqual(len(res.json), 2)
开发者ID:UPCnet,项目名称:max,代码行数:49,代码来源:_test_follows.py

示例3: InfoACLTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import get [as 别名]
class InfoACLTests(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_execute_maintenance(self):
        """
            Given i'm a regular user
            When i try to execute maintenance endpoints
            Then i get Forbidden Exceptions
        """
        username = 'sheldon'

        self.testapp.post('/admin/maintenance/keywords', headers=oauth2Header(username), status=403)
        self.testapp.post('/admin/maintenance/dates', headers=oauth2Header(username), status=403)
        self.testapp.post('/admin/maintenance/subscriptions', headers=oauth2Header(username), status=403)
        self.testapp.post('/admin/maintenance/conversations', headers=oauth2Header(username), status=403)
        self.testapp.post('/admin/maintenance/users', headers=oauth2Header(username), status=403)
        self.testapp.get('/admin/maintenance/exceptions', headers=oauth2Header(username), status=403)
        self.testapp.get('/admin/maintenance/exceptions/000000', headers=oauth2Header(username), status=403)

    def test_execute_maintenance_as_manager(self):
        """
            Given i'm a Manager
            When i try to execute maintenance endpoints
            Then i succeed
        """
        self.testapp.post('/admin/maintenance/keywords', headers=oauth2Header(test_manager), status=200)
        self.testapp.post('/admin/maintenance/dates', headers=oauth2Header(test_manager), status=200)
        self.testapp.post('/admin/maintenance/subscriptions', headers=oauth2Header(test_manager), status=200)
        self.testapp.post('/admin/maintenance/conversations', headers=oauth2Header(test_manager), status=200)
        self.testapp.post('/admin/maintenance/users', headers=oauth2Header(test_manager), status=200)
        self.testapp.get('/admin/maintenance/exceptions', headers=oauth2Header(test_manager), status=200)
        self.testapp.get('/admin/maintenance/exceptions/000000', headers=oauth2Header(test_manager), status=404)
开发者ID:UPCnet,项目名称:max,代码行数:50,代码来源:test_maintenance_acls.py

示例4: FunctionalTests

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

示例5: FunctionalTests

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

    def setUp(self):
        self.conf_dir = os.path.dirname(__file__)
        self.app = loadapp('config:tests.ini', relative_to=self.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):
        shutil.rmtree('{}/exceptions'.format(self.conf_dir))

    # BEGIN TESTS

    def test_root(self):
        """
            Test site root is accessible and returns html
        """
        res = self.testapp.get('/', status=200)
        self.assertEqual(res.content_type, 'text/html')

    def test_bad_test_call_warning(self):
        """
            Test calling a service with missing body parameter, and the authorization as body.
            As this will only probably happen in tests, The error message is targeted so.
        """
        username = 'messi'
        self.create_user(username)
        res = self.testapp.post('/people/%s/activities' % username, oauth2Header(test_manager), status=401)
        self.assertEqual(res.json['error_description'], u'Authorization found in url params, not in request. Check your tests, you may be passing the authentication headers as the request body...')

    @patch('max.models.user.User.insert', fucked_up_insert)
    def test_generic_exception_catching(self):
        """
            Test calling a webservice mocked to force an exception, to test the scavenger
            that formats beautiful json error messages for uncatched exceptions
        """
        username = 'messi'
        res = self.create_user(username, expect=500)
        self.assertEqual(res.json['error'], 'ServerError')
        self.assertIn('BEGIN EXCEPTION REPORT', res.json['error_description'])
        self.assertIn('END EXCEPTION REPORT', res.json['error_description'])

    def test_bad_body_content_parsing(self):
        """
            Test calling a service with a list on post body, that expects a json object.
            It should fail
        """
        username = 'messi'
        self.testapp.post('/people/%s' % username, '[]', oauth2Header(username), status=400)

    def test_post_tunneling_on_delete(self):
        """
            Test that calling a endpoint with DELETE indirectly within a POST
            actually calls the real delete method
        """
        from .mockers import user_status
        username = 'messi'
        self.create_user(username)
        res = self.create_activity(username, user_status)
        activity_id = res.json['id']
        headers = oauth2Header(test_manager)
        headers['X-HTTP-Method-Override'] = 'DELETE'
        self.testapp.post('/activities/{}'.format(activity_id), '', headers, status=204)

    def test_compat_id_match(self):
        """
        """
        username = 'messi'
        self.create_user(username)
        headers = oauth2Header(username)
        headers['X-Max-Compat-ID'] = 'test'
        self.testapp.get('/people', headers=headers, status=200)

    def test_compat_id_mismatch(self):
        """
        """
        username = 'messi'
        self.create_user(username)
        headers = oauth2Header(username)
        headers['X-Max-Compat-ID'] = 'test2'
        self.testapp.get('/people', headers=headers, status=412)

    def test_post_tunneling_on_put(self):
        """
            Test that calling a endpoint with PUT indirectly within a POST
            actually calls the real PUT method
        """
        username = 'messi'
        self.create_user(username)
        headers = oauth2Header(username)
        headers['X-HTTP-Method-Override'] = 'PUT'
        res = self.testapp.post('/people/{}'.format(username), json.dumps({"displayName": "Lionel Messi"}), headers, status=200)
        self.assertEqual(res.request.method, 'PUT')
        self.assertEqual(res.json['displayName'], 'Lionel Messi')

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

示例6: PeopleACLTests

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

    # Add people tests

    def test_create_person_as_manager(self):
        """
            Given i'm a user that has the Manager role
            When i try to create a person
            I succeed
        """
        username = 'sheldon'
        self.testapp.post('/people', json.dumps({"username": username}), headers=oauth2Header(test_manager), status=201)

    def test_create_person_as_non_manager(self):
        """
            Given i'm user that doesn't have the Manager role
            When i try to create a person
            I get a Forbidden exception
        """
        username = 'sheldon'
        other = 'penny'
        self.testapp.post('/people', json.dumps({"username": other}), headers=oauth2Header(username), status=403)

    def test_create_person_as_oneself(self):
        """
            Given i'm user that doesn't have the Manager role
            When i try to create a person
            I succeed
        """
        username = 'sheldon'
        self.testapp.post('/people', json.dumps({"username": username}), headers=oauth2Header(username), status=201)

    # View profile tests

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

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

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

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

    # Get all people

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

示例7: FunctionalTests

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

    def test_create_context_creator_is_admin(self):
        """
            Given a admin user
            When I create a context
            Then the creator of the context is the admin user
        """
        from .mockers import create_context
        res = self.testapp.post('/contexts', json.dumps(create_context), oauth2Header(test_manager), status=201)
        self.assertEqual(res.json['creator'], test_manager)

    def test_create_context_default_fields(self):
        """
            Given an admin user
            When I create a context
            Then non-required fields with defaults are set
        """
        from .mockers import create_context
        res = self.testapp.post('/contexts', json.dumps(create_context), oauth2Header(test_manager), status=201)
        self.assertIn('permissions', res.json)
        self.assertIn('tags', res.json)
        self.assertIn('objectType', res.json)
        self.assertEqual(res.json['objectType'], 'context')

    def test_post_activity_with_public_context(self):
        """ Post an activity to a context which allows everyone to read and write
        """
        from .mockers import subscribe_context, create_context
        from .mockers import user_status_context
        username = 'messi'
        self.create_user(username)
        self.create_context(create_context)
        self.admin_subscribe_user_to_context(username, subscribe_context)
        res = self.create_activity(username, user_status_context)

        result = json.loads(res.text)
        self.assertEqual(result.get('actor', None).get('username', None), 'messi')
        self.assertEqual(result.get('object', None).get('objectType', None), 'note')
        self.assertEqual(result.get('contexts', None)[0]['url'], subscribe_context['object']['url'])

    def test_post_activity_with_private_read_write_context(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, create_context
        from .mockers import user_status_context
        from hashlib import sha1

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

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

        result = json.loads(res.text)
        self.assertEqual(result.get('actor', None).get('username', None), 'messi')
        self.assertEqual(result.get('object', None).get('objectType', None), 'note')
        self.assertEqual(result.get('contexts', None)[0]['url'], subscribe_context['object']['url'])
        return url_hash, username, user_status_context

    def test_post_activity_with_private_read_context(self):
        """ Try to post an activity to a context which needs the user to be subscribed to read
            but needs to explicitly give write permission on the user to post and we have previously
            subscribed the user but not given write permission.
        """
        from .mockers import subscribe_context, create_context
        from .mockers import user_status_context
        username = 'messi'
        self.create_user(username)
        context_permissions = dict(read='subscribed', write='restricted', subscribe='restricted', invite='restricted')
        self.create_context(create_context, permissions=context_permissions)
        self.admin_subscribe_user_to_context(username, subscribe_context)
        self.create_activity(username, user_status_context, expect=403)

    def test_add_public_context(self):
        from hashlib import sha1
        from .mockers import create_context
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_contexts.py

示例8: FunctionalTests

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

    def setUp(self):
        conf_dir = os.path.dirname(__file__)
        self.app = loadapp('config:tests_restricted_user_visibility.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()

    # ############################################################################################################################
    #
    #  !!! IMPORTANT INFO !!! All this tests are run with the max.restricted_user_visibility_mode=True set in the .ini
    #  Tests for NonVisible users without restricted_user_visibility live in test_nonvisible.py, wich uses a different .ini
    #
    ##############################################################################################################################

    # Tests for listing people without sharing contexts (2 tests)

    def test_get_people_as_a_nonvisible_user_without_subscriptions(self):
        """
            Given i'm a nonvisible user
            When I search users
            And we don't share any context subscription
            Then I cannot see any of them
        """
        username_visible1 = 'user1'
        username_visible2 = 'user2'
        username_nonvisible1 = 'usernonvisible1'
        username_nonvisible2 = 'usernonvisible2'

        self.create_user(username_visible1)
        self.create_user(username_visible2)
        self.create_user(username_nonvisible1)
        self.create_user(username_nonvisible2)

        self.testapp.post('/admin/security/roles/%s/users/%s' % ('NonVisible', username_nonvisible1), "", oauth2Header(test_manager), status=201)
        self.testapp.post('/admin/security/roles/%s/users/%s' % ('NonVisible', username_nonvisible2), "", oauth2Header(test_manager), status=201)

        res = self.testapp.get('/people', "", oauth2Header(username_nonvisible1), status=200)

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

    def test_get_people_as_visible_user_without_subscriptions(self):
        """
            Given i'm a visible user
            When I search users
            And we don't share any context subscription
            Then I cannot see any of them
        """
        username_visible1 = 'user1'
        username_visible2 = 'user2'
        username_nonvisible1 = 'usernonvisible1'
        username_nonvisible2 = 'usernonvisible2'

        self.create_user(username_visible1)
        self.create_user(username_visible2)
        self.create_user(username_nonvisible1)
        self.create_user(username_nonvisible2)

        self.testapp.post('/admin/security/roles/%s/users/%s' % ('NonVisible', username_nonvisible1), "", oauth2Header(test_manager), status=201)
        self.testapp.post('/admin/security/roles/%s/users/%s' % ('NonVisible', username_nonvisible2), "", oauth2Header(test_manager), status=201)

        res = self.testapp.get('/people', "", oauth2Header(username_visible1), status=200)

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

    # Tests for listing people sharing contexts (2 tests)

    def test_get_people_as_nonvisible_user(self):
        """
            Given i'm a nonvisible person
            When I search users
            Then I can see all people on the same contexts as I, including other nonvisible users
        """
        from .mockers import subscribe_context, create_context
        username_visible1 = 'user1'
        username_visible2 = 'user2'
        username_nonvisible1 = 'usernonvisible1'
        username_nonvisible2 = 'usernonvisible2'

        self.create_user(username_visible1)
        self.create_user(username_visible2)
        self.create_user(username_nonvisible1)
        self.create_user(username_nonvisible2)

        self.create_context(create_context)
        self.admin_subscribe_user_to_context(username_visible1, subscribe_context)
        self.admin_subscribe_user_to_context(username_nonvisible1, subscribe_context)
        self.admin_subscribe_user_to_context(username_nonvisible2, subscribe_context)

        self.testapp.post('/admin/security/roles/%s/users/%s' % ('NonVisible', username_nonvisible1), "", oauth2Header(test_manager), status=201)
        self.testapp.post('/admin/security/roles/%s/users/%s' % ('NonVisible', username_nonvisible2), "", oauth2Header(test_manager), status=201)
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_restricted_user_visibility.py

示例9: DeprecationTests

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

#.........这里部分代码省略.........
            When the request is processed
            Then the request is rewrited as DELETE /conversations/{id}/participants/{username}
            And the url parameters are remapped
        """
        from max.tests.mockers import group_message as 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'])

        res = self.testapp.delete('/people/{}/conversations/{}'.format(recipient2, cid), '', oauth2Header(test_manager), status=204)

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

        self.assertEqual(rewrited_request_url, '/conversations/{}/participants/{}'.format(cid, recipient2))

    def test_deprecated_add_token(self):
        """
            Given a request to the deprecated POST /people/{user}/device/{platform}/{token}
            When the request is processed
            Then the request is rewrited as POST /tokens
            And the token is injected in the request body
            And the platform is injected in the reqeust body
            And the response contains a Person instead of a Token
        """
        username = 'sheldon'
        self.create_user(username)
        token = '000000000000000000'
        platform = 'ios'

        res = self.testapp.post('/people/{}/device/{}/{}'.format(username, platform, token), '', headers=oauth2Header(username), status=201)

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

        self.assertEqual(rewrited_request_url, '/tokens')
        self.assertEqual(res.json['username'], username)
        self.assertEqual(res.json['objectType'], 'person')

    def test_deprecated_delete_token(self):
        """
            Given a request to the deprecated DELETE /people/{user}/device/{platform}/{token}
            When the request is processed
            Then the request is rewrited as DELETE /tokens/{token}
            And the token is injected in the body
            And the platform is injected in the body
        """
        username = 'sheldon'
        self.create_user(username)
        token = '000000000000000000'
        platform = 'ios'

        self.testapp.post('/people/{}/device/{}/{}'.format(username, platform, token), '', headers=oauth2Header(username), status=201)
        res = self.testapp.delete('/people/{}/device/{}/{}'.format(username, platform, token), '', headers=oauth2Header(username), status=204)

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

        self.assertEqual(rewrited_request_url, '/tokens/{}'.format(token))

    def test_deprecated_sortBy_parameter(self):
        """
            Given a plain user
            When I query ativities using old sortBy parameter
            I get the expected result

            THIS TEST IS A DUPLICATE OF max.tests.test_timeline_order_sorted_by_last_comment_publish_date
            ONLY TO TEST THE TRANSLATION OF THE SORTBY PARAMETER

        """
        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?sortBy=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?sortBy=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])
开发者ID:UPCnet,项目名称:max,代码行数:104,代码来源:test_deprecations.py

示例10: FunctionalTests

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

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

    def test_add_nonvisible_role(self):
        username = 'messi'
        self.create_user(username)
        self.testapp.post('/admin/security/roles/%s/users/%s' % ('NonVisible', username), "", oauth2Header(test_manager), status=201)

    # ############################################################################################################################
    #
    #  !!! IMPORTANT INFO !!! All this tests are run with the max.restricted_user_visibility_mode=False in set the .ini
    #  Tests for NonVisible users WITH restricted_user_visibility live in test_restricted_user_visibility.py, wich uses a different .ini
    #
    #  The tests on this file are the same tests on test_restricted_user_visibility.py but WITHOUT excluding the ones that test
    #  Users with shared contexts, And with different asserts, as here we have the restricted_user_visibility disabled,
    #  and shared subscriptions doesn't affect us
    #
    ##############################################################################################################################

    # Tests for listing people without sharing contexts (2 tests)

    def test_get_people_as_a_nonvisible_user_without_subscriptions(self):
        """
            Given i'm a nonvisible user
            When I search users
            Then I see everyone
        """
        username_visible1 = 'user1'
        username_visible2 = 'user2'
        username_nonvisible1 = 'usernonvisible1'
        username_nonvisible2 = 'usernonvisible2'

        self.create_user(username_visible1)
        self.create_user(username_visible2)
        self.create_user(username_nonvisible1)
        self.create_user(username_nonvisible2)

        self.testapp.post('/admin/security/roles/%s/users/%s' % ('NonVisible', username_nonvisible1), "", oauth2Header(test_manager), status=201)
        self.testapp.post('/admin/security/roles/%s/users/%s' % ('NonVisible', username_nonvisible2), "", oauth2Header(test_manager), status=201)

        res = self.testapp.get('/people', "", oauth2Header(username_nonvisible1), status=200)

        self.assertEqual(len(res.json), 4)
        self.assertEqual(res.json[0]['username'], username_nonvisible2)
        self.assertEqual(res.json[1]['username'], username_nonvisible1)
        self.assertEqual(res.json[2]['username'], username_visible2)
        self.assertEqual(res.json[3]['username'], username_visible1)

    def test_get_people_as_visible_user_without_subscriptions(self):
        """
            Given i'm a visible user
            When I search users
            Then I only see the visible ones
        """
        username_visible1 = 'user1'
        username_visible2 = 'user2'
        username_nonvisible1 = 'usernonvisible1'
        username_nonvisible2 = 'usernonvisible2'

        self.create_user(username_visible1)
        self.create_user(username_visible2)
        self.create_user(username_nonvisible1)
        self.create_user(username_nonvisible2)

        self.testapp.post('/admin/security/roles/%s/users/%s' % ('NonVisible', username_nonvisible1), "", oauth2Header(test_manager), status=201)
        self.testapp.post('/admin/security/roles/%s/users/%s' % ('NonVisible', username_nonvisible2), "", oauth2Header(test_manager), status=201)

        res = self.testapp.get('/people', "", oauth2Header(username_visible1), status=200)

        self.assertEqual(len(res.json), 2)
        self.assertEqual(res.json[0]['username'], username_visible2)
        self.assertEqual(res.json[1]['username'], username_visible1)

    # Tests for start Conversations without sharing contexts (4 tests)

    def test_start_conversation_with_visible_as_nonvisible_without_sharing_contexts(self):
        from .mockers import message
        """
            Given i'm a nonvisible person
            When I try to start a conversation with a visible
            Then I can start the conversation
        """
        username_visible1 = 'user1'
        username_nonvisible1 = 'usernonvisible1'

        self.create_user(username_visible1)
        self.create_user(username_nonvisible1)

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

示例11: FunctionalTests

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

    def tearDown(self):
        import pyramid.testing

        pyramid.testing.tearDown()

    # BEGIN TESTS

    def test_create_user(self):
        username = "messi"
        self.testapp.post("/people/%s" % username, "", oauth2Header(test_manager), status=201)
        return username

    def test_create_user_missing_username(self):
        self.testapp.post("/people", json.dumps({}), oauth2Header(test_manager), status=400)

    def test_create_user_creator_is_admin(self):
        """
            Given an admin user
            When I create a user
            Then the creator must be the admin user
        """
        username = "messi"
        res = self.testapp.post("/people/%s" % username, "", oauth2Header(test_manager), status=201)
        self.assertEqual(res.json["creator"], test_manager)

    def test_create_user_default_fields(self):
        """
            Given an admin user
            When I create a user
            Then non-required fields with defaults are set
        """
        username = "messi"
        res = self.testapp.post("/people/%s" % username, "", oauth2Header(test_manager), status=201)
        self.assertIn("objectType", res.json)
        self.assertIn("following", res.json)
        self.assertIn("subscribedTo", res.json)
        self.assertEqual(res.json["objectType"], "person")

    def test_create_user_not_manager(self):
        username = "messi"
        self.testapp.post("/people/%s" % username, "", oauth2Header("imnotallowed"), status=403)

    def test_user_exist(self):
        username = "messi"
        self.create_user(username)
        res = self.testapp.post("/people/%s" % username, "", oauth2Header(test_manager), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get("username", None), "messi")

    def test_create_same_user_case_insensitive(self):
        username = "messi"
        username_case = "Messi"
        self.create_user(username)
        res = self.testapp.post("/people/%s" % username_case, "", oauth2Header(test_manager), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get("username", None), "messi")

    def test_get_user(self):
        """ Doctest .. http:get:: /people/{username} """
        username = "messi"
        self.create_user(username)
        res = self.testapp.get("/people/%s" % username, "", oauth2Header(username), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get("username", None), "messi")
        self.assertIn("username", result)
        self.assertIn("displayName", result)
        self.assertIn("objectType", result)
        self.assertGreater(len(result.keys()), 3)

    def test_get_user_as_someone_else(self):
        """ Doctest .. http:get:: /people/{username} """
        username = "messi"
        usernamenotme = "xavi"

        self.create_user(username)
        self.create_user(usernamenotme)

        res = self.testapp.get("/people/%s" % username, "", oauth2Header(usernamenotme), status=200)
        result = json.loads(res.text)
        self.assertEqual(result.get("username", None), "messi")
        self.assertIn("username", result)
        self.assertIn("displayName", result)
        self.assertIn("objectType", result)
        self.assertIn("published", result)
        self.assertEqual(len(result.keys()), 4)

    def test_get_user_case_insensitive(self):
        """ Doctest .. http:get:: /people/{username} """
        username = "messi"
        self.create_user(username)
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_people.py

示例12: AvatarsACLTests

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

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

        self.app = loadapp('config:tests.ini', relative_to=self.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)

        MaxAvatarsTestBase.setUp(self)

    def tearDown(self):
        """
            Deletes test avatar folder with all test images
        """
        self.patched_post.stop()
        MaxAvatarsTestBase.tearDown(self)

    # Add person avatar tests

    def test_add_user_avatar(self):
        """
            Given i'm a regular user
            When i try to update my avatar
            I succeed
        """
        username = 'sheldon'
        self.create_user(username)
        avatar_file = open(os.path.join(self.conf_dir, "avatar.png"), "rb")
        files = [('image', 'avatar.png', avatar_file.read(), 'image/png')]

        self.testapp.post('/people/{}/avatar'.format(username), '', headers=oauth2Header(username), upload_files=files, status=201)

    def test_add_user_avatar_as_manager(self):
        """
            Given i'm a regular user
            When i try to update my avatar
            I succeed
        """
        username = 'sheldon'
        self.create_user(username)
        avatar_file = open(os.path.join(self.conf_dir, "avatar.png"), "rb")
        files = [('image', 'avatar.png', avatar_file.read(), 'image/png')]

        self.testapp.post('/people/{}/avatar'.format(username), '', headers=oauth2Header(test_manager), upload_files=files, status=201)

    def test_add_other_user_avatar(self):
        """
            Given i'm a regular user
            When i try to update another user's avatar
            I get a Forbidden Exception
        """
        username = 'sheldon'
        self.create_user(username)
        other = 'penny'
        self.create_user(other)
        avatar_file = open(os.path.join(self.conf_dir, "avatar.png"), "rb")
        files = [('image', 'avatar.png', avatar_file.read(), 'image/png')]

        self.testapp.post('/people/{}/avatar'.format(username), '', headers=oauth2Header(other), upload_files=files, status=403)

    # Get person avatar tests, Large avatars acl's are not tested as is the same endpoint

    def test_get_user_avatar_unauthenticated(self):
        """
            Given i'm a unauthenticated user
            When I try to get a user avatar
            I succeed
        """
        username = 'sheldon'
        self.create_user(username)
        self.upload_user_avatar(username, "avatar.png")
        self.testapp.get('/people/%s/avatar' % username, '', {}, status=200)

    # Get twitter avatar tests

    def test_get_twitter_avatar_unauthenticated(self):
        """
            Given i'm a unauthenticated user
            When I try to get a context avatar coming from twitter
            I succeed
        """
        from hashlib import sha1
        from max.tests.mockers import create_context_full

        avatar_image = os.path.join(self.conf_dir, "avatar.png")
        http_mock_twitter_user_image(avatar_image)

        self.testapp.post('/contexts', json.dumps(create_context_full), oauth2Header(test_manager), status=201)
        url_hash = sha1(create_context_full['url']).hexdigest()
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_avatars_acls.py

示例13: AvatarTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import get [as 别名]
class AvatarTests(unittest.TestCase, MaxTestBase, MaxAvatarsTestBase):
    """
        Tests to check the uploading, downlading and retrieving of all
        avatar types used in max, included the ones coming from twitter.
    """

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

        self.testapp = MaxTestApp(self)
        self.create_user(test_manager)

        MaxAvatarsTestBase.setUp(self)

    def tearDown(self):
        """
            Deletes test avatar folder with all test images
        """
        self.patched_post.stop()
        self.patched_get.stop()
        MaxAvatarsTestBase.tearDown(self)

    # BEGIN TESTS

    def test_upload_user_avatar(self):
        """
            Given a user without avatar
            When I upload an image for that user
            Then a normal 48x48 image is stored in the correct avatar folder
            And a large 250x250 image is stored in the correct avatar folder
        """
        username = 'messi'
        self.create_user(username)
        avatar_file = open(os.path.join(self.conf_dir, "avatar.png"), "rb")
        files = [('image', 'avatar.png', avatar_file.read(), 'image/png')]

        self.testapp.post('/people/{}/avatar'.format(username), '', headers=oauth2Header(username), upload_files=files, status=201)

        self.assertEqual(self.get_user_avatar_dimensions(username), (48, 48))
        self.assertEqual(self.get_user_avatar_dimensions(username, 'large'), (250, 250))

    def test_invalid_upload_user_avatar(self):
        """
            Given a user without avatar
            When I upload an image for that user on the json body
            I get an error
        """
        username = 'messi'
        self.create_user(username)

        self.testapp.post('/people/{}/avatar'.format(username), '', headers=oauth2Header(username), status=400)

    def test_get_user_avatar(self):
        """
            Given a user with avatar
            When I retrieve the avatar
            Then I get the 48x48 version of that avatar
        """
        username = 'messi'
        self.create_user(username)
        self.upload_user_avatar(username, "avatar.png")

        response = self.testapp.get('/people/%s/avatar' % username, '', {}, status=200)

        self.assertIn('image', response.content_type)
        self.assertEqual(self.get_image_dimensions_from(response), (48, 48))

    def test_get_user_avatar_large(self):
        """
            Given a user without avatar
            When I retrieve the large avatar
            Then I get the 250x250 version of that avatar
        """
        username = 'messi'
        self.create_user(username)
        self.upload_user_avatar(username, "avatar.png")

        response = self.testapp.get('/people/%s/avatar/%s' % (username, 'large'), '', {}, status=200)

        self.assertIn('image', response.content_type)
        self.assertIn('image', response.content_type)
        self.assertEqual(self.get_image_dimensions_from(response), (250, 250))

    def test_get_user_avatar_large_missing_named_size(self):
        """
            Given a user without avatar
            When I retrieve the large avatar
            And the large avatars has disappeared
            Then I get the 48x48 version of that avatar
        """
        username = 'messi'
        self.create_user(username)
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:103,代码来源:test_avatars.py

示例14: FunctionalTests

# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import get [as 别名]
class FunctionalTests(unittest.TestCase, MaxTestBase):
    def setUp(self):
        conf_dir = os.path.dirname(__file__)
        self.app = loadapp("config:debug.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 test_debugging_mode_does_not_break_normal_app(self):
        """
            Make a simple get in debug mode to test app's normal behaviour
        """
        self.testapp.get("/people", "", status=401)

    def test_make_get_without_oauth(self):
        """
            With oauth2 passtrough and debug api option activated
            Check that we can make a get without getting a 401
        """
        debug_params = dict(d="", u=test_manager)
        qs = urllib.urlencode(debug_params)
        self.testapp.get("/people?{}".format(qs), "", {}, status=200)

    def test_make_debug_post_without_user(self):
        """
            With oauth2 passtrough and debug api option activated
            Check that debug mode without a user does not activate
            the method override
        """
        username = "messi"
        debug_params = dict(d="", m="post")
        qs = urllib.urlencode(debug_params)
        self.testapp.get("/people/{}?{}".format(username, qs), "", {}, status=400)

    def test_make_post_as_get(self):
        """
            With oauth2 passtrough and debug api option activated
            Check that we can make a post in a get request
        """
        username = "messi"
        debug_params = dict(d="", u=test_manager, m="post")
        qs = urllib.urlencode(debug_params)
        self.testapp.get("/people/{}?{}".format(username, qs), "", {}, status=201)

    def test_make_post_as_get_with_payload(self):
        """
            With oauth2 passtrough and debug api option activated
            Check that we can make a post in a get request
            with json payload as a oneline string
        """

        username = "messi"
        debug_params = dict(d="", u=test_manager, m="post", p='{"displayName":"El messi"}')
        qs = urllib.urlencode(debug_params)
        resp = self.testapp.get("/people/{}?{}".format(username, qs), "", {}, status=201)
        self.assertEqual(resp.json["displayName"], "El messi")

    def test_debug_responds_html(self):
        """
            Test that with option 1 in debug mode, we get the output as html
            This is necessary to debug_toolbar to instantiate
        """
        debug_params = dict(d="1", u=test_manager)
        qs = urllib.urlencode(debug_params)
        res = self.testapp.get("/people?{}".format(qs), "", {}, status=200)
        self.assertEqual(res.content_type, "text/html")
        self.assertIn("<html>", res.text)
开发者ID:UPCnet,项目名称:max,代码行数:73,代码来源:test_debug.py

示例15: FunctionalTests

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


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