本文整理汇总了Python中kitsune.questions.events.QuestionReplyEvent.notify方法的典型用法代码示例。如果您正苦于以下问题:Python QuestionReplyEvent.notify方法的具体用法?Python QuestionReplyEvent.notify怎么用?Python QuestionReplyEvent.notify使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kitsune.questions.events.QuestionReplyEvent
的用法示例。
在下文中一共展示了QuestionReplyEvent.notify方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setUp
# 需要导入模块: from kitsune.questions.events import QuestionReplyEvent [as 别名]
# 或者: from kitsune.questions.events.QuestionReplyEvent import notify [as 别名]
def setUp(self):
p = profile()
p.save()
self.user = p.user
self.client.login(username=self.user.username, password='testpass')
self.question = question(creator=self.user, save=True)
QuestionReplyEvent.notify(self.user, self.question)
示例2: test_notify_arbitrary_reply_to
# 需要导入模块: from kitsune.questions.events import QuestionReplyEvent [as 别名]
# 或者: from kitsune.questions.events.QuestionReplyEvent import notify [as 别名]
def test_notify_arbitrary_reply_to(self):
"""
Test that notifications to the asker have a correct reply to field.
"""
watcher = user(save=True)
QuestionReplyEvent.notify(watcher, self.question)
self.makeAnswer()
notification = [m for m in mail.outbox if m.to == [watcher.email]][0]
# Headers should be compared case-insensitively.
headers = dict((k.lower(), v) for k, v in notification.extra_headers.items())
eq_("[email protected]", headers["reply-to"])
示例3: test_notify_anonymous_reply_to
# 需要导入模块: from kitsune.questions.events import QuestionReplyEvent [as 别名]
# 或者: from kitsune.questions.events.QuestionReplyEvent import notify [as 别名]
def test_notify_anonymous_reply_to(self):
"""
Test that notifications to the asker have a correct reply to field.
"""
ANON_EMAIL = "[email protected]"
QuestionReplyEvent.notify(ANON_EMAIL, self.question)
self.makeAnswer()
notification = [m for m in mail.outbox if m.to == [ANON_EMAIL]][0]
# Headers should be compared case-insensitively.
headers = dict((k.lower(), v) for k, v in notification.extra_headers.items())
eq_("[email protected]", headers["reply-to"])
示例4: test_notify_arbitrary
# 需要导入模块: from kitsune.questions.events import QuestionReplyEvent [as 别名]
# 或者: from kitsune.questions.events.QuestionReplyEvent import notify [as 别名]
def test_notify_arbitrary(self):
"""Test that arbitrary users are notified of new answers."""
watcher = UserFactory()
QuestionReplyEvent.notify(watcher, self.question)
self.makeAnswer()
# One for the asker's email, and one for the watcher's email.
eq_(2, len(mail.outbox))
notification = [m for m in mail.outbox if m.to == [watcher.email]][0]
eq_([watcher.email], notification.to)
eq_(u'Re: {0}'.format(self.question.title), notification.subject)
body = re.sub(r'auth=[a-zA-Z0-9%_-]+', 'auth=AUTH', notification.body)
starts_with(body, ANSWER_EMAIL.format(to_user=display_name(watcher), **self.format_args()))
示例5: test_notify_arbitrary
# 需要导入模块: from kitsune.questions.events import QuestionReplyEvent [as 别名]
# 或者: from kitsune.questions.events.QuestionReplyEvent import notify [as 别名]
def test_notify_arbitrary(self):
"""Test that arbitrary users are notified of new answers."""
watcher = user(save=True)
QuestionReplyEvent.notify(watcher, self.question)
self.makeAnswer()
# One for the asker's email, and one for the watcher's email.
eq_(2, len(mail.outbox))
notification = [m for m in mail.outbox if m.to == [watcher.email]][0]
eq_([watcher.email], notification.to)
eq_("Re: {0}".format(self.question.title), notification.subject)
body = re.sub(r"auth=[a-zA-Z0-9%_-]+", "auth=AUTH", notification.body)
starts_with(body, ANSWER_EMAIL.format(to_user=watcher.username, **self.format_args()))
示例6: test_notify_anonymous
# 需要导入模块: from kitsune.questions.events import QuestionReplyEvent [as 别名]
# 或者: from kitsune.questions.events.QuestionReplyEvent import notify [as 别名]
def test_notify_anonymous(self):
"""Test that anonymous users are notified of new answers."""
ANON_EMAIL = "[email protected]"
QuestionReplyEvent.notify(ANON_EMAIL, self.question)
self.makeAnswer()
# One for the asker's email, and one for the anonymous email.
eq_(2, len(mail.outbox))
notification = [m for m in mail.outbox if m.to == [ANON_EMAIL]][0]
eq_([ANON_EMAIL], notification.to)
eq_("Re: {0}".format(self.question.title), notification.subject)
body = re.sub(r"auth=[a-zA-Z0-9%_-]+", "auth=AUTH", notification.body)
starts_with(body, ANSWER_EMAIL_TO_ANONYMOUS.format(**self.format_args()))
示例7: save
# 需要导入模块: from kitsune.questions.events import QuestionReplyEvent [as 别名]
# 或者: from kitsune.questions.events.QuestionReplyEvent import notify [as 别名]
def save(self, update=False, *args, **kwargs):
"""Override save method to take care of updated if requested."""
new = not self.id
if not new:
self.clear_cached_html()
if update:
self.updated = datetime.now()
super(Question, self).save(*args, **kwargs)
if new:
# Avoid circular import, events.py imports Question
from kitsune.questions.events import QuestionReplyEvent
# Authors should automatically watch their own questions.
QuestionReplyEvent.notify(self.creator, self)
示例8: test_notify_anonymous
# 需要导入模块: from kitsune.questions.events import QuestionReplyEvent [as 别名]
# 或者: from kitsune.questions.events.QuestionReplyEvent import notify [as 别名]
def test_notify_anonymous(self):
"""Test that anonymous users are notified of new answers."""
ANON_EMAIL = '[email protected]'
QuestionReplyEvent.notify(ANON_EMAIL, self.question)
self.makeAnswer()
# One for the asker's email, and one for the anonymous email.
eq_(2, len(mail.outbox))
notification = [m for m in mail.outbox if m.to == [ANON_EMAIL]][0]
eq_([ANON_EMAIL], notification.to)
eq_("{0} commented on a Firefox question you're watching"
.format(self.answer.creator.username),
notification.subject)
body = re.sub(r'auth=[a-zA-Z0-9%_-]+', 'auth=AUTH', notification.body)
starts_with(body, ANSWER_EMAIL_TO_ANONYMOUS
.format(**self.format_args()))
示例9: test_notify_unique_auth_tokens
# 需要导入模块: from kitsune.questions.events import QuestionReplyEvent [as 别名]
# 或者: from kitsune.questions.events.QuestionReplyEvent import notify [as 别名]
def test_notify_unique_auth_tokens(self, email_mock):
"""Test that arbitrary users get unique auth tokens."""
auth_backend = TokenLoginBackend()
auth_re = re.compile(r'auth=([a-zA-Z0-9%_-]+)')
watcher = UserFactory()
QuestionReplyEvent.notify(watcher, self.question)
asker_id = self.question.creator.id
self.makeAnswer()
def get_auth_token(ctx):
return auth_re.search(ctx['answer_url']).group(1).replace('%3D', '=')
eq_(email_mock.call_count, 2)
all_calls = email_mock.call_args_list
for call in all_calls:
ctx = call[1]['context_vars']
user = ctx['to_user']
if user.id == asker_id:
auth = get_auth_token(ctx)
eq_(user, auth_backend.authenticate(auth))
else:
assert auth_re.search(ctx['answer_url']) is None
示例10: test_answer_notification
# 需要导入模块: from kitsune.questions.events import QuestionReplyEvent [as 别名]
# 或者: from kitsune.questions.events.QuestionReplyEvent import notify [as 别名]
def test_answer_notification(self, get_current):
"""Assert that hitting the watch toggle toggles and that proper mails
are sent to anonymous users, registered users, and the question
asker."""
# TODO: This test is way too monolithic, and the fixtures encode
# assumptions that aren't obvious here. Split this test into about 5,
# each of which tests just 1 thing. Consider using instantiation
# helpers.
get_current.return_value.domain = 'testserver'
# An arbitrary registered user watches:
watcher = user(save=True)
q = self._toggle_watch_question('reply', watcher, turn_on=True)
# An anonymous user watches:
QuestionReplyEvent.notify('[email protected]', q)
# The question asker watches:
QuestionReplyEvent.notify(q.creator, q)
# Post a reply
replier = user(save=True)
self.client.login(username=replier.username, password='testpass')
post(self.client, 'questions.reply', {'content': 'an answer'},
args=[q.id])
a = Answer.uncached.filter().order_by('-id')[0]
# Order of emails is not important.
eq_(3, len(mail.outbox))
emails_to = [m.to[0] for m in mail.outbox]
i = emails_to.index(watcher.email)
attrs_eq(mail.outbox[i], to=[watcher.email],
subject='%s commented on a Firefox question '
"you're watching" % a.creator.username)
body = mail.outbox[i].body
body = re.sub(r'auth=[a-zA-Z0-9%_-]+', r'auth=AUTH', body)
starts_with(body, ANSWER_EMAIL.format(
to_user=watcher.username,
title=q.title,
content=a.content,
replier=replier.username,
question_id=q.id,
answer_id=a.id))
i = emails_to.index(q.creator.email)
attrs_eq(mail.outbox[i], to=[q.creator.email],
subject='%s posted an answer to your question "%s"' %
(a.creator.username, q.title))
body = mail.outbox[i].body
body = re.sub(r'auth=[a-zA-Z0-9%_-]+', r'auth=AUTH', body)
starts_with(body, ANSWER_EMAIL_TO_ASKER.format(
asker=q.creator.username,
title=q.title,
content=a.content,
replier=replier.username,
question_id=q.id,
answer_id=a.id))
i = emails_to.index('[email protected]')
attrs_eq(mail.outbox[i], to=['[email protected]'],
subject="%s commented on a Firefox question you're watching" %
a.creator.username)
body = mail.outbox[i].body
body = re.sub(r'auth=[a-zA-Z0-9%_-]+', r'auth=AUTH', body)
starts_with(body, ANSWER_EMAIL_TO_ANONYMOUS.format(
title=q.title,
content=a.content,
replier=replier.username,
question_id=q.id,
answer_id=a.id))
示例11: setUp
# 需要导入模块: from kitsune.questions.events import QuestionReplyEvent [as 别名]
# 或者: from kitsune.questions.events.QuestionReplyEvent import notify [as 别名]
def setUp(self):
self.user = UserFactory()
self.client.login(username=self.user.username, password='testpass')
self.question = QuestionFactory(creator=self.user)
QuestionReplyEvent.notify(self.user, self.question)