Python django.contrib.messages.constants.SUCCESS Examples
The following are 26
code examples of django.contrib.messages.constants.SUCCESS().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.contrib.messages.constants
, or try the search function
.
Example #1
Source File: test_moderation.py From wagtail with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #2
Source File: tests.py From ecommerce with GNU Affero General Public License v3.0 | 6 votes |
def test_create_refund(self): """Verify the view creates a Refund for the Order and selected Lines.""" # Create Order and Lines order = self.create_order(user=self.user) self.assertFalse(order.refunds.exists()) # Validate the Refund response = self._request_refund(order) refund = Refund.objects.latest() self.assert_refund_matches_order(refund, order) # Verify a message was passed for display data = { 'link_start': '<a href="{}" target="_blank">'.format( reverse('dashboard:refunds-detail', kwargs={'pk': refund.pk})), 'link_end': '</a>', 'refund_id': refund.pk } expected = '{link_start}Refund #{refund_id}{link_end} created! ' \ 'Click {link_start}here{link_end} to view it.'.format(**data) self.assert_message_equals(response, expected, MSG.SUCCESS)
Example #3
Source File: api.py From bioforum with MIT License | 5 votes |
def success(request, message, extra_tags='', fail_silently=False): """Add a message with the ``SUCCESS`` level.""" add_message(request, constants.SUCCESS, message, extra_tags=extra_tags, fail_silently=fail_silently)
Example #4
Source File: background_messages.py From feedsubs with MIT License | 5 votes |
def success(user, message): """ Adds a message with the ``SUCCESS`` level. :param user: User instance :param message: Message to show """ message_user(user, message, constants.SUCCESS)
Example #5
Source File: form_views.py From django-is-core with BSD 3-Clause "New" or "Revised" License | 5 votes |
def success_render_to_response(self, obj, msg, msg_level): msg_level = msg_level or constants.SUCCESS msg = msg or self.get_message(msg_level, obj) if self.is_popup_form: return JsonHttpResponse({'messages': {msg_level: msg}, 'obj': self.get_popup_obj(obj)}) elif self.is_ajax_form: add_message(self.request, msg_level, msg) location = self.get_success_url(obj) response = JsonHttpResponse({'location': location}, status=202) response['Location'] = location return response else: add_message(self.request, msg_level, msg) return HttpResponseRedirect(self.get_success_url(obj))
Example #6
Source File: base_tags.py From jorvik with GNU General Public License v3.0 | 5 votes |
def level_to_bootstrap(message): map = { constants.DEBUG: 'alert-info', constants.INFO: 'alert-info', constants.SUCCESS: 'alert-success', constants.WARNING: 'alert-warning', constants.ERROR: 'alert-danger', } return map.get(message.level, 'alert-info')
Example #7
Source File: messages.py From avos with Apache License 2.0 | 5 votes |
def success(request, message, extra_tags='', fail_silently=False): """Adds a message with the ``SUCCESS`` level.""" add_message(request, constants.SUCCESS, message, extra_tags=extra_tags, fail_silently=fail_silently)
Example #8
Source File: utils.py From esdc-ce with Apache License 2.0 | 5 votes |
def success(self, msg): self.add_message(constants.SUCCESS, msg)
Example #9
Source File: utils.py From esdc-ce with Apache License 2.0 | 5 votes |
def __init__(self, msg=None, level=constants.SUCCESS): if msg: self.add_message(level, msg)
Example #10
Source File: base.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def add_level_messages(storage): """ Add 6 messages from different levels (including a custom one) to a storage instance. """ storage.add(constants.INFO, 'A generic info message') storage.add(29, 'Some custom level') storage.add(constants.DEBUG, 'A debugging message', extra_tags='extra-tag') storage.add(constants.WARNING, 'A warning') storage.add(constants.ERROR, 'An error') storage.add(constants.SUCCESS, 'This was a triumph.')
Example #11
Source File: base.py From djongo with GNU Affero General Public License v3.0 | 5 votes |
def add_level_messages(storage): """ Add 6 messages from different levels (including a custom one) to a storage instance. """ storage.add(constants.INFO, 'A generic info message') storage.add(29, 'Some custom level') storage.add(constants.DEBUG, 'A debugging message', extra_tags='extra-tag') storage.add(constants.WARNING, 'A warning') storage.add(constants.ERROR, 'An error') storage.add(constants.SUCCESS, 'This was a triumph.')
Example #12
Source File: messages.py From Inboxen with GNU Affero General Public License v3.0 | 5 votes |
def success(user, message): """ Adds a message with the ``SUCCESS`` level. :param user: User instance :param message: Message to show """ message_user(user, message, constants.SUCCESS)
Example #13
Source File: tests.py From Inboxen with GNU Affero General Public License v3.0 | 5 votes |
def test_success(self): messages.success(self.user, "Hello") self.assertMessageOk(constants.SUCCESS)
Example #14
Source File: extra_filters.py From Kiwi with GNU General Public License v2.0 | 5 votes |
def message_icon(msg): """ Returns the string class name of a message icon which feeds directly into Patternfly. """ icons = { messages.ERROR: 'error-circle-o', messages.WARNING: 'warning-triangle-o', messages.SUCCESS: 'ok', messages.INFO: 'info', } return 'pficon-' + icons[msg.level]
Example #15
Source File: test_view.py From edx-enterprise with GNU Affero General Public License v3.0 | 5 votes |
def test_post_link_and_enroll_no_notification( self, forms_client, views_client, track_enrollment, ): """ Test bulk upload with linking and enrolling """ views_instance = views_client.return_value views_instance.enroll_user_in_course.side_effect = fake_enrollment_api.enroll_user_in_course forms_instance = forms_client.return_value forms_instance.get_course_details.side_effect = fake_enrollment_api.get_course_details self._login() user = UserFactory.create() unknown_email = FAKER.email() # pylint: disable=no-member columns = [ManageLearnersForm.CsvColumns.EMAIL] data = [(user.email,), (unknown_email,)] course_id = "course-v1:EnterpriseX+Training+2017" course_mode = "professional" response = self._perform_request(columns, data, course=course_id, course_mode=course_mode, notify=False) views_instance.enroll_user_in_course.assert_called_once_with( user.username, course_id, course_mode ) track_enrollment.assert_called_once_with('admin-enrollment', user.id, course_id) pending_user_message = ( "The following learners do not have an account on Test platform. They have not been enrolled in {}. " "When these learners create an account, they will be enrolled automatically: {}" ) self._assert_django_messages(response, set([ (messages.SUCCESS, "2 new learners were added to {}.".format(self.enterprise_customer.name)), (messages.SUCCESS, "1 learner was enrolled in {}.".format(course_id)), (messages.WARNING, pending_user_message.format(course_id, unknown_email)), ])) assert PendingEnterpriseCustomerUser.objects.all()[0].pendingenrollment_set.all()[0].course_id == course_id num_messages = len(mail.outbox) assert num_messages == 0
Example #16
Source File: test_view.py From edx-enterprise with GNU Affero General Public License v3.0 | 5 votes |
def test_post_enroll_no_course_detail( self, forms_client, views_client, course_catalog_client, track_enrollment, ): catalog_instance = course_catalog_client.return_value catalog_instance.get_course_run.return_value = {} views_instance = views_client.return_value views_instance.enroll_user_in_course.side_effect = fake_enrollment_api.enroll_user_in_course forms_instance = forms_client.return_value forms_instance.get_course_details.side_effect = fake_enrollment_api.get_course_details user = UserFactory(id=2) course_id = "course-v1:HarvardX+CoolScience+2016" mode = "verified" response = self._enroll_user_request(user, mode, course_id=course_id) views_instance.enroll_user_in_course.assert_called_once_with( user.username, course_id, mode, ) track_enrollment.assert_called_once_with('admin-enrollment', user.id, course_id) self._assert_django_messages(response, set([ (messages.SUCCESS, "1 learner was enrolled in {}.".format(course_id)), ])) all_enterprise_enrollments = EnterpriseCourseEnrollment.objects.all() num_enterprise_enrollments = len(all_enterprise_enrollments) assert num_enterprise_enrollments == 1 enrollment = all_enterprise_enrollments[0] assert enrollment.enterprise_customer_user.user == user assert enrollment.course_id == course_id num_messages = len(mail.outbox) assert num_messages == 0
Example #17
Source File: api.py From python2017 with MIT License | 5 votes |
def success(request, message, extra_tags='', fail_silently=False): """ Adds a message with the ``SUCCESS`` level. """ add_message(request, constants.SUCCESS, message, extra_tags=extra_tags, fail_silently=fail_silently)
Example #18
Source File: api.py From openhgsenti with Apache License 2.0 | 5 votes |
def success(request, message, extra_tags='', fail_silently=False): """ Adds a message with the ``SUCCESS`` level. """ add_message(request, constants.SUCCESS, message, extra_tags=extra_tags, fail_silently=fail_silently)
Example #19
Source File: api.py From Hands-On-Application-Development-with-PyCharm with MIT License | 5 votes |
def success(request, message, extra_tags='', fail_silently=False): """Add a message with the ``SUCCESS`` level.""" add_message(request, constants.SUCCESS, message, extra_tags=extra_tags, fail_silently=fail_silently)
Example #20
Source File: api.py From GTDWeb with GNU General Public License v2.0 | 5 votes |
def success(request, message, extra_tags='', fail_silently=False): """ Adds a message with the ``SUCCESS`` level. """ add_message(request, constants.SUCCESS, message, extra_tags=extra_tags, fail_silently=fail_silently)
Example #21
Source File: test_view.py From edx-enterprise with GNU Affero General Public License v3.0 | 4 votes |
def test_post_link_and_enroll_no_course_details( self, forms_client, views_client, course_catalog_client, track_enrollment, ): """ Test bulk upload with linking and enrolling """ course_catalog_instance = course_catalog_client.return_value course_catalog_instance.get_course_run.return_value = {} views_instance = views_client.return_value views_instance.enroll_user_in_course.side_effect = fake_enrollment_api.enroll_user_in_course forms_instance = forms_client.return_value forms_instance.get_course_details.side_effect = fake_enrollment_api.get_course_details self._login() user = UserFactory.create() unknown_email = FAKER.email() # pylint: disable=no-member columns = [ManageLearnersForm.CsvColumns.EMAIL] data = [(user.email,), (unknown_email,)] course_id = "course-v1:EnterpriseX+Training+2017" course_mode = "professional" response = self._perform_request(columns, data, course=course_id, course_mode=course_mode) views_instance.enroll_user_in_course.assert_called_once_with( user.username, course_id, course_mode ) track_enrollment.assert_called_once_with('admin-enrollment', user.id, course_id) pending_user_message = ( "The following learners do not have an account on Test platform. " "They have not been enrolled in {}. When these learners create an " "account, they will be enrolled automatically: {}" ) self._assert_django_messages(response, set([ (messages.SUCCESS, "2 new learners were added to {}.".format(self.enterprise_customer.name)), (messages.SUCCESS, "1 learner was enrolled in {}.".format(course_id)), (messages.WARNING, pending_user_message.format(course_id, unknown_email)), ])) assert PendingEnterpriseCustomerUser.objects.all()[0].pendingenrollment_set.all()[0].course_id == course_id num_messages = len(mail.outbox) assert num_messages == 0
Example #22
Source File: test_view.py From edx-enterprise with GNU Affero General Public License v3.0 | 4 votes |
def test_post_link_and_enroll( self, forms_client, views_client, course_catalog_client, track_enrollment, ): """ Test bulk upload with linking and enrolling """ discount_percentage = 20.0 sales_force_id = 'dummy-sales_force_id' self.required_fields_with_default[ManageLearnersForm.Fields.DISCOUNT] = discount_percentage self.required_fields_with_default[ManageLearnersForm.Fields.SALES_FORCE_ID] = sales_force_id course_catalog_instance = course_catalog_client.return_value course_catalog_instance.get_course_run.return_value = { "name": "Enterprise Training", "start": "2017-01-01T12:00:00Z", "marketing_url": "http://localhost/course-v1:EnterpriseX+Training+2017" } views_instance = views_client.return_value views_instance.enroll_user_in_course.side_effect = fake_enrollment_api.enroll_user_in_course forms_instance = forms_client.return_value forms_instance.get_course_details.side_effect = fake_enrollment_api.get_course_details self._login() user = UserFactory.create() unknown_email = FAKER.email() # pylint: disable=no-member columns = [ManageLearnersForm.CsvColumns.EMAIL] data = [(user.email,), (unknown_email,)] course_id = "course-v1:EnterpriseX+Training+2017" course_mode = "professional" response = self._perform_request(columns, data, course=course_id, course_mode=course_mode) views_instance.enroll_user_in_course.assert_called_once_with( user.username, course_id, course_mode ) track_enrollment.assert_called_once_with('admin-enrollment', user.id, course_id) pending_user_message = ( "The following learners do not have an account on Test platform. " "They have not been enrolled in {}. When these learners create an " "account, they will be enrolled automatically: {}" ) self._assert_django_messages(response, set([ (messages.SUCCESS, "2 new learners were added to {}.".format(self.enterprise_customer.name)), (messages.SUCCESS, "1 learner was enrolled in {}.".format(course_id)), (messages.WARNING, pending_user_message.format(course_id, unknown_email)), ])) pending_enrollment = PendingEnterpriseCustomerUser.objects.all()[0].pendingenrollment_set.all()[0] assert pending_enrollment.course_id == course_id assert pending_enrollment.discount_percentage == discount_percentage assert pending_enrollment.sales_force_id == sales_force_id num_messages = len(mail.outbox) assert num_messages == 2
Example #23
Source File: test_view.py From edx-enterprise with GNU Affero General Public License v3.0 | 4 votes |
def test_post_existing_and_duplicates(self): """ Test that duplicates and existing links are handled correctly. 1. Users already linked to an EnterpriseCustomer should cause a warning message, and an additional link won't be created, but otherwise will behave normally. 2. Users that appear in a CSV twice will be ignored and a message will be created. 3. Users that are attached to a different EnterpriseCustomer will be ignored, and a message will be created. """ self._login() user = UserFactory(id=2) linked_user = UserFactory(id=3) user_linked_to_other_ec = UserFactory(id=4) EnterpriseCustomerUserFactory(user_id=user_linked_to_other_ec.id) EnterpriseCustomerUserFactory(user_id=linked_user.id, enterprise_customer=self.enterprise_customer) new_email = FAKER.email() # pylint: disable=no-member assert EnterpriseCustomerUser.objects.count() == 2, "Precondition check: Two linked users" assert EnterpriseCustomerUser.objects.filter(user_id=linked_user.id).exists() assert EnterpriseCustomerUser.objects.filter(user_id=user_linked_to_other_ec.id).exists() assert not PendingEnterpriseCustomerUser.objects.exists(), "Precondition check: no pending user links" columns = [ManageLearnersForm.CsvColumns.EMAIL] data = [ (linked_user.email,), # a user that is already linked to this EC (new_email,), # valid not previously seen email (user.email,), # valid user email (user.email,), # valid user email repeated (user_linked_to_other_ec.email,), # valid user email linked to a different EC ] response = self._perform_request(columns, data) assert EnterpriseCustomerUser.objects.count() == 3, \ "Two linked users remain, and one new link is created" assert EnterpriseCustomerUser.objects.filter(user_id=linked_user.id).exists() assert EnterpriseCustomerUser.objects.filter(user_id=user.id).exists() assert PendingEnterpriseCustomerUser.objects.count() == 1, "One pending linked users should be created" assert PendingEnterpriseCustomerUser.objects.filter(user_email=new_email).exists() self._assert_django_messages(response, set([ (messages.SUCCESS, "2 new learners were added to {}.".format(self.enterprise_customer.name)), ( messages.WARNING, "The following learners were already associated with this " "Enterprise Customer: {}".format(linked_user.email) ), (messages.WARNING, "The following duplicate email addresses were not added: {}".format(user.email)), ( messages.WARNING, "The following learners are already associated with another Enterprise Customer. " "These learners were not added to {}: {}".format( self.enterprise_customer.name, user_linked_to_other_ec.email ) ) ]))
Example #24
Source File: test_view.py From edx-enterprise with GNU Affero General Public License v3.0 | 4 votes |
def test_post_enroll_with_missing_course_start_date( self, forms_client, views_client, course_catalog_client, track_enrollment, ): """ Test that learner is added successfully if course does not have a start date. If admin tries to add a learner to a course that does not have a start date then learner should be enrolled successfully without any errors and learner should receive an email about the enrollment. """ catalog_instance = course_catalog_client.return_value catalog_instance.get_course_run.return_value = { "title": "Cool Science", "start": None, "marketing_url": "http://lms.example.com/courses/course-v1:HarvardX+CoolScience+2016" } views_instance = views_client.return_value views_instance.enroll_user_in_course.side_effect = fake_enrollment_api.enroll_user_in_course forms_instance = forms_client.return_value forms_instance.get_course_details.side_effect = fake_enrollment_api.get_course_details user = UserFactory(id=2) course_id = "course-v1:HarvardX+CoolScience+2016" mode = "verified" response = self._enroll_user_request(user, mode, course_id=course_id) views_instance.enroll_user_in_course.assert_called_once_with( user.username, course_id, mode, ) track_enrollment.assert_called_once_with('admin-enrollment', user.id, course_id) self._assert_django_messages(response, set([ (messages.SUCCESS, "1 learner was enrolled in {}.".format(course_id)), ])) all_enterprise_enrollments = EnterpriseCourseEnrollment.objects.all() num_enterprise_enrollments = len(all_enterprise_enrollments) assert num_enterprise_enrollments == 1 enrollment = all_enterprise_enrollments[0] assert enrollment.enterprise_customer_user.user == user assert enrollment.course_id == course_id num_messages = len(mail.outbox) assert num_messages == 1
Example #25
Source File: test_view.py From edx-enterprise with GNU Affero General Public License v3.0 | 4 votes |
def test_post_enroll_course_when_enrollment_closed( self, forms_client, views_client, course_catalog_client, track_enrollment, ): """ Tests scenario when user being enrolled has already SCE(student CourseEnrollment) record and course enrollment window is closed """ catalog_instance = course_catalog_client.return_value catalog_instance.get_course_run.return_value = {} views_instance = views_client.return_value views_instance.enroll_user_in_course.side_effect = HttpClientError( "Client Error", content=json.dumps({"message": "Enrollment closed"}).encode() ) views_instance.get_course_enrollment.side_effect = fake_enrollment_api.get_course_enrollment forms_instance = forms_client.return_value forms_instance.get_course_details.side_effect = fake_enrollment_api.get_course_details user = UserFactory(id=2) course_id = "course-v1:HarvardX+CoolScience+2016" mode = "verified" response = self._enroll_user_request(user, mode, course_id=course_id) views_instance.enroll_user_in_course.assert_called_once_with( user.username, course_id, mode, ) track_enrollment.assert_called_once_with('admin-enrollment', user.id, course_id) self._assert_django_messages(response, { (messages.SUCCESS, "1 learner was enrolled in {}.".format(course_id)), }) all_enterprise_enrollments = EnterpriseCourseEnrollment.objects.all() num_enterprise_enrollments = len(all_enterprise_enrollments) assert num_enterprise_enrollments == 1 enrollment = all_enterprise_enrollments[0] assert enrollment.enterprise_customer_user.user == user assert enrollment.course_id == course_id num_messages = len(mail.outbox) assert num_messages == 0
Example #26
Source File: test_view.py From edx-enterprise with GNU Affero General Public License v3.0 | 4 votes |
def test_post_enroll_user( self, enrollment_exists, audit_mode, forms_client, views_client, course_catalog_client, track_enrollment, ecommerce_api_client_mock ): catalog_instance = course_catalog_client.return_value catalog_instance.get_course_run.return_value = { "title": "Cool Science", "start": "2017-01-01T12:00:00Z", "marketing_url": "http://lms.example.com/courses/course-v1:HarvardX+CoolScience+2016" } views_instance = views_client.return_value views_instance.enroll_user_in_course.side_effect = fake_enrollment_api.enroll_user_in_course forms_instance = forms_client.return_value forms_instance.get_course_details.side_effect = fake_enrollment_api.get_course_details user = UserFactory(id=2) course_id = "course-v1:HarvardX+CoolScience+2016" mode = "audit" if audit_mode else "verified" if enrollment_exists: enterprise_customer_user = EnterpriseCustomerUser.objects.create( enterprise_customer=self.enterprise_customer, user_id=user.id, ) EnterpriseCourseEnrollment.objects.create( enterprise_customer_user=enterprise_customer_user, course_id=course_id, ) response = self._enroll_user_request(user, mode, course_id=course_id) if audit_mode: ecommerce_api_client_mock.assert_not_called() else: ecommerce_api_client_mock.assert_called_once() views_instance.enroll_user_in_course.assert_called_once_with( user.username, course_id, mode, ) if enrollment_exists: track_enrollment.assert_not_called() else: track_enrollment.assert_called_once_with('admin-enrollment', user.id, course_id) self._assert_django_messages(response, set([ (messages.SUCCESS, "1 learner was enrolled in {}.".format(course_id)), ])) all_enterprise_enrollments = EnterpriseCourseEnrollment.objects.all() num_enterprise_enrollments = len(all_enterprise_enrollments) assert num_enterprise_enrollments == 1 enrollment = all_enterprise_enrollments[0] assert enrollment.enterprise_customer_user.user == user assert enrollment.course_id == course_id if not enrollment_exists: assert enrollment.source is not None assert enrollment.source.slug == EnterpriseEnrollmentSource.MANUAL num_messages = len(mail.outbox) assert num_messages == 1