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
569727e6
Commit
569727e6
authored
Aug 22, 2013
by
Diana Huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Pep8 fixes
parent
d7e311f5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
7 deletions
+20
-7
common/lib/xmodule/xmodule/course_module.py
+0
-0
lms/djangoapps/shoppingcart/tests/test_models.py
+14
-1
lms/djangoapps/shoppingcart/tests/test_views.py
+5
-5
lms/djangoapps/shoppingcart/views.py
+1
-1
No files found.
common/lib/xmodule/xmodule/course_module.py
View file @
569727e6
This diff is collapsed.
Click to expand it.
lms/djangoapps/shoppingcart/tests/test_models.py
View file @
569727e6
...
...
@@ -3,8 +3,10 @@ Tests for the Shopping Cart Models
"""
from
factory
import
DjangoModelFactory
from
mock
import
patch
from
django.test
import
TestCase
from
django.test.utils
import
override_settings
from
django.db
import
DatabaseError
from
xmodule.modulestore.tests.django_utils
import
ModuleStoreTestCase
from
xmodule.modulestore.tests.factories
import
CourseFactory
from
courseware.tests.tests
import
TEST_DATA_MONGO_MODULESTORE
...
...
@@ -12,7 +14,7 @@ from shoppingcart.models import Order, OrderItem, CertificateItem, InvalidCartIt
from
student.tests.factories
import
UserFactory
from
student.models
import
CourseEnrollment
from
course_modes.models
import
CourseMode
from
.
.exceptions
import
PurchasedCallbackException
from
shoppingcart
.exceptions
import
PurchasedCallbackException
class
OrderTest
(
TestCase
):
...
...
@@ -74,6 +76,17 @@ class OrderTest(TestCase):
cart
.
purchase
()
self
.
assertTrue
(
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course_id
))
def
test_purchase_item_failure
(
self
):
# once again, we're testing against the specific implementation of
# CertificateItem
cart
=
Order
.
get_cart_for_user
(
user
=
self
.
user
)
CertificateItem
.
add_to_order
(
cart
,
self
.
course_id
,
self
.
cost
,
'verified'
)
with
patch
(
'shoppingcart.models.CertificateItem.save'
,
side_effect
=
DatabaseError
):
with
self
.
assertRaises
(
DatabaseError
):
cart
.
purchase
()
# verify that we rolled back the entire transaction
self
.
assertFalse
(
CourseEnrollment
.
is_enrolled
(
self
.
user
,
self
.
course_id
))
class
OrderItemTest
(
TestCase
):
def
setUp
(
self
):
...
...
lms/djangoapps/shoppingcart/tests/test_views.py
View file @
569727e6
...
...
@@ -22,6 +22,7 @@ from mitxmako.shortcuts import render_to_response
from
shoppingcart.processors
import
render_purchase_form_html
,
process_postpay_callback
from
mock
import
patch
,
Mock
def
mock_render_purchase_form_html
(
*
args
,
**
kwargs
):
return
render_purchase_form_html
(
*
args
,
**
kwargs
)
...
...
@@ -34,6 +35,7 @@ render_mock = Mock(side_effect=mock_render_to_response)
postpay_mock
=
Mock
()
@override_settings
(
MODULESTORE
=
TEST_DATA_MONGO_MODULESTORE
)
class
ShoppingCartViewsTests
(
ModuleStoreTestCase
):
def
setUp
(
self
):
...
...
@@ -53,7 +55,6 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
def
login_user
(
self
):
self
.
client
.
login
(
username
=
self
.
user
.
username
,
password
=
"password"
)
def
test_add_course_to_cart_anon
(
self
):
resp
=
self
.
client
.
post
(
reverse
(
'shoppingcart.views.add_course_to_cart'
,
args
=
[
self
.
course_id
]))
self
.
assertEqual
(
resp
.
status_code
,
403
)
...
...
@@ -141,7 +142,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
'Cannot remove cart OrderItem id={0}. DoesNotExist or item is already purchased'
.
format
(
cert_item
.
id
))
resp3
=
self
.
client
.
post
(
reverse
(
'shoppingcart.views.remove_item'
,
args
=
[]),
{
'id'
:
-
1
})
{
'id'
:
-
1
})
self
.
assertEqual
(
resp3
.
status_code
,
200
)
exception_log
.
assert_called_with
(
'Cannot remove cart OrderItem id={0}. DoesNotExist or item is already purchased'
.
format
(
-
1
))
...
...
@@ -158,7 +159,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
@patch
(
'shoppingcart.views.process_postpay_callback'
,
postpay_mock
)
@patch
(
'shoppingcart.views.render_to_response'
,
render_mock
)
def
test_postpay_callback_failure
(
self
):
postpay_mock
.
return_value
=
{
'success'
:
False
,
'order'
:
self
.
cart
,
'error_html'
:
'ERROR_TEST!!!'
}
postpay_mock
.
return_value
=
{
'success'
:
False
,
'order'
:
self
.
cart
,
'error_html'
:
'ERROR_TEST!!!'
}
self
.
login_user
()
resp
=
self
.
client
.
post
(
reverse
(
'shoppingcart.views.postpay_callback'
,
args
=
[]))
self
.
assertEqual
(
resp
.
status_code
,
200
)
...
...
@@ -224,4 +225,4 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
self
.
assertEqual
(
context
[
'order'
],
self
.
cart
)
self
.
assertIn
(
reg_item
.
orderitem_ptr
,
context
[
'order_items'
])
self
.
assertIn
(
cert_item
.
orderitem_ptr
,
context
[
'order_items'
])
self
.
assertTrue
(
context
[
'any_refunds'
])
\ No newline at end of file
self
.
assertTrue
(
context
[
'any_refunds'
])
lms/djangoapps/shoppingcart/views.py
View file @
569727e6
...
...
@@ -26,7 +26,7 @@ def add_course_to_cart(request, course_id):
PaidCourseRegistration
.
add_to_order
(
cart
,
course_id
)
except
ItemNotFoundError
:
return
HttpResponseNotFound
(
_
(
'The course you requested does not exist.'
))
if
request
.
method
==
'GET'
:
##
# This is temporary for testing purposes and will go away before we pull
if
request
.
method
==
'GET'
:
# This is temporary for testing purposes and will go away before we pull
return
HttpResponseRedirect
(
reverse
(
'shoppingcart.views.show_cart'
))
return
HttpResponse
(
_
(
"Course added to cart."
))
...
...
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