Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
ecommerce
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
ecommerce
Commits
f3d06132
Commit
f3d06132
authored
Feb 01, 2017
by
Douglas Hall
Committed by
Douglas Hall
Feb 02, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add course start and end dates to basket view context
parent
2f78785d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
0 deletions
+41
-0
ecommerce/extensions/basket/tests/test_views.py
+21
-0
ecommerce/extensions/basket/views.py
+20
-0
No files found.
ecommerce/extensions/basket/tests/test_views.py
View file @
f3d06132
...
...
@@ -515,6 +515,27 @@ class BasketSummaryViewTests(CourseCatalogTestMixin, CourseCatalogMockMixin, Lms
expected_url
=
'{path}?next={next}'
.
format
(
path
=
testserver_login_url
,
next
=
urllib
.
quote
(
self
.
path
))
self
.
assertRedirects
(
response
,
expected_url
,
target_status_code
=
302
)
@ddt.data
(
(
None
,
None
),
(
'invalid-date'
,
None
),
(
'2017-02-01T00:00:00'
,
datetime
.
datetime
(
2017
,
2
,
1
)),
)
@ddt.unpack
@mock_course_catalog_api_client
@override_settings
(
PAYMENT_PROCESSORS
=
[
'ecommerce.extensions.payment.tests.processors.DummyProcessor'
])
def
test_context_data_contains_course_dates
(
self
,
date_string
,
expected_result
):
seat
=
self
.
create_seat
(
self
.
course
)
self
.
create_basket_and_add_product
(
seat
)
self
.
mock_dynamic_catalog_single_course_runs_api
(
self
.
course
,
{
'start'
:
date_string
,
'end'
:
date_string
})
response
=
self
.
client
.
get
(
self
.
path
)
self
.
assertEqual
(
response
.
status_code
,
200
)
for
_
,
line_data
in
response
.
context
[
'formset_lines_data'
]:
self
.
assertEqual
(
line_data
[
'course_start'
],
expected_result
)
self
.
assertEqual
(
line_data
[
'course_end'
],
expected_result
)
class
VoucherAddMessagesViewTests
(
TestCase
):
""" VoucherAddMessagesView view tests. """
...
...
ecommerce/extensions/basket/views.py
View file @
f3d06132
...
...
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
from
datetime
import
datetime
import
logging
import
dateutil.parser
import
waffle
from
django.http
import
HttpResponseBadRequest
,
HttpResponseRedirect
from
django.utils.translation
import
ugettext_lazy
as
_
...
...
@@ -103,6 +104,14 @@ class BasketSummaryView(BasketView):
seat_type
=
get_certificate_type_display_value
(
product
.
attr
.
seat_type
)
return
seat_type
def
_deserialize_date
(
self
,
date_string
):
date
=
None
try
:
date
=
dateutil
.
parser
.
parse
(
date_string
)
except
(
AttributeError
,
ValueError
):
pass
return
date
def
_get_course_data
(
self
,
product
):
"""
Return course data.
...
...
@@ -116,6 +125,8 @@ class BasketSummaryView(BasketView):
course_name
=
None
image_url
=
None
short_description
=
None
course_start
=
None
course_end
=
None
try
:
course
=
get_course_info_from_catalog
(
self
.
request
.
site
,
course_key
)
...
...
@@ -125,6 +136,13 @@ class BasketSummaryView(BasketView):
image_url
=
''
short_description
=
course
.
get
(
'short_description'
,
''
)
course_name
=
course
.
get
(
'title'
,
''
)
# The course start/end dates are not currently used
# in the default basket templates, but we are adding
# the dates to the template context so that theme
# template overrides can make use of them.
course_start
=
self
.
_deserialize_date
(
course
.
get
(
'start'
))
course_end
=
self
.
_deserialize_date
(
course
.
get
(
'end'
))
except
(
ConnectionError
,
SlumberBaseException
,
Timeout
):
logger
.
exception
(
'Failed to retrieve data from Catalog Service for course [
%
s].'
,
course_key
)
...
...
@@ -133,6 +151,8 @@ class BasketSummaryView(BasketView):
'course_key'
:
course_key
,
'image_url'
:
image_url
,
'product_description'
:
short_description
,
'course_start'
:
course_start
,
'course_end'
:
course_end
,
}
def
_process_basket_lines
(
self
,
lines
):
...
...
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