本文整理汇总了Python中max.tests.base.MaxTestApp类的典型用法代码示例。如果您正苦于以下问题:Python MaxTestApp类的具体用法?Python MaxTestApp怎么用?Python MaxTestApp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MaxTestApp类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: InfoACLTests
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,代码行数:60,代码来源:test_info_acls.py
示例2: FunctionalTests
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,代码行数:47,代码来源:_test_follows.py
示例3: setUp
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)
开发者ID:UPCnet,项目名称:max,代码行数:8,代码来源:_test_follows.py
示例4: setUp
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)
开发者ID:UPCnet,项目名称:max,代码行数:10,代码来源:test_debug.py
示例5: setUp
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)
开发者ID:UPCnet,项目名称:max,代码行数:14,代码来源:test_people_acls.py
示例6: setUp
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)
开发者ID:UPCnet,项目名称:max,代码行数:15,代码来源:test_avatars.py
示例7: setUp
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)
开发者ID:UPCnet,项目名称:max,代码行数:16,代码来源:test_comments_acls.py
示例8: FunctionalTests
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,代码行数:101,代码来源:test_restricted_user_visibility.py
示例9: ContextACLTests
class ContextACLTests(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 context tests
def test_add_context_as_manager(self):
"""
Given a user that has the Manager role
When i try to get create a context
I succeed
"""
from max.tests.mockers import create_context
self.create_user(test_manager)
self.testapp.post('/contexts', json.dumps(create_context), oauth2Header(test_manager), status=201)
def test_add_context_as_non_manager(self):
"""
Given a user that doesn't have the Manager role
When i try to create a context
I get a Forbidden exception
"""
from max.tests.mockers import create_context
username = 'sheldon'
self.create_user(username)
self.testapp.post('/contexts', json.dumps(create_context), oauth2Header(username), status=403)
# View context tests
def test_view_context_as_manager_with_acls(self):
"""
Given i'm a user that has the Manager role
When i try to update any context
I succeed
And I get the acls for that context
"""
from max.tests.mockers import create_context
self.create_user(test_manager)
res = self.create_context(create_context)
chash = res.json['hash']
res = self.testapp.get('/contexts/%s?show_acls=1' % chash, "", oauth2Header(test_manager), status=200)
self.assertGreater(len(res.json['acls']), 0)
def test_view_context_as_manager(self):
"""
Given i'm a user that has the Manager role
When i try to update any context
I succeed
"""
from max.tests.mockers import create_context
self.create_user(test_manager)
res = self.create_context(create_context)
chash = res.json['hash']
self.testapp.get('/contexts/%s' % chash, "", oauth2Header(test_manager), status=200)
def test_view_context_as_non_manager(self):
"""
Given i'm a user that has the Manager role
When i try to update any context
I succeed
"""
from max.tests.mockers import create_context
username = 'sheldon'
self.create_user(test_manager)
self.create_user(username)
res = self.create_context(create_context)
chash = res.json['hash']
self.testapp.get('/contexts/%s' % chash, "", oauth2Header(username), status=200)
# Get all contexts tests
def test_get_all_contexts_as_manager(self):
"""
Given a user that has the Manager role
When i try to get all contexts
I succeed
"""
from max.tests.mockers import create_context
self.create_user(test_manager)
self.create_context(create_context)
self.testapp.get('/contexts', "", oauth2Header(test_manager), status=200)
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:101,代码来源:test_contexts_acls.py
示例10: FunctionalTests
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,代码行数:101,代码来源:test_nonvisible.py
示例11: SubscriptionsACLTests
class SubscriptionsACLTests(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)
# Create subscription tests
def test_subscribe_user_to_context_as_manager(self):
"""
Given i'm a user that has the Manager role
When i try to get subscribe another user to a context
I succeed
"""
from max.tests.mockers import create_context, subscribe_context
username = 'sheldon'
self.create_user(username)
self.create_context(create_context)
self.admin_subscribe_user_to_context(username, subscribe_context, expect=201)
def test_subscribe_user_to_context_as_context_owner(self):
"""
Given i'm a user that doesn't have the Manager role
And i'm the owner of the context
When i try to subscribe another user to a context
I succeed
"""
from max.tests.mockers import create_context, subscribe_context
username = 'sheldon'
other = 'penny'
self.create_user(username)
self.create_user(other)
self.create_context(create_context, owner=username)
self.user_subscribe_user_to_context(other, subscribe_context, auth_user=username, expect=201)
def test_self_subscribe_to_public_context_as_non_manager(self):
"""
Given i'm a user that doesn't have the Manager role
When i try to subscribe myself to a public subscription context
I succeed
"""
from max.tests.mockers import create_context, subscribe_context
username = 'sheldon'
self.create_user(username)
self.create_context(create_context, permissions={'subscribe': 'public'})
self.user_subscribe_user_to_context(username, subscribe_context, expect=201)
def test_self_subscribe_to_restricted_context_as_non_manager(self):
"""
Given i'm a user that doesn't have the Manager role
When i try to subscribe myself to a restricted subscription context
I succeed
"""
from max.tests.mockers import create_context, subscribe_context
username = 'sheldon'
self.create_user(username)
self.create_context(create_context, permissions={'subscribe': 'restricted'})
self.user_subscribe_user_to_context(username, subscribe_context, expect=403)
def test_subscribe_user_to_restricted_context_as_non_manager(self):
"""
Given i'm a user that doesn't have the Manager role
When i try to subscribe another user to a restricted subscription context
I get a Forbidden exception
"""
from max.tests.mockers import create_context, subscribe_context
username = 'sheldon'
other = 'penny'
self.create_user(username)
self.create_user(other)
self.create_context(create_context, permissions={'subscribe': 'restricted'})
self.user_subscribe_user_to_context(username, subscribe_context, expect=403)
def test_subscribe_user_to_public_context_as_non_manager(self):
"""
Given i'm a user that doesn't have the Manager role
When i try to subscribe another user to a public subscription context
I get a Forbidden exception
"""
from max.tests.mockers import create_context, subscribe_context
username = 'sheldon'
other = 'penny'
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:101,代码来源:test_subscriptions_acls.py
示例12: FunctionalTests
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,代码行数:101,代码来源:test_misc.py
示例13: TimelineACLTests
class TimelineACLTests(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)
# View user timeline
def test_get_timeline(self):
"""
Given i'm a regular user
When i try to get my timeline
I succeed
"""
username = 'sheldon'
self.create_user(username)
self.testapp.get('/people/%s/timeline' % username, '', oauth2Header(username), status=200)
def test_get_timeline_as_manager(self):
"""
Given i'm a Manager user
When i try to get another user's timeline
I succeed
"""
username = 'sheldon'
self.create_user(username)
self.testapp.get('/people/%s/timeline' % username, '', oauth2Header(test_manager), status=200)
def test_get_timeline_as_other(self):
"""
Given i'm a regular user
When i try to get another user's timeline
I get a Forbidden Exception
"""
username = 'sheldon'
other = 'penny'
self.create_user(username)
self.create_user(other)
self.testapp.get('/people/%s/timeline' % username, '', oauth2Header(other), status=403)
# View user timeline authors
def test_get_timeline_authors(self):
"""
Given i'm a regular user
When i try to get my timeline authors
I succeed
"""
username = 'sheldon'
self.create_user(username)
self.testapp.get('/people/%s/timeline/authors' % username, '', oauth2Header(username), status=200)
def test_get_timeline_authors_as_manager(self):
"""
Given i'm a Manager user
When i try to get another user's timeline authors
I succeed
"""
username = 'sheldon'
self.create_user(username)
self.testapp.get('/people/%s/timeline/authors' % username, '', oauth2Header(test_manager), status=200)
def test_get_timeline_authors_as_other(self):
"""
Given i'm a regular user
When i try to get another user's timeline authors
I get a Forbidden Exception
"""
username = 'sheldon'
other = 'penny'
self.create_user(username)
self.create_user(other)
self.testapp.get('/people/%s/timeline/authors' % username, '', oauth2Header(other), status=403)
开发者ID:UPCnet,项目名称:max,代码行数:88,代码来源:test_timeline_acls.py
示例14: FunctionalTests
class FunctionalTests(unittest.TestCase, MaxTestBase):
def setUp(self):
conf_dir = os.path.dirname(__file__)
self.app = loadapp('config:tests.ini', relative_to=conf_dir)
self.reset_database(self.app)
self.app.registry.max_store.security.insert(test_default_security)
self.patched_post = patch('requests.post', new=partial(mock_post, self))
self.patched_post.start()
self.testapp = MaxTestApp(self)
self.create_user(test_manager)
# BEGIN TESTS
def test_invalid_token(self):
username = 'messi'
res = self.testapp.post('/people/%s' % username, json.dumps({}), oauth2Header(test_manager, token='bad token'), status=401)
self.assertEqual(res.json['error_description'], 'Invalid token.')
def test_invalid_token_TEMPORARY(self):
from hashlib import sha1
from .mockers import create_context
mindundi = 'messi'
self.create_user(mindundi)
self.create_context(create_context, owner=mindundi)
url_hash = sha1(create_context['url']).hexdigest()
res = self.testapp.put('/contexts/%s' % url_hash, json.dumps({"twitterHashtag": "assignatura1"}), oauth2Header(mindundi, token='bad token'), status=401)
self.assertEqual(res.json['error_description'], 'Invalid token.')
def test_invalid_scope(self):
username = 'messi'
headers = oauth2Header(test_manager)
headers['X-Oauth-Scope'] = 'Invalid scope'
res = self.testapp.post('/people/%s' % username, "", headers, status=401)
self.assertEqual(res.json['error_description'], 'The specified scope is not allowed for this resource.')
def test_invalid_scope_TEMPORARY(self):
from hashlib import sha1
from .mockers import create_context
mindundi = 'messi'
headers = oauth2Header(test_manager)
headers['X-Oauth-Scope'] = 'Invalid scope'
self.create_user(mindundi)
self.create_context(create_context, owner=mindundi)
url_hash = sha1(create_context['url']).hexdigest()
res = self.testapp.put('/contexts/%s' % url_hash, json.dumps({"twitterHashtag": "assignatura1"}), headers, status=401)
self.assertEqual(res.json['error_description'], 'The specified scope is not allowed for this resource.')
def test_required_user_not_found(self):
from hashlib import sha1
from .mockers import create_context
mindundi = 'messi'
self.create_context(create_context, owner=mindundi)
url_hash = sha1(create_context['url']).hexdigest()
res = self.testapp.put('/contexts/%s' % url_hash, json.dumps({"twitterHashtag": "assignatura1"}), oauth2Header(mindundi), status=400)
self.assertEqual(res.json['error_description'], 'Unknown actor identified by: messi')
def test_post_activity_no_auth_headers(self):
from .mockers import user_status
username = 'messi'
self.create_user(username)
res = self.testapp.post('/people/%s/activities' % username, json.dumps(user_status), status=401)
result = json.loads(res.text)
self.assertEqual(result.get('error', None), 'Unauthorized')
开发者ID:UPCnet,项目名称:max,代码行数:67,代码来源:test_auth.py
示例15: FunctionalTests
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):
self.patched_post.stop()
# BEGIN TESTS
def test_create_activity_strip_tags(self):
""" doctest .. http:post:: /people/{username}/activities """
from .mockers import user_status
username = 'messi'
self.create_user(username)
res = self.testapp.post('/people/%s/activities' % username, json.dumps(user_status), oauth2Header(username), status=201)
self.assertEqual(res.json['object']['content'], u"[A] Testejant la creació d'un canvi d'estatus")
def test_post_comment_strip_tags(self):
""" doctest .. http:post:: /activities/{activity}/comments """
from .mockers import user_status, user_comment
from .mockers import subscribe_context, create_context
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)
self.assertEqual(res.json['object']['content'], u"[C] Testejant un comentari nou a una activitat")
def test_post_message_to_conversation_strip_tags(self):
""" doctest .. http:post:: /conversations """
from .mockers import message_with_tags
sender = 'messi'
recipient = 'xavi'
self.create_user(sender)
self.create_user(recipient)
res = self.testapp.post('/conversations', json.dumps(message_with_tags), oauth2Header(sender), status=201)
self.assertEqual(res.json['object']['content'], u'A <strong>text</strong> A')
def test_post_activity_shortens_url(self):
""" """
from .mockers import user_status_with_url
username = 'messi'
self.create_user(username)
res = self.create_activity(username, user_status_with_url)
self.assertIn('bit.ly', res.json['object']['content'],)
@httpretty.activate
def test_url_shortened_bitly_failure(self):
from max.utils.formatting import shortenURL
http_mock_bitly(status=500)
url = 'http://example.com'
bitly_username = 'maxclient2'
bitly_api_key = 'R_1123ce7d9aea4d699f65af02912c048e'
newurl = shortenURL(url, bitly_username, bitly_api_key)
self.assertEqual(url, newurl)
@httpretty.activate
def test_url_shortened_parsing_failure(self):
from max.utils.formatting import shortenURL
http_mock_bitly(status=500, body="invalid json")
url = 'http://example.com'
bitly_username = 'maxclient2'
bitly_api_key = 'R_1123ce7d9aea4d699f65af02912c048e'
newurl = shortenURL(url, bitly_username, bitly_api_key)
self.assertEqual(url, newurl)
@httpretty.activate
def test_url_shortened(self):
from max.utils.formatting import shortenURL
http_mock_bitly()
url = 'http://example.com'
bitly_username = 'maxclient2'
bitly_api_key = 'R_1123ce7d9aea4d699f65af02912c048e'
newurl = shortenURL(url, bitly_username, bitly_api_key)
self.assertEqual(newurl, "http://shortened.url")
@httpretty.activate
def test_url_secure_shortened(self):
from max.utils.formatting import shortenURL
http_mock_bitly()
url = 'http://example.com'
bitly_username = 'maxclient2'
bitly_api_key = 'R_1123ce7d9aea4d699f65af02912c048e'
newurl = shortenURL(url, bitly_username, bitly_api_key, secure=True)
#.........这里部分代码省略.........
开发者ID:UPCnet,项目名称:max,代码行数:101,代码来源:test_formatters.py
示例16: FunctionalTests
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 r
|
请发表评论