当前位置: 首页>>代码示例>>Python>>正文


Python constants.ERROR属性代码示例

本文整理汇总了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) 
开发者ID:pytition,项目名称:Pytition,代码行数:27,代码来源:tests_SignatureViews.py

示例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) 
开发者ID:pytition,项目名称:Pytition,代码行数:25,代码来源:tests_SignatureViews.py

示例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) 
开发者ID:pytition,项目名称:Pytition,代码行数:26,代码来源:tests_SignatureViews.py

示例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) 
开发者ID:pytition,项目名称:Pytition,代码行数:25,代码来源:tests_OrgSetUserPermsView.py

示例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) 
开发者ID:pytition,项目名称:Pytition,代码行数:26,代码来源:tests_OrgSetUserPermsView.py

示例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) 
开发者ID:pytition,项目名称:Pytition,代码行数:26,代码来源:tests_OrgSetUserPermsView.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:20,代码来源:test_move_page.py

示例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) 
开发者ID:wagtail,项目名称:wagtail,代码行数:18,代码来源:test_moderation.py

示例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) 
开发者ID:mathiasertl,项目名称:django-ca,代码行数:26,代码来源:admin.py

示例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
                )
            )) 
开发者ID:edx,项目名称:ecommerce,代码行数:21,代码来源:test_views.py

示例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) 
开发者ID:edx,项目名称:ecommerce,代码行数:19,代码来源:tests.py

示例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) 
开发者ID:nesdis,项目名称:djongo,代码行数:21,代码来源:test_cookie.py

示例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,
        ) 
开发者ID:maas,项目名称:maas,代码行数:18,代码来源:test_middleware.py

示例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,
        ) 
开发者ID:maas,项目名称:maas,代码行数:18,代码来源:test_middleware.py

示例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,
        ) 
开发者ID:maas,项目名称:maas,代码行数:23,代码来源:test_middleware.py


注:本文中的django.contrib.messages.constants.ERROR属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。