started view tests
This commit is contained in:
0
lms/djangoapps/shoppingcart/tests/__init__.py
Normal file
0
lms/djangoapps/shoppingcart/tests/__init__.py
Normal file
@@ -1,5 +1,5 @@
|
||||
"""
|
||||
Tests for the Shopping Cart
|
||||
Tests for the Shopping Cart Models
|
||||
"""
|
||||
|
||||
from factory import DjangoModelFactory
|
||||
@@ -12,7 +12,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 ..exceptions import PurchasedCallbackException
|
||||
|
||||
|
||||
class OrderTest(TestCase):
|
||||
34
lms/djangoapps/shoppingcart/tests/test_views.py
Normal file
34
lms/djangoapps/shoppingcart/tests/test_views.py
Normal file
@@ -0,0 +1,34 @@
|
||||
"""
|
||||
Tests for Shopping Cart views
|
||||
"""
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.core.urlresolvers import reverse
|
||||
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
|
||||
from shoppingcart.views import add_course_to_cart
|
||||
from shoppingcart.models import Order, OrderItem, CertificateItem, InvalidCartItem, PaidCourseRegistration
|
||||
from student.tests.factories import UserFactory
|
||||
from student.models import CourseEnrollment
|
||||
from course_modes.models import CourseMode
|
||||
from ..exceptions import PurchasedCallbackException
|
||||
|
||||
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE, DEBUG=True)
|
||||
class ShoppingCartViewsTests(ModuleStoreTestCase):
|
||||
def setUp(self):
|
||||
self.user = UserFactory.create()
|
||||
self.course_id = "MITx/999/Robot_Super_Course"
|
||||
self.cost = 40
|
||||
self.course = CourseFactory.create(org='MITx', number='999', display_name='Robot Super Course')
|
||||
self.course_mode = CourseMode(course_id=self.course_id,
|
||||
mode_slug="honor",
|
||||
mode_display_name="honor cert",
|
||||
min_price=self.cost)
|
||||
self.course_mode.save()
|
||||
self.cart = Order.get_cart_for_user(self.user)
|
||||
|
||||
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)
|
||||
@@ -16,8 +16,7 @@ if settings.MITX_FEATURES['ENABLE_SHOPPING_CART']:
|
||||
if settings.DEBUG:
|
||||
urlpatterns += patterns(
|
||||
'shoppingcart.views',
|
||||
url(r'^(?P<course_id>[^/]+/[^/]+/[^/]+)/$', 'test'),
|
||||
url(r'^add/course/(?P<course_id>[^/]+/[^/]+/[^/]+)/$', 'add_course_to_cart'),
|
||||
url(r'^add/course/(?P<course_id>[^/]+/[^/]+/[^/]+)/$', 'add_course_to_cart', name='add_course_to_cart'),
|
||||
url(r'^register_verified_course/course/(?P<course_id>[^/]+/[^/]+/[^/]+)/$',
|
||||
'register_for_verified_cert'),
|
||||
)
|
||||
|
||||
@@ -14,12 +14,6 @@ from .processors import process_postpay_callback, render_purchase_form_html
|
||||
log = logging.getLogger("shoppingcart")
|
||||
|
||||
|
||||
def test(request, course_id):
|
||||
item1 = PaidCourseRegistration(course_id, 200)
|
||||
item1.purchased_callback(request.user.id)
|
||||
return HttpResponse('OK')
|
||||
|
||||
|
||||
def add_course_to_cart(request, course_id):
|
||||
if not request.user.is_authenticated():
|
||||
return HttpResponseForbidden(_('You must be logged-in to add to a shopping cart'))
|
||||
|
||||
Reference in New Issue
Block a user