From f2ea2ca360a87b11b0b54f88deee56bb4eb5286c Mon Sep 17 00:00:00 2001 From: Zia Fazal <zia.fazal@arbisoft.com> Date: Mon, 21 May 2018 13:44:22 +0500 Subject: [PATCH] Added a base MessageType for ace added unit tests updated edx-ace version fixed quality violations Fixed quality violations Changed ACEMessageType to BaseMessageType --- common/djangoapps/student/message_types.py | 9 ++---- lms/djangoapps/discussion/tasks.py | 4 +-- openedx/core/djangoapps/ace_common/message.py | 13 +++++++++ .../ace_common/tests/test_message.py | 29 +++++++++++++++++++ .../djangoapps/schedules/message_types.py | 5 ++-- requirements/edx/base.in | 2 +- requirements/edx/base.txt | 3 +- requirements/edx/development.txt | 3 +- requirements/edx/testing.txt | 3 +- 9 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 openedx/core/djangoapps/ace_common/message.py create mode 100644 openedx/core/djangoapps/ace_common/tests/test_message.py diff --git a/common/djangoapps/student/message_types.py b/common/djangoapps/student/message_types.py index 0aac833376f..da89a2a3f56 100644 --- a/common/djangoapps/student/message_types.py +++ b/common/djangoapps/student/message_types.py @@ -1,17 +1,12 @@ """ ACE message types for the student module. """ -from django.conf import settings -from edx_ace.message import MessageType -from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers +from openedx.core.djangoapps.ace_common.message import BaseMessageType -class PasswordReset(MessageType): +class PasswordReset(BaseMessageType): def __init__(self, *args, **kwargs): super(PasswordReset, self).__init__(*args, **kwargs) self.options['transactional'] = True - self.options['from_address'] = configuration_helpers.get_value( - 'email_from_address', settings.DEFAULT_FROM_EMAIL - ) diff --git a/lms/djangoapps/discussion/tasks.py b/lms/djangoapps/discussion/tasks.py index 2072d36701c..00615027f66 100644 --- a/lms/djangoapps/discussion/tasks.py +++ b/lms/djangoapps/discussion/tasks.py @@ -15,7 +15,6 @@ from celery_utils.logged_task import LoggedTask from django_comment_common.utils import set_course_discussion_settings from edx_ace import ace from edx_ace.utils import date -from edx_ace.message import MessageType from edx_ace.recipient import Recipient from opaque_keys.edx.keys import CourseKey from lms.djangoapps.django_comment_client.utils import permalink, get_accessible_discussion_xblocks_by_course_id @@ -23,6 +22,7 @@ import lms.lib.comment_client as cc from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.ace_common.template_context import get_base_template_context +from openedx.core.djangoapps.ace_common.message import BaseMessageType from openedx.core.lib.celery.task_utils import emulate_http_request @@ -51,7 +51,7 @@ def update_discussions_map(context): set_course_discussion_settings(course_key, discussions_id_map=discussions_id_map) -class ResponseNotification(MessageType): +class ResponseNotification(BaseMessageType): pass diff --git a/openedx/core/djangoapps/ace_common/message.py b/openedx/core/djangoapps/ace_common/message.py new file mode 100644 index 00000000000..e56b875b0bd --- /dev/null +++ b/openedx/core/djangoapps/ace_common/message.py @@ -0,0 +1,13 @@ +""" +Base Message types to be used to construct ace messages. +""" +from edx_ace.message import MessageType +from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers + + +class BaseMessageType(MessageType): + def __init__(self, *args, **kwargs): + super(BaseMessageType, self).__init__(*args, **kwargs) + from_address = configuration_helpers.get_value('email_from_address') + if from_address: + self.options.update({'from_address': from_address}) # pylint: disable=no-member diff --git a/openedx/core/djangoapps/ace_common/tests/test_message.py b/openedx/core/djangoapps/ace_common/tests/test_message.py new file mode 100644 index 00000000000..bb7006d3cc3 --- /dev/null +++ b/openedx/core/djangoapps/ace_common/tests/test_message.py @@ -0,0 +1,29 @@ +""" +Tests for ace message module +""" +import ddt +from mock import patch + +from django.test import TestCase + +from openedx.core.djangoapps.ace_common.message import BaseMessageType + + +@ddt.ddt +class TestAbsoluteUrl(TestCase): + + @ddt.data( + ('test@example.com', True), + ('', False), + (None, False), + ) + @ddt.unpack + def test_from_email_address_in_message(self, from_address, has_from_address): + """ + Tests presence of from_address option in ace message + """ + with patch("openedx.core.djangoapps.site_configuration.helpers.get_value", return_value=from_address): + ace_message_type = BaseMessageType() + self.assertEqual('from_address' in ace_message_type.options, has_from_address) + if from_address: + self.assertEqual(ace_message_type.options.get('from_address'), from_address) diff --git a/openedx/core/djangoapps/schedules/message_types.py b/openedx/core/djangoapps/schedules/message_types.py index 187d3149f4f..029edb3d8fb 100644 --- a/openedx/core/djangoapps/schedules/message_types.py +++ b/openedx/core/djangoapps/schedules/message_types.py @@ -1,11 +1,10 @@ import logging -from edx_ace.message import MessageType - +from openedx.core.djangoapps.ace_common.message import BaseMessageType from openedx.core.djangoapps.schedules.config import DEBUG_MESSAGE_WAFFLE_FLAG -class ScheduleMessageType(MessageType): +class ScheduleMessageType(BaseMessageType): def __init__(self, *args, **kwargs): super(ScheduleMessageType, self).__init__(*args, **kwargs) self.log_level = logging.DEBUG if DEBUG_MESSAGE_WAFFLE_FLAG.is_enabled() else None diff --git a/requirements/edx/base.in b/requirements/edx/base.in index 27ed86bf2d8..0f4fad2da93 100644 --- a/requirements/edx/base.in +++ b/requirements/edx/base.in @@ -64,7 +64,7 @@ django-waffle==0.12.0 django-webpack-loader==0.4.1 djangorestframework-jwt dogapi==1.2.1 # Python bindings to Datadog's API, for metrics gathering -edx-ace==0.1.7 +edx-ace==0.1.8 edx-analytics-data-api-client edx-ccx-keys edx-celeryutils diff --git a/requirements/edx/base.txt b/requirements/edx/base.txt index a41ad6d6310..50b42638bd2 100644 --- a/requirements/edx/base.txt +++ b/requirements/edx/base.txt @@ -4,7 +4,6 @@ # # make upgrade # - -e git+https://github.com/edx/acid-block.git@e46f9cda8a03e121a00c7e347084d142d22ebfb7#egg=acid-xblock -e common/lib/calc -e common/lib/capa @@ -109,7 +108,7 @@ dm.xmlsec.binding==1.3.3 # via python-saml docopt==0.6.2 docutils==0.14 # via botocore dogapi==1.2.1 -edx-ace==0.1.7 +edx-ace==0.1.8 edx-analytics-data-api-client==0.14.4 edx-ccx-keys==0.2.1 edx-celeryutils==0.2.7 diff --git a/requirements/edx/development.txt b/requirements/edx/development.txt index b82870b7e1f..e9c66a19413 100644 --- a/requirements/edx/development.txt +++ b/requirements/edx/development.txt @@ -4,7 +4,6 @@ # # make upgrade # - -e git+https://github.com/edx/acid-block.git@e46f9cda8a03e121a00c7e347084d142d22ebfb7#egg=acid-xblock -e common/lib/calc -e common/lib/capa @@ -128,7 +127,7 @@ dm.xmlsec.binding==1.3.3 docopt==0.6.2 docutils==0.14 dogapi==1.2.1 -edx-ace==0.1.7 +edx-ace==0.1.8 edx-analytics-data-api-client==0.14.4 edx-ccx-keys==0.2.1 edx-celeryutils==0.2.7 diff --git a/requirements/edx/testing.txt b/requirements/edx/testing.txt index 065b6370320..1da7dd87e59 100644 --- a/requirements/edx/testing.txt +++ b/requirements/edx/testing.txt @@ -4,7 +4,6 @@ # # make upgrade # - -e git+https://github.com/edx/acid-block.git@e46f9cda8a03e121a00c7e347084d142d22ebfb7#egg=acid-xblock -e common/lib/calc -e common/lib/capa @@ -123,7 +122,7 @@ dm.xmlsec.binding==1.3.3 docopt==0.6.2 docutils==0.14 dogapi==1.2.1 -edx-ace==0.1.7 +edx-ace==0.1.8 edx-analytics-data-api-client==0.14.4 edx-ccx-keys==0.2.1 edx-celeryutils==0.2.7 -- GitLab