本文整理汇总了Python中django.contrib.messages.constants.ERROR属性的典型用法代码示例。如果您正苦于以下问题:Python constants.ERROR属性的具体用法?Python constants.ERROR怎么用?Python constants.ERROR使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类django.contrib.messages.constants
的用法示例。
在下文中一共展示了constants.ERROR属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_show_signatures_post_resendOK_org
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_show_signatures_post_resendOK_org(self):
self.login("julia")
org = Organization.objects.get(name="Les Amis de la Terre")
petition = org.petition_set.first()
pid = petition.id
signature = Signature.objects.create(
first_name="Me",
last_name="You",
email="you@example.org",
petition=petition)
sid = signature.id
data = {
'action': 're-send',
'signature_id': [sid],
}
response = self.client.post(reverse("show_signatures", args=[pid]), data, follow=True)
self.assertRedirects(response, reverse("show_signatures", args=[pid]))
self.assertTemplateUsed(response, "petition/signature_data.html")
messages = response.context['messages']
self.assertGreaterEqual(len(messages), 1)
ThereIsAnyError = False
for msg in messages:
if msg.level == constants.ERROR:
ThereIsAnyError = True
self.assertEquals(ThereIsAnyError, False)
示例2: test_show_signatures_post_resendallOK
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_show_signatures_post_resendallOK(self):
julia = self.login("julia")
petition = julia.petition_set.first()
pid = petition.id
signature = Signature.objects.create(
first_name="Me",
last_name="You",
email="you@example.org",
petition=petition)
#sid = signature.id
data = {
'action': 're-send-all',
}
response = self.client.post(reverse("show_signatures", args=[pid]), data, follow=True)
self.assertRedirects(response, reverse("show_signatures", args=[pid]))
self.assertTemplateUsed(response, "petition/signature_data.html")
messages = response.context['messages']
self.assertGreaterEqual(len(messages), 1)
ThereIsAnyError = False
for msg in messages:
if msg.level == constants.ERROR:
ThereIsAnyError = True
self.assertEquals(ThereIsAnyError, False)
示例3: test_show_signatures_post_resendallOK_org
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_show_signatures_post_resendallOK_org(self):
self.login("julia")
org = Organization.objects.get(name="Les Amis de la Terre")
petition = org.petition_set.first()
pid = petition.id
signature = Signature.objects.create(
first_name="Me",
last_name="You",
email="you@example.org",
petition=petition)
#sid = signature.id
data = {
'action': 're-send-all',
}
response = self.client.post(reverse("show_signatures", args=[pid]), data, follow=True)
self.assertRedirects(response, reverse("show_signatures", args=[pid]))
self.assertTemplateUsed(response, "petition/signature_data.html")
messages = response.context['messages']
self.assertGreaterEqual(len(messages), 1)
ThereIsAnyError = False
for msg in messages:
if msg.level == constants.ERROR:
ThereIsAnyError = True
self.assertEquals(ThereIsAnyError, False)
示例4: test_OrgSetUserPermsViewLastAdminRemoveItsPermsKO
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_OrgSetUserPermsViewLastAdminRemoveItsPermsKO(self):
julia = self.login("julia")
julia_perms = Permission.objects.get(organization__slugname="rap", user=julia)
# Now let's try to remove admin rights from julia
# It should fail in order to make it impossible to have an admin-less Organization
data = {
'can_modify_permissions': 'off',
}
self.assertEqual(julia_perms.can_modify_permissions, True)
response = self.client.post(reverse("org_set_user_perms", kwargs={'orgslugname': 'rap', 'user_name': 'julia'}),
data, follow=True)
self.assertRedirects(response, reverse("org_edit_user_perms",
kwargs={'orgslugname': 'rap', 'user_name': 'julia'}))
self.assertEqual(response.context['permissions'].can_modify_permissions, True)
julia_perms.refresh_from_db()
self.assertEquals(julia_perms.can_modify_permissions, True)
messages = response.context['messages']
self.assertGreaterEqual(len(messages), 1)
ThereIsAnyError = False
for msg in messages:
if msg.level == constants.ERROR:
ThereIsAnyError = True
self.assertEquals(ThereIsAnyError, True)
示例5: test_OrgSetUserPermsViewSeveralAdminsRemoveItsPermsOK
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_OrgSetUserPermsViewSeveralAdminsRemoveItsPermsOK(self):
julia = self.login("julia")
julia_perms = Permission.objects.get(organization__slugname="alternatiba", user=julia)
# Now let's try to remove admin rights from julia
# It should fail in order to make it impossible to have an admin-less Organization
data = {
'can_modify_permissions': 'off',
}
self.assertEqual(julia_perms.can_modify_permissions, True)
response = self.client.post(reverse("org_set_user_perms", kwargs={'orgslugname': 'alternatiba',
'user_name': 'julia'}),
data, follow=True)
self.assertRedirects(response, reverse("org_edit_user_perms",
kwargs={'orgslugname': 'alternatiba', 'user_name': 'julia'}))
self.assertEqual(response.context['permissions'].can_modify_permissions, False)
julia_perms.refresh_from_db()
self.assertEquals(julia_perms.can_modify_permissions, False)
messages = response.context['messages']
self.assertGreaterEqual(len(messages), 1)
ThereIsAnyError = False
for msg in messages:
if msg.level == constants.ERROR:
ThereIsAnyError = True
self.assertEquals(ThereIsAnyError, False)
示例6: test_OrgSetUserPermsViewLastAdminSeveralMembersRemoveItsPermsKO
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_OrgSetUserPermsViewLastAdminSeveralMembersRemoveItsPermsKO(self):
julia = self.login("julia")
julia_perms = Permission.objects.get(organization__slugname="les-amis-de-la-terre", user=julia)
# Now let's try to remove admin rights from julia
# It should fail in order to make it impossible to have an admin-less Organization
data = {
'can_modify_permissions': 'off',
}
self.assertEqual(julia_perms.can_modify_permissions, True)
response = self.client.post(reverse("org_set_user_perms", kwargs={'orgslugname': 'les-amis-de-la-terre',
'user_name': 'julia'}),
data, follow=True)
self.assertRedirects(response, reverse("org_edit_user_perms",
kwargs={'orgslugname': 'les-amis-de-la-terre', 'user_name': 'julia'}))
self.assertEqual(response.context['permissions'].can_modify_permissions, True)
julia_perms.refresh_from_db()
self.assertEquals(julia_perms.can_modify_permissions, True)
messages = response.context['messages']
self.assertGreaterEqual(len(messages), 1)
ThereIsAnyError = False
for msg in messages:
if msg.level == constants.ERROR:
ThereIsAnyError = True
self.assertEquals(ThereIsAnyError, True)
示例7: test_page_move_confirm
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_page_move_confirm(self):
response = self.client.get(
reverse('wagtailadmin_pages:move_confirm', args=(self.test_page_a.id, self.section_b.id))
)
self.assertEqual(response.status_code, 200)
response = self.client.get(
reverse('wagtailadmin_pages:move_confirm', args=(self.test_page_b.id, self.section_a.id))
)
# Duplicate slugs triggers a redirect with an error message.
self.assertEqual(response.status_code, 302)
response = self.client.get(reverse('wagtailadmin_home'))
messages = list(response.context['messages'])
self.assertEqual(len(messages), 1)
self.assertEqual(messages[0].level, message_constants.ERROR)
# Slug should be in error message.
self.assertIn("{}".format(self.test_page_b.slug), messages[0].message)
示例8: test_email_send_error
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_email_send_error(self, mock_fn):
logging.disable(logging.CRITICAL)
# Approve
self.silent_submit()
response = self.approve()
logging.disable(logging.NOTSET)
# An email that fails to send should return a message rather than crash the page
self.assertEqual(response.status_code, 302)
response = self.client.get(reverse('wagtailadmin_home'))
# There should be one "approved" message and one "failed to send notifications"
messages = list(response.context['messages'])
self.assertEqual(len(messages), 2)
self.assertEqual(messages[0].level, message_constants.SUCCESS)
self.assertEqual(messages[1].level, message_constants.ERROR)
示例9: revoke_change
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def revoke_change(self, request, obj):
if not self.has_change_permission(request, obj):
raise PermissionDenied
if obj.revoked:
self.message_user(request, _('Certificate is already revoked.'), level=messages.ERROR)
return HttpResponseRedirect(obj.admin_change_url)
if request.method == 'POST':
form = RevokeCertificateForm(request.POST, instance=obj)
if form.is_valid():
reason = form.cleaned_data['revoked_reason']
if reason:
reason = ReasonFlags[reason]
obj.revoke(
reason=reason,
compromised=form.cleaned_data['compromised'] or None
)
return HttpResponseRedirect(obj.admin_change_url)
else:
form = RevokeCertificateForm(instance=obj)
context = dict(self.admin_site.each_context(request), form=form, object=obj, opts=obj._meta)
return TemplateResponse(request, "admin/django_ca/certificate/revoke_form.html", context)
示例10: test_enrollments_bad_response
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_enrollments_bad_response(self):
"""Verify a message is logged, and a separate message displayed to the user,
if the API does not return HTTTP 200."""
api_status = 500
self.mock_enrollment_api(status=api_status)
with LogCapture(LOGGER_NAME) as logger:
response = self.load_view()
self.assertEqual(response.status_code, 200)
self.assertEqual(response.context['enrollments'], [])
self.assert_message_equals(response, 'Failed to retrieve enrollment data.', MSG.ERROR)
logger.check((
LOGGER_NAME,
'WARNING',
'Failed to retrieve enrollments for [{}]. Enrollment API returned status code [{}].'.format(
self.user.username,
api_status
)
))
示例11: test_create_refund_error
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_create_refund_error(self):
"""Verify the view does not create a Refund if the selected Lines have already been refunded."""
refund = self.create_refund()
order = refund.order
for line in order.lines.all():
self.assertTrue(line.refund_lines.exists())
# No new refunds should be created
self.assertEqual(Refund.objects.count(), 1)
response = self._request_refund(order)
self.assertEqual(Refund.objects.count(), 1)
# An error message should be displayed.
self.assert_message_equals(response,
'A refund cannot be created for these lines. They may have already been refunded.',
MSG.ERROR)
示例12: test_json_encoder_decoder
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_json_encoder_decoder(self):
"""
A complex nested data structure containing Message
instances is properly encoded/decoded by the custom JSON
encoder/decoder classes.
"""
messages = [
{
'message': Message(constants.INFO, 'Test message'),
'message_list': [
Message(constants.INFO, 'message %s') for x in range(5)
] + [{'another-message': Message(constants.ERROR, 'error')}],
},
Message(constants.INFO, 'message %s'),
]
encoder = MessageEncoder(separators=(',', ':'))
value = encoder.encode(messages)
decoded_messages = json.loads(value, cls=MessageDecoder)
self.assertEqual(messages, decoded_messages)
示例13: test_handles_PowerActionAlreadyInProgress
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_handles_PowerActionAlreadyInProgress(self):
request = factory.make_fake_request(factory.make_string(), "POST")
error_message = (
"Unable to execute power action: another action is "
"already in progress for node %s" % factory.make_name("node")
)
error = PowerActionAlreadyInProgress(error_message)
response = self.process_request(request, error)
# The response is a redirect.
self.assertEqual(request.path, extract_redirect(response))
# An error message has been published.
self.assertEqual(
[(constants.ERROR, "Error: %s" % error_message, "")],
request._messages.messages,
)
示例14: test_handles_NoConnectionsAvailable
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_handles_NoConnectionsAvailable(self):
request = factory.make_fake_request(factory.make_string(), "POST")
error_message = (
"No connections available for cluster %s"
% factory.make_name("cluster")
)
error = NoConnectionsAvailable(error_message)
response = self.process_request(request, error)
# The response is a redirect.
self.assertEqual(request.path, extract_redirect(response))
# An error message has been published.
self.assertEqual(
[(constants.ERROR, "Error: " + error_message, "")],
request._messages.messages,
)
示例15: test_no_connections_available_has_usable_cluster_name_in_msg
# 需要导入模块: from django.contrib.messages import constants [as 别名]
# 或者: from django.contrib.messages.constants import ERROR [as 别名]
def test_no_connections_available_has_usable_cluster_name_in_msg(self):
# If a NoConnectionsAvailable exception carries a reference to
# the cluster UUID, RPCErrorsMiddleware will look up the
# cluster's name and make the error message it displays more
# useful.
request = factory.make_fake_request(factory.make_string(), "POST")
rack_controller = factory.make_RackController()
error = NoConnectionsAvailable(
factory.make_name("msg"), uuid=rack_controller.system_id
)
self.process_request(request, error)
expected_error_message = (
"Error: Unable to connect to rack controller '%s' (%s); no "
"connections available."
% (rack_controller.hostname, rack_controller.system_id)
)
self.assertEqual(
[(constants.ERROR, expected_error_message, "")],
request._messages.messages,
)