本文整理汇总了Python中sentry.plugins.sentry_mail.models.MailProcessor类的典型用法代码示例。如果您正苦于以下问题:Python MailProcessor类的具体用法?Python MailProcessor怎么用?Python MailProcessor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MailProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_notify_users_does_email
def test_notify_users_does_email(self, _send_mail):
group = Group(
id=2,
first_seen=timezone.now(),
last_seen=timezone.now(),
project=self.project,
)
event = Event(
group=group,
message='hello world',
logger='root',
project=self.project,
datetime=group.last_seen,
)
with self.Settings(SENTRY_URL_PREFIX='http://example.com'):
p = MailProcessor(send_to=['[email protected]'])
p.notify_users(group, event)
_send_mail.assert_called_once()
args, kwargs = _send_mail.call_args
self.assertEquals(kwargs.get('fail_silently'), False)
self.assertEquals(kwargs.get('project'), self.project)
self.assertEquals(kwargs.get('subject'), u"[Project Name] ERROR: hello world")
示例2: test_notify_users_does_email
def test_notify_users_does_email(self, _send_mail):
project = Project(id=1, name='Project Name')
group = Group()
group.first_seen = timezone.now()
group.last_seen = group.first_seen
group.project = project
group.id = 2
event = Event()
event.group = group
event.message = 'hello world'
event.logger = 'root'
event.project = project
event.date = group.last_seen
with self.Settings(SENTRY_URL_PREFIX='http://example.com'):
p = MailProcessor(send_to=['[email protected]'])
p.notify_users(group, event)
_send_mail.assert_called_once()
args, kwargs = _send_mail.call_args
self.assertEquals(kwargs.get('fail_silently'), False)
self.assertEquals(kwargs.get('project'), project)
self.assertEquals(kwargs.get('subject'), u"[Project Name] ERROR: hello world")
示例3: test_notify_users_renders_interfaces_with_utf8
def test_notify_users_renders_interfaces_with_utf8(self, _send_mail):
group = Group(
id=2,
first_seen=timezone.now(),
last_seen=timezone.now(),
project=self.project,
)
stacktrace = Mock(spec=Stacktrace)
stacktrace.to_string.return_value = u'רונית מגן'
stacktrace.get_title.return_value = 'Stacktrace'
event = Event()
event.group = group
event.message = 'hello world'
event.logger = 'root'
event.site = None
event.interfaces = {'sentry.interfaces.Stacktrace': stacktrace}
with self.Settings(SENTRY_URL_PREFIX='http://example.com'):
p = MailProcessor(send_to=['[email protected]'])
p.notify_users(group, event)
stacktrace.get_title.assert_called_once_with()
stacktrace.to_string.assert_called_once_with(event)
示例4: test_notify_users_does_email
def test_notify_users_does_email(self, _send_mail):
project = Project(id=1, name="Project Name")
group = Group()
group.first_seen = datetime.datetime.now()
group.last_seen = group.first_seen
group.project = project
group.id = 2
event = Event()
event.group = group
event.message = "hello world"
event.logger = "root"
event.project = project
event.date = group.last_seen
with self.Settings(SENTRY_URL_PREFIX="http://example.com"):
p = MailProcessor(send_to=["[email protected]"])
p.notify_users(group, event)
_send_mail.assert_called_once()
args, kwargs = _send_mail.call_args
self.assertEquals(kwargs.get("fail_silently"), False)
self.assertEquals(kwargs.get("project"), project)
self.assertEquals(kwargs.get("subject"), u"[Project Name] ERROR: hello world")
示例5: test_should_notify_excluded
def test_should_notify_excluded(self):
p = MailProcessor(min_level=None, exclude_loggers=['root'])
group = Mock(spec=Group)
group.project = Project()
group.level = 5
group.logger = 'root'
self.assertFalse(p.should_notify(group=group, event=Mock()))
示例6: test_should_notify_match
def test_should_notify_match(self):
p = MailProcessor(min_level=None)
group = Mock(spec=Group)
group.level = 5
group.project = Project()
group.logger = 'root'
event = Mock()
event.data = {}
self.assertTrue
(p.should_notify(group=group, event=event))
示例7: test_get_emails_for_users
def test_get_emails_for_users(self):
from django.contrib.auth.models import User
from sentry.models import UserOption
user = User.objects.create(username='foo', email='[email protected]')
user2 = User.objects.create(username='baz', email='[email protected]')
p = MailProcessor()
self.assertEquals(sorted(p.get_emails_for_users([user.pk, user2.pk])),
sorted([user.email, user2.email]))
UserOption.objects.create(key='alert_email', value='[email protected]', user=user2)
self.assertEquals(sorted(p.get_emails_for_users([user.pk, user2.pk])),
sorted([user.email, '[email protected]']))
示例8: test_get_sendable_users
def test_get_sendable_users(self):
from django.contrib.auth.models import User
from sentry.models import Project, UserOption
user = User.objects.create(username="foo", email="[email protected]", is_active=True)
user2 = User.objects.create(username="baz", email="[email protected]", is_active=True)
user3 = User.objects.create(username="bar", email="[email protected]", is_active=False)
project = Project.objects.create(name="Test", slug="test", owner=user)
project.team.member_set.get_or_create(user=user)
project.team.member_set.get_or_create(user=user2)
project.team.member_set.get_or_create(user=user3)
p = MailProcessor()
# all members
self.assertEqual(sorted(set([user.pk, user2.pk])), sorted(p.get_sendable_users(project)))
# disabled user2
UserOption.objects.create(key="mail:alert", value=0, project=project, user=user2)
self.assertEqual(sorted(set([user.pk])), sorted(p.get_sendable_users(project)))
示例9: test_get_sendable_users
def test_get_sendable_users(self):
from django.contrib.auth.models import User
from sentry.models import Project, UserOption
user = User.objects.create(username='foo', email='[email protected]')
user2 = User.objects.create(username='baz', email='[email protected]')
project = Project.objects.create(name='Test', slug='test', owner=user)
project.team.member_set.get_or_create(user=user)
project.team.member_set.get_or_create(user=user2)
p = MailProcessor()
# all members
self.assertEqual(sorted(set([user.pk, user2.pk])),
sorted(p.get_sendable_users(project)))
# disabled user2
UserOption.objects.create(key='mail:alert', value=0, project=project, user=user2)
self.assertEqual(sorted(set([user.pk])),
sorted(p.get_sendable_users(project)))
示例10: test_send_to
def test_send_to(self, get_emails_for_users, get_sendable_users, get_value):
opts = {}
admins = ["1"]
member_emails = ["2", "3"]
project_emails = ["2", "4"]
get_value.side_effect = lambda p, k, d: opts.get(k, d)
get_emails_for_users.side_effect = lambda x: x
get_sendable_users.return_value = member_emails
project = mock.Mock()
project.id = 1
project.pk = project.id
with self.Settings(SENTRY_ADMINS=admins):
p = MailProcessor()
# member emails without admins
self.assertEqual(sorted(set(member_emails)), sorted(p.get_send_to(project)))
# member emails with members
opts = {"mail:send_to_admins": True}
self.assertEqual(sorted(set(member_emails + admins)), sorted(p.get_send_to(project)))
# project emails without members
opts = {"mail:send_to": ",".join(project_emails), "mail:send_to_members": False}
self.assertEqual(sorted(set(project_emails)), sorted(p.get_send_to(project)))
# project emails with members
opts = {
"mail:send_to": ",".join(project_emails),
"mail:send_to_members": False,
"mail:send_to_admins": True,
}
self.assertEqual(sorted(set(project_emails + admins)), sorted(p.get_send_to(project)))
# project emails with members and admins
opts = {"mail:send_to": ",".join(project_emails), "mail:send_to_members": True, "mail:send_to_admins": True}
self.assertEqual(sorted(set(project_emails + admins + member_emails)), sorted(p.get_send_to(project)))
示例11: test_multiline_error
def test_multiline_error(self, _send_mail):
group = Group(
id=2,
first_seen=timezone.now(),
last_seen=timezone.now(),
project=self.project,
)
event = Event(
group=group,
message='hello world\nfoo bar',
logger='root',
project=self.project,
datetime=group.last_seen,
)
with self.Settings(SENTRY_URL_PREFIX='http://example.com'):
p = MailProcessor(send_to=['[email protected]'])
p.notify_users(group, event)
_send_mail.assert_called_once()
args, kwargs = _send_mail.call_args
assert kwargs.get('subject') == u"[{0}] ERROR: hello world".format(self.project.name)
示例12: test_notify_users_renders_interfaces_with_utf8_fix_issue_422
def test_notify_users_renders_interfaces_with_utf8_fix_issue_422(self, _send_mail):
group = Group()
group.first_seen = timezone.now()
group.last_seen = group.first_seen
group.id = 2
group.project_id = 1
stacktrace = Mock(spec=Stacktrace)
stacktrace.to_string.return_value = u'רונית מגן'
stacktrace.get_title.return_value = 'Stacktrace'
event = Event()
event.group = group
event.message = 'Soubor ji\xc5\xbe existuje'
event.logger = 'root'
event.site = None
event.interfaces = {'sentry.interfaces.Stacktrace': stacktrace}
with self.Settings(SENTRY_URL_PREFIX='http://example.com'):
p = MailProcessor(send_to=['[email protected]'])
p.notify_users(group, event)
stacktrace.get_title.assert_called_once_with()
stacktrace.to_string.assert_called_once_with(event)
示例13: test_notify_users_renders_interfaces_with_utf8
def test_notify_users_renders_interfaces_with_utf8(self, _send_mail):
group = Group()
group.first_seen = datetime.datetime.now()
group.last_seen = group.first_seen
group.id = 2
group.project_id = 1
stacktrace = Mock(spec=Stacktrace)
stacktrace.to_string.return_value = u"רונית מגן"
stacktrace.get_title.return_value = "Stacktrace"
event = Event()
event.group = group
event.message = "hello world"
event.logger = "root"
event.site = None
event.interfaces = {"sentry.interfaces.Stacktrace": stacktrace}
with self.Settings(SENTRY_URL_PREFIX="http://example.com"):
p = MailProcessor(send_to=["[email protected]"])
p.notify_users(group, event)
stacktrace.get_title.assert_called_once_with()
stacktrace.to_string.assert_called_once_with(event)
示例14: test_send_to
def test_send_to(self, get_emails_for_users, get_sendable_users, get_value):
opts = {}
member_emails = ['2', '3']
project_emails = ['2', '4']
get_value.side_effect = lambda p, k, d: opts.get(k, d)
get_emails_for_users.side_effect = lambda x: x
get_sendable_users.return_value = member_emails
project = mock.Mock()
project.id = 1
project.pk = project.id
p = MailProcessor()
# member emails without admins
self.assertEqual(sorted(set(member_emails)),
sorted(p.get_send_to(project)))
# project emails without members
opts = {'mail:send_to': ','.join(project_emails),
'mail:send_to_members': False}
self.assertEqual(sorted(set(project_emails)),
sorted(p.get_send_to(project)))
示例15: test_should_notify_match
def test_should_notify_match(self):
p = MailProcessor(min_level=None)
group = Mock(spec=Group)
group.level = 5
group.logger = 'root'
self.assertTrue(p.should_notify(group=group, event=Mock()))