Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
51c2444d
Commit
51c2444d
authored
Sep 30, 2016
by
Renzo Lucioni
Committed by
GitHub
Sep 30, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #13601 from edx/renzo/exclude-utm
Leverage the catalog's exclude_utm parameter
parents
e4c626d3
eb50f4d3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
49 deletions
+12
-49
openedx/core/djangoapps/catalog/tests/test_utils.py
+6
-30
openedx/core/djangoapps/catalog/utils.py
+6
-19
No files found.
openedx/core/djangoapps/catalog/tests/test_utils.py
View file @
51c2444d
...
...
@@ -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
)
openedx/core/djangoapps/catalog/utils.py
View file @
51c2444d
...
...
@@ -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'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment