本文整理汇总了Python中pyramid.testing.DummyRequest.domain方法的典型用法代码示例。如果您正苦于以下问题:Python DummyRequest.domain方法的具体用法?Python DummyRequest.domain怎么用?Python DummyRequest.domain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyramid.testing.DummyRequest
的用法示例。
在下文中一共展示了DummyRequest.domain方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_all_keys_are_there
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import domain [as 别名]
def test_all_keys_are_there():
"""Checks for the existence of every needed key for the template"""
with patch('h.notification.reply_template.Annotation') as mock_annotation:
mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
request = DummyRequest()
request.domain = 'www.howtoreachtheark.now'
annotation = store_fake_data[1]
data = {
'parent': rt.parent_values(annotation),
'subscription': {'id': 1}
}
tmap = rt.create_template_map(request, annotation, data)
assert 'document_title' in tmap
assert 'document_path' in tmap
assert 'parent_text' in tmap
assert 'parent_user' in tmap
assert 'parent_timestamp' in tmap
assert 'parent_user_profile' in tmap
assert 'parent_path' in tmap
assert 'reply_text' in tmap
assert 'reply_user' in tmap
assert 'reply_timestamp' in tmap
assert 'reply_user_profile' in tmap
assert 'reply_path' in tmap
assert 'unsubscribe' in tmap
示例2: _create_request
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import domain [as 别名]
def _create_request():
mock_dumps = Mock(return_value='TOKEN')
request = DummyRequest()
request.domain = 'www.howtoreachtheark.now'
request.registry.notification_serializer = Mock(dumps=mock_dumps)
request.route_url = Mock()
request.route_url.return_value = 'UNSUBSCRIBE_URL'
return request
示例3: test_action_create
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import domain [as 别名]
def test_action_create():
"""If the action is create, it'll try to get the subscriptions"""
with patch('h.notification.reply_template.Annotation') as mock_annotation:
mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
request = DummyRequest()
request.domain = 'www.howtoreachtheark.now'
annotation = store_fake_data[1]
event = events.AnnotationEvent(request, annotation, 'create')
with patch('h.notification.reply_template.Subscriptions') as mock_subs:
mock_subs.get_active_subscriptions_for_a_type.return_value = []
rt.send_notifications(event)
assert mock_subs.get_active_subscriptions_for_a_type.called
示例4: test_fallback_title
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import domain [as 别名]
def test_fallback_title():
"""Checks that the title falls back to using the url"""
with patch('h.notification.reply_template.Annotation') as mock_annotation:
mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
request = DummyRequest()
request.domain = 'www.howtoreachtheark.now'
annotation = store_fake_data[4]
data = {
'parent': rt.parent_values(annotation),
'subscription': {'id': 1}
}
tmap = rt.create_template_map(request, annotation, data)
assert tmap['document_title'] == annotation['uri']
示例5: test_dont_send_to_the_same_user
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import domain [as 别名]
def test_dont_send_to_the_same_user():
"""Tests that if the parent user and the annotation user is the same
then this function returns False"""
with patch('h.notification.reply_template.Annotation') as mock_annotation:
mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
request = DummyRequest()
request.domain = 'www.howtoreachtheark.now'
annotation = store_fake_data[0]
data = {
'parent': rt.parent_values(annotation),
'subscription': {'id': 1}
}
send = rt.check_conditions(annotation, data)
assert send is False
示例6: test_template_map_key_values
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import domain [as 别名]
def test_template_map_key_values():
"""This test checks whether the keys holds the correct values"""
with patch('h.notification.reply_template.Annotation') as mock_annotation:
mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
request = DummyRequest()
request.domain = 'www.howtoreachtheark.now'
annotation = store_fake_data[1]
data = {
'parent': rt.parent_values(annotation),
'subscription': {'id': 1}
}
tmap = rt.create_template_map(request, annotation, data)
parent = store_fake_data[0]
# Document properties
assert tmap['document_title'] == annotation['document']['title']
assert tmap['document_path'] == parent['uri']
# Parent properties
assert tmap['parent_text'] == parent['text']
assert tmap['parent_user'] == user_name(parent['user'])
assert tmap['parent_user_profile'] == user_profile_url(request, parent['user'])
assert tmap['parent_path'] == standalone_url(request, parent['id'])
# Annotation properties
assert tmap['reply_text'] == annotation['text']
assert tmap['reply_user'] == user_name(annotation['user'])
assert tmap['reply_user_profile'] == user_profile_url(request, annotation['user'])
assert tmap['reply_path'] == standalone_url(request, annotation['id'])
# Timestamps
date_format = '%Y-%m-%dT%H:%M:%S.%f'
parent_timestamp = datetime.strptime(parent['created'][:-6], date_format)
reply_timestamp = datetime.strptime(annotation['created'][:-6], date_format)
assert tmap['parent_timestamp'] == parent_timestamp
assert tmap['reply_timestamp'] == reply_timestamp
# Unsubscribe link
seq = ('http://', str(request.domain), '/app?__formid__=unsubscribe&subscription_id=', str(data['subscription']['id']))
unsubscribe = "".join(seq)
assert tmap['unsubscribe'] == unsubscribe
示例7: test_check_conditions_false_stops_sending
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import domain [as 别名]
def test_check_conditions_false_stops_sending():
"""If the check conditions() returns False, no notification is sent"""
with patch('h.notification.reply_template.Annotation') as mock_annotation:
mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
request = DummyRequest()
request.domain = 'www.howtoreachtheark.now'
annotation = store_fake_data[1]
event = events.AnnotationEvent(request, annotation, 'create')
with patch('h.notification.reply_template.Subscriptions') as mock_subs:
mock_subs.get_active_subscriptions_for_a_type.return_value = [
MockSubscription(id=1, uri='acct:[email protected]')
]
with patch('h.notification.reply_template.check_conditions') as mock_conditions:
mock_conditions.return_value = False
with patch('h.notification.reply_template.send_email') as mock_mail:
rt.send_notifications(event)
assert mock_mail.called is False
示例8: test_get_email
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import domain [as 别名]
def test_get_email():
"""Tests whether it gives back the user.email property"""
with patch('h.notification.reply_template.Annotation') as mock_annotation:
mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
with patch('h.notification.reply_template.get_user_by_name') as mock_user_db:
user = Mock()
user.email = '[email protected]'
mock_user_db.return_value = user
request = DummyRequest()
request.domain = 'www.howtoreachtheark.now'
annotation = store_fake_data[1]
data = {
'parent': rt.parent_values(annotation),
'subscription': {'id': 1}
}
email = rt.get_recipients(request, data)
assert email[0] == user.email
示例9: test_no_email
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import domain [as 别名]
def test_no_email():
"""If user has no email we must throw an exception"""
with patch('h.notification.reply_template.Annotation') as mock_annotation:
mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
with patch('h.notification.reply_template.get_user_by_name') as mock_user_db:
mock_user_db.return_value = {}
request = DummyRequest()
request.domain = 'www.howtoreachtheark.now'
annotation = store_fake_data[1]
data = {
'parent': rt.parent_values(annotation),
'subscription': {'id': 1}
}
exc = False
try:
rt.get_recipients(request, data)
except:
exc = True
assert exc
示例10: test_send_if_everything_is_okay
# 需要导入模块: from pyramid.testing import DummyRequest [as 别名]
# 或者: from pyramid.testing.DummyRequest import domain [as 别名]
def test_send_if_everything_is_okay():
"""Test whether we call the send_email() if every condition is okay"""
with patch('h.notification.reply_template.Annotation') as mock_annotation:
mock_annotation.fetch = MagicMock(side_effect=fake_fetch)
request = DummyRequest()
request.domain = 'www.howtoreachtheark.now'
annotation = store_fake_data[1]
event = events.AnnotationEvent(request, annotation, 'create')
with patch('h.notification.reply_template.Subscriptions') as mock_subs:
mock_subs.get_active_subscriptions_for_a_type.return_value = [
MockSubscription(id=1, uri='acct:[email protected]')
]
with patch('h.notification.reply_template.check_conditions') as mock_conditions:
mock_conditions.return_value = True
with patch('h.notification.reply_template.render') as mock_render:
mock_render.return_value = ''
with patch('h.notification.reply_template.get_user_by_name') as mock_user_db:
user = Mock()
user.email = '[email protected]'
mock_user_db.return_value = user
with patch('h.notification.reply_template.send_email') as mock_mail:
rt.send_notifications(event)
assert mock_mail.called is True