Commit 569727e6 by Diana Huang

Pep8 fixes

parent d7e311f5
...@@ -147,51 +147,51 @@ class TextbookList(List): ...@@ -147,51 +147,51 @@ class TextbookList(List):
class CourseFields(object): class CourseFields(object):
textbooks = TextbookList(help="List of pairs of (title, url) for textbooks used in this course", textbooks = TextbookList(help="List of pairs of (title, url) for textbooks used in this course",
default=[], scope=Scope.content) default=[], scope=Scope.content)
wiki_slug = String(help="Slug that points to the wiki for this course", scope=Scope.content) wiki_slug = String(help="Slug that points to the wiki for this course", scope=Scope.content)
enrollment_start = Date(help="Date that enrollment for this class is opened", scope=Scope.settings) enrollment_start = Date(help="Date that enrollment for this class is opened", scope=Scope.settings)
enrollment_end = Date(help="Date that enrollment for this class is closed", scope=Scope.settings) enrollment_end = Date(help="Date that enrollment for this class is closed", scope=Scope.settings)
start = Date(help="Start time when this module is visible", start = Date(help="Start time when this module is visible",
# using now(UTC()) resulted in fractional seconds which screwed up comparisons and anyway w/b the # using now(UTC()) resulted in fractional seconds which screwed up comparisons and anyway w/b the
# time of first invocation of this stmt on the server # time of first invocation of this stmt on the server
default=datetime.fromtimestamp(0, UTC()), default=datetime.fromtimestamp(0, UTC()),
scope=Scope.settings) scope=Scope.settings)
end = Date(help="Date that this class ends", scope=Scope.settings) end = Date(help="Date that this class ends", scope=Scope.settings)
advertised_start = String(help="Date that this course is advertised to start", scope=Scope.settings) advertised_start = String(help="Date that this course is advertised to start", scope=Scope.settings)
grading_policy = Dict(help="Grading policy definition for this class", grading_policy = Dict(help="Grading policy definition for this class",
default={"GRADER": [ default={"GRADER": [
{ {
"type": "Homework", "type": "Homework",
"min_count": 12, "min_count": 12,
"drop_count": 2, "drop_count": 2,
"short_label": "HW", "short_label": "HW",
"weight": 0.15 "weight": 0.15
}, },
{ {
"type": "Lab", "type": "Lab",
"min_count": 12, "min_count": 12,
"drop_count": 2, "drop_count": 2,
"weight": 0.15 "weight": 0.15
}, },
{ {
"type": "Midterm Exam", "type": "Midterm Exam",
"short_label": "Midterm", "short_label": "Midterm",
"min_count": 1, "min_count": 1,
"drop_count": 0, "drop_count": 0,
"weight": 0.3 "weight": 0.3
}, },
{ {
"type": "Final Exam", "type": "Final Exam",
"short_label": "Final", "short_label": "Final",
"min_count": 1, "min_count": 1,
"drop_count": 0, "drop_count": 0,
"weight": 0.4 "weight": 0.4
} }
], ],
"GRADE_CUTOFFS": { "GRADE_CUTOFFS": {
"Pass": 0.5 "Pass": 0.5
}}, }},
scope=Scope.content) scope=Scope.content)
show_calculator = Boolean(help="Whether to show the calculator in this course", default=False, scope=Scope.settings) show_calculator = Boolean(help="Whether to show the calculator in this course", default=False, scope=Scope.settings)
display_name = String(help="Display name for this module", default="Empty", display_name="Display Name", scope=Scope.settings) display_name = String(help="Display name for this module", default="Empty", display_name="Display Name", scope=Scope.settings)
show_chat = Boolean(help="Whether to show the chat widget in this course", default=False, scope=Scope.settings) show_chat = Boolean(help="Whether to show the chat widget in this course", default=False, scope=Scope.settings)
...@@ -201,7 +201,7 @@ class CourseFields(object): ...@@ -201,7 +201,7 @@ class CourseFields(object):
discussion_topics = Dict( discussion_topics = Dict(
help="Map of topics names to ids", help="Map of topics names to ids",
scope=Scope.settings scope=Scope.settings
) )
testcenter_info = Dict(help="Dictionary of Test Center info", scope=Scope.settings) testcenter_info = Dict(help="Dictionary of Test Center info", scope=Scope.settings)
announcement = Date(help="Date this course is announced", scope=Scope.settings) announcement = Date(help="Date this course is announced", scope=Scope.settings)
cohort_config = Dict(help="Dictionary defining cohort configuration", scope=Scope.settings) cohort_config = Dict(help="Dictionary defining cohort configuration", scope=Scope.settings)
...@@ -216,128 +216,124 @@ class CourseFields(object): ...@@ -216,128 +216,124 @@ class CourseFields(object):
advanced_modules = List(help="Beta modules used in your course", scope=Scope.settings) advanced_modules = List(help="Beta modules used in your course", scope=Scope.settings)
has_children = True has_children = True
checklists = List(scope=Scope.settings, checklists = List(scope=Scope.settings,
default=[ default=[
{"short_description" : "Getting Started With Studio", {"short_description": "Getting Started With Studio",
"items" : [{"short_description": "Add Course Team Members", "items": [{"short_description": "Add Course Team Members",
"long_description": "Grant your collaborators permission to edit your course so you can work together.", "long_description": "Grant your collaborators permission to edit your course so you can work together.",
"is_checked": False, "is_checked": False,
"action_url": "ManageUsers", "action_url": "ManageUsers",
"action_text": "Edit Course Team", "action_text": "Edit Course Team",
"action_external": False}, "action_external": False},
{"short_description": "Set Important Dates for Your Course", {"short_description": "Set Important Dates for Your Course",
"long_description": "Establish your course's student enrollment and launch dates on the Schedule and Details page.", "long_description": "Establish your course's student enrollment and launch dates on the Schedule and Details page.",
"is_checked": False, "is_checked": False,
"action_url": "SettingsDetails", "action_url": "SettingsDetails",
"action_text": "Edit Course Details & Schedule", "action_text": "Edit Course Details & Schedule",
"action_external": False}, "action_external": False},
{"short_description": "Draft Your Course's Grading Policy", {"short_description": "Draft Your Course's Grading Policy",
"long_description": "Set up your assignment types and grading policy even if you haven't created all your assignments.", "long_description": "Set up your assignment types and grading policy even if you haven't created all your assignments.",
"is_checked": False, "is_checked": False,
"action_url": "SettingsGrading", "action_url": "SettingsGrading",
"action_text": "Edit Grading Settings", "action_text": "Edit Grading Settings",
"action_external": False}, "action_external": False},
{"short_description": "Explore the Other Studio Checklists", {"short_description": "Explore the Other Studio Checklists",
"long_description": "Discover other available course authoring tools, and find help when you need it.", "long_description": "Discover other available course authoring tools, and find help when you need it.",
"is_checked": False, "is_checked": False,
"action_url": "", "action_url": "",
"action_text": "", "action_text": "",
"action_external": False}] "action_external": False}]},
}, {"short_description": "Draft a Rough Course Outline",
{"short_description" : "Draft a Rough Course Outline", "items": [{"short_description": "Create Your First Section and Subsection",
"items" : [{"short_description": "Create Your First Section and Subsection", "long_description": "Use your course outline to build your first Section and Subsection.",
"long_description": "Use your course outline to build your first Section and Subsection.", "is_checked": False,
"is_checked": False, "action_url": "CourseOutline",
"action_url": "CourseOutline", "action_text": "Edit Course Outline",
"action_text": "Edit Course Outline", "action_external": False},
"action_external": False}, {"short_description": "Set Section Release Dates",
{"short_description": "Set Section Release Dates", "long_description": "Specify the release dates for each Section in your course. Sections become visible to students on their release dates.",
"long_description": "Specify the release dates for each Section in your course. Sections become visible to students on their release dates.", "is_checked": False,
"is_checked": False, "action_url": "CourseOutline",
"action_url": "CourseOutline", "action_text": "Edit Course Outline",
"action_text": "Edit Course Outline", "action_external": False},
"action_external": False}, {"short_description": "Designate a Subsection as Graded",
{"short_description": "Designate a Subsection as Graded", "long_description": "Set a Subsection to be graded as a specific assignment type. Assignments within graded Subsections count toward a student's final grade.",
"long_description": "Set a Subsection to be graded as a specific assignment type. Assignments within graded Subsections count toward a student's final grade.", "is_checked": False,
"is_checked": False, "action_url": "CourseOutline",
"action_url": "CourseOutline", "action_text": "Edit Course Outline",
"action_text": "Edit Course Outline", "action_external": False},
"action_external": False}, {"short_description": "Reordering Course Content",
{"short_description": "Reordering Course Content", "long_description": "Use drag and drop to reorder the content in your course.",
"long_description": "Use drag and drop to reorder the content in your course.", "is_checked": False,
"is_checked": False, "action_url": "CourseOutline",
"action_url": "CourseOutline", "action_text": "Edit Course Outline",
"action_text": "Edit Course Outline", "action_external": False},
"action_external": False}, {"short_description": "Renaming Sections",
{"short_description": "Renaming Sections", "long_description": "Rename Sections by clicking the Section name from the Course Outline.",
"long_description": "Rename Sections by clicking the Section name from the Course Outline.", "is_checked": False,
"is_checked": False, "action_url": "CourseOutline",
"action_url": "CourseOutline", "action_text": "Edit Course Outline",
"action_text": "Edit Course Outline", "action_external": False},
"action_external": False}, {"short_description": "Deleting Course Content",
{"short_description": "Deleting Course Content", "long_description": "Delete Sections, Subsections, or Units you don't need anymore. Be careful, as there is no Undo function.",
"long_description": "Delete Sections, Subsections, or Units you don't need anymore. Be careful, as there is no Undo function.", "is_checked": False,
"is_checked": False, "action_url": "CourseOutline",
"action_url": "CourseOutline", "action_text": "Edit Course Outline",
"action_text": "Edit Course Outline", "action_external": False},
"action_external": False}, {"short_description": "Add an Instructor-Only Section to Your Outline",
{"short_description": "Add an Instructor-Only Section to Your Outline", "long_description": "Some course authors find using a section for unsorted, in-progress work useful. To do this, create a section and set the release date to the distant future.",
"long_description": "Some course authors find using a section for unsorted, in-progress work useful. To do this, create a section and set the release date to the distant future.", "is_checked": False,
"is_checked": False, "action_url": "CourseOutline",
"action_url": "CourseOutline", "action_text": "Edit Course Outline",
"action_text": "Edit Course Outline", "action_external": False}]},
"action_external": False}] {"short_description": "Explore edX's Support Tools",
}, "items": [{"short_description": "Explore the Studio Help Forum",
{"short_description" : "Explore edX's Support Tools", "long_description": "Access the Studio Help forum from the menu that appears when you click your user name in the top right corner of Studio.",
"items" : [{"short_description": "Explore the Studio Help Forum", "is_checked": False,
"long_description": "Access the Studio Help forum from the menu that appears when you click your user name in the top right corner of Studio.", "action_url": "http://help.edge.edx.org/",
"is_checked": False, "action_text": "Visit Studio Help",
"action_url": "http://help.edge.edx.org/", "action_external": True},
"action_text": "Visit Studio Help", {"short_description": "Enroll in edX 101",
"action_external": True}, "long_description": "Register for edX 101, edX's primer for course creation.",
{"short_description": "Enroll in edX 101", "is_checked": False,
"long_description": "Register for edX 101, edX's primer for course creation.", "action_url": "https://edge.edx.org/courses/edX/edX101/How_to_Create_an_edX_Course/about",
"is_checked": False, "action_text": "Register for edX 101",
"action_url": "https://edge.edx.org/courses/edX/edX101/How_to_Create_an_edX_Course/about", "action_external": True},
"action_text": "Register for edX 101", {"short_description": "Download the Studio Documentation",
"action_external": True}, "long_description": "Download the searchable Studio reference documentation in PDF form.",
{"short_description": "Download the Studio Documentation", "is_checked": False,
"long_description": "Download the searchable Studio reference documentation in PDF form.", "action_url": "http://files.edx.org/Getting_Started_with_Studio.pdf",
"is_checked": False, "action_text": "Download Documentation",
"action_url": "http://files.edx.org/Getting_Started_with_Studio.pdf", "action_external": True}]},
"action_text": "Download Documentation", {"short_description": "Draft Your Course About Page",
"action_external": True}] "items": [{"short_description": "Draft a Course Description",
}, "long_description": "Courses on edX have an About page that includes a course video, description, and more. Draft the text students will read before deciding to enroll in your course.",
{"short_description" : "Draft Your Course About Page", "is_checked": False,
"items" : [{"short_description": "Draft a Course Description", "action_url": "SettingsDetails",
"long_description": "Courses on edX have an About page that includes a course video, description, and more. Draft the text students will read before deciding to enroll in your course.", "action_text": "Edit Course Schedule & Details",
"is_checked": False, "action_external": False},
"action_url": "SettingsDetails", {"short_description": "Add Staff Bios",
"action_text": "Edit Course Schedule & Details", "long_description": "Showing prospective students who their instructor will be is helpful. Include staff bios on the course About page.",
"action_external": False}, "is_checked": False,
{"short_description": "Add Staff Bios", "action_url": "SettingsDetails",
"long_description": "Showing prospective students who their instructor will be is helpful. Include staff bios on the course About page.", "action_text": "Edit Course Schedule & Details",
"is_checked": False, "action_external": False},
"action_url": "SettingsDetails", {"short_description": "Add Course FAQs",
"action_text": "Edit Course Schedule & Details", "long_description": "Include a short list of frequently asked questions about your course.",
"action_external": False}, "is_checked": False,
{"short_description": "Add Course FAQs", "action_url": "SettingsDetails",
"long_description": "Include a short list of frequently asked questions about your course.", "action_text": "Edit Course Schedule & Details",
"is_checked": False, "action_external": False},
"action_url": "SettingsDetails", {"short_description": "Add Course Prerequisites",
"action_text": "Edit Course Schedule & Details", "long_description": "Let students know what knowledge and/or skills they should have before they enroll in your course.",
"action_external": False}, "is_checked": False,
{"short_description": "Add Course Prerequisites", "action_url": "SettingsDetails",
"long_description": "Let students know what knowledge and/or skills they should have before they enroll in your course.", "action_text": "Edit Course Schedule & Details",
"is_checked": False, "action_external": False}]}
"action_url": "SettingsDetails",
"action_text": "Edit Course Schedule & Details",
"action_external": False}]
}
]) ])
info_sidebar_name = String(scope=Scope.settings, default='Course Handouts') info_sidebar_name = String(scope=Scope.settings, default='Course Handouts')
show_timezone = Boolean(help="True if timezones should be shown on dates in the courseware", scope=Scope.settings, default=True) show_timezone = Boolean(help="True if timezones should be shown on dates in the courseware", scope=Scope.settings, default=True)
enrollment_domain = String(help="External login method associated with user accounts allowed to register in course", enrollment_domain = String(help="External login method associated with user accounts allowed to register in course",
scope=Scope.settings) scope=Scope.settings)
course_image = String( course_image = String(
help="Filename of the course image", help="Filename of the course image",
scope=Scope.settings, scope=Scope.settings,
......
...@@ -3,8 +3,10 @@ Tests for the Shopping Cart Models ...@@ -3,8 +3,10 @@ Tests for the Shopping Cart Models
""" """
from factory import DjangoModelFactory from factory import DjangoModelFactory
from mock import patch
from django.test import TestCase from django.test import TestCase
from django.test.utils import override_settings from django.test.utils import override_settings
from django.db import DatabaseError
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
from xmodule.modulestore.tests.factories import CourseFactory from xmodule.modulestore.tests.factories import CourseFactory
from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE from courseware.tests.tests import TEST_DATA_MONGO_MODULESTORE
...@@ -12,7 +14,7 @@ from shoppingcart.models import Order, OrderItem, CertificateItem, InvalidCartIt ...@@ -12,7 +14,7 @@ from shoppingcart.models import Order, OrderItem, CertificateItem, InvalidCartIt
from student.tests.factories import UserFactory from student.tests.factories import UserFactory
from student.models import CourseEnrollment from student.models import CourseEnrollment
from course_modes.models import CourseMode from course_modes.models import CourseMode
from ..exceptions import PurchasedCallbackException from shoppingcart.exceptions import PurchasedCallbackException
class OrderTest(TestCase): class OrderTest(TestCase):
...@@ -74,6 +76,17 @@ class OrderTest(TestCase): ...@@ -74,6 +76,17 @@ class OrderTest(TestCase):
cart.purchase() cart.purchase()
self.assertTrue(CourseEnrollment.is_enrolled(self.user, self.course_id)) 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): class OrderItemTest(TestCase):
def setUp(self): def setUp(self):
......
...@@ -22,6 +22,7 @@ from mitxmako.shortcuts import render_to_response ...@@ -22,6 +22,7 @@ from mitxmako.shortcuts import render_to_response
from shoppingcart.processors import render_purchase_form_html, process_postpay_callback from shoppingcart.processors import render_purchase_form_html, process_postpay_callback
from mock import patch, Mock from mock import patch, Mock
def mock_render_purchase_form_html(*args, **kwargs): def mock_render_purchase_form_html(*args, **kwargs):
return 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) ...@@ -34,6 +35,7 @@ render_mock = Mock(side_effect=mock_render_to_response)
postpay_mock = Mock() postpay_mock = Mock()
@override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE) @override_settings(MODULESTORE=TEST_DATA_MONGO_MODULESTORE)
class ShoppingCartViewsTests(ModuleStoreTestCase): class ShoppingCartViewsTests(ModuleStoreTestCase):
def setUp(self): def setUp(self):
...@@ -53,7 +55,6 @@ class ShoppingCartViewsTests(ModuleStoreTestCase): ...@@ -53,7 +55,6 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
def login_user(self): def login_user(self):
self.client.login(username=self.user.username, password="password") self.client.login(username=self.user.username, password="password")
def test_add_course_to_cart_anon(self): def test_add_course_to_cart_anon(self):
resp = self.client.post(reverse('shoppingcart.views.add_course_to_cart', args=[self.course_id])) resp = self.client.post(reverse('shoppingcart.views.add_course_to_cart', args=[self.course_id]))
self.assertEqual(resp.status_code, 403) self.assertEqual(resp.status_code, 403)
...@@ -141,7 +142,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase): ...@@ -141,7 +142,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
'Cannot remove cart OrderItem id={0}. DoesNotExist or item is already purchased'.format(cert_item.id)) '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=[]), resp3 = self.client.post(reverse('shoppingcart.views.remove_item', args=[]),
{'id': -1}) {'id': -1})
self.assertEqual(resp3.status_code, 200) self.assertEqual(resp3.status_code, 200)
exception_log.assert_called_with( exception_log.assert_called_with(
'Cannot remove cart OrderItem id={0}. DoesNotExist or item is already purchased'.format(-1)) 'Cannot remove cart OrderItem id={0}. DoesNotExist or item is already purchased'.format(-1))
...@@ -158,7 +159,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase): ...@@ -158,7 +159,7 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
@patch('shoppingcart.views.process_postpay_callback', postpay_mock) @patch('shoppingcart.views.process_postpay_callback', postpay_mock)
@patch('shoppingcart.views.render_to_response', render_mock) @patch('shoppingcart.views.render_to_response', render_mock)
def test_postpay_callback_failure(self): 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() self.login_user()
resp = self.client.post(reverse('shoppingcart.views.postpay_callback', args=[])) resp = self.client.post(reverse('shoppingcart.views.postpay_callback', args=[]))
self.assertEqual(resp.status_code, 200) self.assertEqual(resp.status_code, 200)
...@@ -224,4 +225,4 @@ class ShoppingCartViewsTests(ModuleStoreTestCase): ...@@ -224,4 +225,4 @@ class ShoppingCartViewsTests(ModuleStoreTestCase):
self.assertEqual(context['order'], self.cart) self.assertEqual(context['order'], self.cart)
self.assertIn(reg_item.orderitem_ptr, context['order_items']) self.assertIn(reg_item.orderitem_ptr, context['order_items'])
self.assertIn(cert_item.orderitem_ptr, context['order_items']) self.assertIn(cert_item.orderitem_ptr, context['order_items'])
self.assertTrue(context['any_refunds']) self.assertTrue(context['any_refunds'])
\ No newline at end of file
...@@ -26,7 +26,7 @@ def add_course_to_cart(request, course_id): ...@@ -26,7 +26,7 @@ def add_course_to_cart(request, course_id):
PaidCourseRegistration.add_to_order(cart, course_id) PaidCourseRegistration.add_to_order(cart, course_id)
except ItemNotFoundError: except ItemNotFoundError:
return HttpResponseNotFound(_('The course you requested does not exist.')) 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 HttpResponseRedirect(reverse('shoppingcart.views.show_cart'))
return HttpResponse(_("Course added to cart.")) return HttpResponse(_("Course added to cart."))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment