feat: Pass segment properties (#30919)

- For new enrollment email pass extra segment event properties.
VAN-999
This commit is contained in:
Mubbshar Anwar
2022-09-05 16:55:46 +05:00
committed by GitHub
parent cb9e6d4841
commit 22b378e605
12 changed files with 368 additions and 27 deletions

View File

@@ -76,6 +76,11 @@ class FieldOverridePerformanceTestCase(FieldOverrideTestMixin, ProceduralCourseT
self.course = None
self.ccx = None
patch_context = mock.patch('common.djangoapps.student.helpers.get_course_dates_for_email')
get_course = patch_context.start()
get_course.return_value = []
self.addCleanup(patch_context.stop)
def setup_course(self, size, enable_ccx, view_as_ccx):
"""
Build a gradable course where each node has `size` children.

View File

@@ -36,8 +36,7 @@ class DateSummarySerializer(serializers.Serializer):
def get_link(self, block):
if block.link:
request = self.context.get('request')
return request.build_absolute_uri(block.link)
return block.link
return ''
def get_first_component_block_id(self, block):

View File

@@ -7,6 +7,7 @@ import logging
from collections import defaultdict, namedtuple
from datetime import datetime
import six
import pytz
from crum import get_current_request
from dateutil.parser import parse as parse_date
@@ -494,6 +495,28 @@ def date_block_key_fn(block):
return block.date or datetime.max.replace(tzinfo=pytz.UTC)
def _get_absolute_url(request, url_path):
"""Construct an absolute URL back to the site.
Arguments:
request (request): request object.
url_path (string): The path of the URL.
Returns:
URL
"""
if not url_path:
return ''
if request:
return request.build_absolute_uri(url_path)
site_name = configuration_helpers.get_value('SITE_NAME', settings.SITE_NAME)
parts = ("https" if settings.HTTPS == "on" else "http", site_name, url_path, '', '', '')
return six.moves.urllib.parse.urlunparse(parts)
def get_course_assignment_date_blocks(course, user, request, num_return=None,
include_past_dates=False, include_access=False):
"""
@@ -510,7 +533,7 @@ def get_course_assignment_date_blocks(course, user, request, num_return=None,
date_block.complete = assignment.complete
date_block.assignment_type = assignment.assignment_type
date_block.past_due = assignment.past_due
date_block.link = request.build_absolute_uri(assignment.url) if assignment.url else ''
date_block.link = _get_absolute_url(request, assignment.url)
date_block.set_title(assignment.title, link=assignment.url)
date_block._extra_info = assignment.extra_info # pylint: disable=protected-access
date_blocks.append(date_block)

View File

@@ -338,8 +338,10 @@ class IndexQueryTestCase(ModuleStoreTestCase):
"""
NUM_PROBLEMS = 20
def test_index_query_counts(self):
@patch('common.djangoapps.student.helpers.get_course_dates_for_email')
def test_index_query_counts(self, mock_course_dates_for_email):
# TODO: decrease query count as part of REVO-28
mock_course_dates_for_email.return_value = []
ContentTypeGatingConfig.objects.create(enabled=True, enabled_as_of=datetime(2018, 1, 1))
with self.store.default_store(ModuleStoreEnum.Type.split):
course = CourseFactory.create()
@@ -350,6 +352,20 @@ class IndexQueryTestCase(ModuleStoreTestCase):
for _ in range(self.NUM_PROBLEMS):
ItemFactory.create(category='problem', parent_location=vertical.location)
course_run = CourseRunFactory.create(key=course.id)
course_run['title'] = course.display_name
course_run['short_description'] = None
course_run['marketing_url'] = 'www.edx.org'
course_run['pacing_type'] = 'self_paced'
course_run['banner_image_url'] = ''
course_run['min_effort'] = 1
course_run['enrollment_count'] = 12345
patch_course_data = patch('openedx.core.djangoapps.catalog.api.get_course_run_details')
course_data = patch_course_data.start()
course_data.return_value = course_run
self.addCleanup(patch_course_data.stop)
self.client.login(username=self.user.username, password=self.user_password)
CourseEnrollment.enroll(self.user, course.id)