From eb50f4d38bef6e5bb8fa635e0717254e8ad68e75 Mon Sep 17 00:00:00 2001 From: Renzo Lucioni Date: Wed, 28 Sep 2016 17:20:53 -0400 Subject: [PATCH] Leverage the catalog's exclude_utm parameter We don't need stripping code on this end anymore. This closes out ECOM-5782. --- .../djangoapps/catalog/tests/test_utils.py | 36 ++++--------------- openedx/core/djangoapps/catalog/utils.py | 25 ++++--------- 2 files changed, 12 insertions(+), 49 deletions(-) diff --git a/openedx/core/djangoapps/catalog/tests/test_utils.py b/openedx/core/djangoapps/catalog/tests/test_utils.py index 74e938585e..38fd07776f 100644 --- a/openedx/core/djangoapps/catalog/tests/test_utils.py +++ b/openedx/core/djangoapps/catalog/tests/test_utils.py @@ -48,7 +48,10 @@ class TestGetPrograms(mixins.CatalogIntegrationMixin, TestCase): self.assertEqual(kwargs['api']._store['base_url'], self.catalog_integration.internal_api_url) # pylint: disable=protected-access - querystring = {'marketable': 1} + querystring = { + 'marketable': 1, + 'exclude_utm': 1, + } if type: querystring['type'] = type self.assertEqual(kwargs['querystring'], querystring) @@ -214,7 +217,6 @@ class TestGetCourseRun(mixins.CatalogIntegrationMixin, TestCase): @mock.patch(UTILS_MODULE + '.get_course_run') -@mock.patch(UTILS_MODULE + '.strip_querystring') class TestGetRunMarketingUrl(TestCase): """Tests covering retrieval of course run marketing URLs.""" def setUp(self): @@ -223,43 +225,17 @@ class TestGetRunMarketingUrl(TestCase): self.course_key = CourseKey.from_string('foo/bar/baz') self.user = UserFactory() - def test_get_run_marketing_url(self, mock_strip, mock_get_course_run): + def test_get_run_marketing_url(self, mock_get_course_run): course_run = factories.CourseRun() mock_get_course_run.return_value = course_run - mock_strip.return_value = course_run['marketing_url'] url = utils.get_run_marketing_url(self.course_key, self.user) - self.assertTrue(mock_strip.called) self.assertEqual(url, course_run['marketing_url']) - def test_marketing_url_empty(self, mock_strip, mock_get_course_run): - course_run = factories.CourseRun() - course_run['marketing_url'] = '' - mock_get_course_run.return_value = course_run - - url = utils.get_run_marketing_url(self.course_key, self.user) - - self.assertFalse(mock_strip.called) - self.assertEqual(url, None) - - def test_marketing_url_missing(self, mock_strip, mock_get_course_run): + def test_marketing_url_missing(self, mock_get_course_run): mock_get_course_run.return_value = {} url = utils.get_run_marketing_url(self.course_key, self.user) - self.assertFalse(mock_strip.called) self.assertEqual(url, None) - - -@ddt.ddt -class TestStripQuerystring(TestCase): - """Tests covering querystring stripping.""" - bare_url = 'https://www.example.com/path' - - @ddt.data( - bare_url, - bare_url + '?foo=bar&baz=qux', - ) - def test_strip_querystring(self, url): - self.assertEqual(utils.strip_querystring(url), self.bare_url) diff --git a/openedx/core/djangoapps/catalog/utils.py b/openedx/core/djangoapps/catalog/utils.py index 48e5b83417..59daf88692 100644 --- a/openedx/core/djangoapps/catalog/utils.py +++ b/openedx/core/djangoapps/catalog/utils.py @@ -40,7 +40,10 @@ def get_programs(user, uuid=None, type=None): # pylint: disable=redefined-built type='.' + type if type else '' ) - querystring = {'marketable': 1} + querystring = { + 'marketable': 1, + 'exclude_utm': 1, + } if type: querystring['type'] = type @@ -133,6 +136,7 @@ def get_course_run(course_key, user): resource_id=unicode(course_key), cache_key=catalog_integration.CACHE_KEY if catalog_integration.is_cache_enabled else None, api=api, + querystring={'exclude_utm': 1}, ) return data if data else {} @@ -151,21 +155,4 @@ def get_run_marketing_url(course_key, user): string, the marketing URL, or None if no URL is available. """ course_run = get_course_run(course_key, user) - marketing_url = course_run.get('marketing_url') - - if marketing_url: - # This URL may include unwanted UTM parameters in the querystring. - # For more, see https://en.wikipedia.org/wiki/UTM_parameters. - return strip_querystring(marketing_url) - else: - return None - - -def strip_querystring(url): - """Strip the querystring from the provided URL. - - urlparse's ParseResult is a subclass of namedtuple. _replace is part of namedtuple's - public API: https://docs.python.org/2/library/collections.html#collections.somenamedtuple._replace. - The name starts with an underscore to prevent conflicts with field names. - """ - return urlparse(url)._replace(query='').geturl() # pylint: disable=no-member + return course_run.get('marketing_url')