本文整理汇总了Python中max.tests.base.MaxTestApp.head方法的典型用法代码示例。如果您正苦于以下问题:Python MaxTestApp.head方法的具体用法?Python MaxTestApp.head怎么用?Python MaxTestApp.head使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类max.tests.base.MaxTestApp
的用法示例。
在下文中一共展示了MaxTestApp.head方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ContextACLTests
# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import head [as 别名]
#.........这里部分代码省略.........
"""
from max.tests.mockers import create_context
self.create_user(test_manager)
self.create_user(test_manager2)
res = self.create_context(create_context)
chash = res.json['hash']
self.testapp.delete('/contexts/%s' % (chash,), "", oauth2Header(test_manager2), status=204)
def test_delete_context_as_owner(self):
"""
Given a user that has doesn't have the Manager role
And is the owner of the context
When i try to remove a context
I succeed
"""
from max.tests.mockers import create_context
username = 'sheldon'
self.create_user(test_manager)
self.create_user(username)
res = self.create_context(create_context, owner=username)
chash = res.json['hash']
self.testapp.delete('/contexts/%s' % (chash,), "", oauth2Header(username), status=204)
def test_delete_context_as_non_manager_neither_owner(self):
"""
Given a user that has doesn't have the Manager role
And is not the owner of the context
When i try to remove a context
I get a Forbidden
"""
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.delete('/contexts/%s' % (chash,), "", oauth2Header(username), status=403)
# Test context authors
def test_get_context_authors_as_manager(self):
"""
Given a user that is Manager
When i try to list context activity authors
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/activities/authors' % (chash,), "", oauth2Header(test_manager), status=200)
def test_get_context_authors_as_non_manager(self):
"""
Given a user that is not Manager
When i try to list context activity authors
I get a Forbidden
"""
from max.tests.mockers import create_context
username = 'sheldon'
self.create_user(test_manager)
self.create_user(username)
res = self.create_context(create_context, permissions={'read': 'subscribed'})
chash = res.json['hash']
self.testapp.get('/contexts/%s/activities/authors' % (chash,), "", oauth2Header(username), status=403)
def test_get_context_authors_as_non_manager_public_context(self):
"""
Given a user that is not Manager
When i try to list context activity authors
I get a Forbidden
"""
from max.tests.mockers import create_context
username = 'sheldon'
self.create_user(test_manager)
self.create_user(username)
res = self.create_context(create_context, permissions={'read': 'public'})
chash = res.json['hash']
self.testapp.get('/contexts/%s/activities/authors' % (chash,), "", oauth2Header(username), status=200)
def test_get_count_context_authors_as_non_manager(self):
"""
Given a user that is not Manager
When i try to list the count of context activity authors
I succeed
"""
from max.tests.mockers import create_context, subscribe_context
username = 'sheldon'
self.create_user(test_manager)
self.create_user(username)
res = self.create_context(create_context)
self.admin_subscribe_user_to_context(username, subscribe_context)
chash = res.json['hash']
self.testapp.head('/contexts/%s/activities/authors' % (chash,), oauth2Header(username), status=200)
示例2: FunctionalTests
# 需要导入模块: from max.tests.base import MaxTestApp [as 别名]
# 或者: from max.tests.base.MaxTestApp import head [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_head_without_permissions(self):
"""
Given a user that is not Manager
And a GET endpoint protected with Manager role
When i try to call that endpoint with HEAD method
Then i can access the results count
And the same endpoint with GET returns a Forbidden
"""
from .mockers import user_status
username = 'messi'
self.create_user(username)
for i in range(11):
self.create_activity(username, user_status, note=str(i))
res = self.testapp.get('/activities', '', oauth2Header(username), status=403)
res = self.testapp.head('/activities', oauth2Header(username), status=200)
self.assertEqual(res.headers.get('X-totalItems'), '11')
def test_user_activities_stats(self):
from .mockers import user_status
username = 'messi'
self.create_user(username)
for i in range(11):
self.create_activity(username, user_status, note=str(i))
res = self.testapp.get('/people/%s/activities' % username, '', oauth2Header(username), status=200)
self.assertEqual(len(res.json), 10)
res = self.testapp.head('/people/%s/activities' % username, oauth2Header(username), status=200)
self.assertEqual(res.headers.get('X-totalItems'), '11')
def test_user_activities_stats_per_year(self):
from .mockers import user_status
username = 'messi'
self.create_user(username)
self.create_activity(username, user_status)
old_activity = deepcopy(user_status)
old_activity['published'] = '2010-01-01T00:01:30.000Z'
for i in range(11):
self.create_activity(username, old_activity, note=str(i))
res = self.testapp.get('/people/%s/activities?date_filter=2010' % username, '', oauth2Header(username), status=200)
self.assertEqual(len(res.json), 10)
res = self.testapp.head('/people/%s/activities?date_filter=2010' % username, oauth2Header(username), status=200)
self.assertEqual(res.headers.get('X-totalItems'), '11')
def test_user_activities_stats_without_activity(self):
username = 'messi'
self.create_user(username)
res = self.testapp.get('/people/%s/activities' % username, '', oauth2Header(username), status=200)
self.assertEqual(len(res.json), 0)
res = self.testapp.head('/people/%s/activities' % username, oauth2Header(username), status=200)
self.assertEqual(res.headers.get('X-totalItems'), '0')
def test_user_activities_stats_context_only(self):
from .mockers import user_status
username = 'messi'
self.create_user(username)
for i in range(11):
self.create_activity(username, user_status, note=str(i))
from .mockers import user_status_context
from .mockers import create_context
from .mockers import subscribe_context
from hashlib import sha1
self.create_context(create_context)
url_hash = sha1(create_context['url']).hexdigest()
self.admin_subscribe_user_to_context(username, subscribe_context)
self.create_activity(username, user_status_context)
res = self.testapp.head('/people/%s/activities?context=%s' % (username, url_hash), oauth2Header(username), status=200)
self.assertEqual(res.headers.get('X-totalItems'), '1')
def test_activities_stats_on_context(self):
from .mockers import user_status_context
from .mockers import create_context
from .mockers import subscribe_context
from hashlib import sha1
#.........这里部分代码省略.........