From d785b1e2137fa734d5bc4bd01af1f3f2165ddd17 Mon Sep 17 00:00:00 2001 From: Calen Pennington Date: Thu, 3 Oct 2013 16:18:35 -0400 Subject: [PATCH] Convert due_date_display_format tests to use factories Previously, these tests modified due_date, which failed due to the new restrictions on writing to Scope.settings from the LMS. --- .../xmodule/modulestore/tests/factories.py | 48 +++-- common/test/data/due_date/about/overview.html | 47 ----- .../c8ee0db7e5a84c85bac80b7013cf6512.xml | 3 - common/test/data/due_date/course.xml | 1 - .../test/data/due_date/course/2013_fall.xml | 3 - .../policies/2013_fall/grading_policy.json | 1 - .../due_date/policies/2013_fall/policy.json | 1 - .../d392c80f5c044e45a4a5f2d62f94efc5.xml | 23 --- .../c804fa32227142a1bd9d5bc183d4a20d.xml | 3 - .../45640305a210424ebcc6f8e045fad0be.xml | 3 - lms/djangoapps/courseware/tests/test_views.py | 168 ++++++++++-------- 11 files changed, 122 insertions(+), 179 deletions(-) delete mode 100644 common/test/data/due_date/about/overview.html delete mode 100644 common/test/data/due_date/chapter/c8ee0db7e5a84c85bac80b7013cf6512.xml delete mode 100644 common/test/data/due_date/course.xml delete mode 100644 common/test/data/due_date/course/2013_fall.xml delete mode 100644 common/test/data/due_date/policies/2013_fall/grading_policy.json delete mode 100644 common/test/data/due_date/policies/2013_fall/policy.json delete mode 100644 common/test/data/due_date/problem/d392c80f5c044e45a4a5f2d62f94efc5.xml delete mode 100644 common/test/data/due_date/sequential/c804fa32227142a1bd9d5bc183d4a20d.xml delete mode 100644 common/test/data/due_date/vertical/45640305a210424ebcc6f8e045fad0be.xml diff --git a/common/lib/xmodule/xmodule/modulestore/tests/factories.py b/common/lib/xmodule/xmodule/modulestore/tests/factories.py index 5b7f9ec3d7..7d887bb81b 100644 --- a/common/lib/xmodule/xmodule/modulestore/tests/factories.py +++ b/common/lib/xmodule/xmodule/modulestore/tests/factories.py @@ -7,7 +7,6 @@ from pytz import UTC from xmodule.modulestore import Location from xmodule.x_module import XModuleDescriptor -from xmodule.course_module import CourseDescriptor class Dummy(object): @@ -124,16 +123,28 @@ class ItemFactory(XModuleFactory): :target_class: is ignored """ + # All class attributes (from this class and base classes) are + # passed in via **kwargs. However, some of those aren't actual field values, + # so pop those off for use separately + DETACHED_CATEGORIES = ['about', 'static_tab', 'course_info'] # catch any old style users before they get into trouble - assert not 'template' in kwargs - data = kwargs.get('data') - category = kwargs.get('category') - display_name = kwargs.get('display_name') - metadata = kwargs.get('metadata', {}) - location = kwargs.get('location') - if kwargs.get('boilerplate') is not None: - template_id = kwargs.get('boilerplate') + assert 'template' not in kwargs + parent_location = Location(kwargs.pop('parent_location', None)) + data = kwargs.pop('data', None) + category = kwargs.pop('category', None) + display_name = kwargs.pop('display_name', None) + metadata = kwargs.pop('metadata', {}) + location = kwargs.pop('location') + assert location != parent_location + + store = kwargs.pop('modulestore') + + # This code was based off that in cms/djangoapps/contentstore/views.py + parent = kwargs.pop('parent', None) or store.get_item(parent_location) + + if 'boilerplate' in kwargs: + template_id = kwargs.pop('boilerplate') clz = XModuleDescriptor.load_class(category) template = clz.get_template(template_id) assert template is not None @@ -141,21 +152,20 @@ class ItemFactory(XModuleFactory): if not isinstance(data, basestring): data.update(template.get('data')) - store = kwargs.get('modulestore') - # replace the display name with an optional parameter passed in from the caller if display_name is not None: metadata['display_name'] = display_name - store.create_and_save_xmodule(location, metadata=metadata, definition_data=data) + module = store.create_and_save_xmodule(location, metadata=metadata, definition_data=data) + + module = store.get_item(location) + + for attr, val in kwargs.items(): + setattr(module, attr, val) + module.save() + + store.save_xmodule(module) if location.category not in DETACHED_CATEGORIES: - - parent_location = Location(kwargs.get('parent_location')) - assert location != parent_location - - # This code was based off that in cms/djangoapps/contentstore/views.py - parent = kwargs.get('parent') or store.get_item(parent_location) - parent.children.append(location.url()) store.update_children(parent_location, parent.children) diff --git a/common/test/data/due_date/about/overview.html b/common/test/data/due_date/about/overview.html deleted file mode 100644 index 961786b8f4..0000000000 --- a/common/test/data/due_date/about/overview.html +++ /dev/null @@ -1,47 +0,0 @@ -
-

About This Course

-

Include your long course description here. The long course description should contain 150-400 words.

- -

This is paragraph 2 of the long course description. Add more paragraphs as needed. Make sure to enclose them in paragraph tags.

-
- -
-

Prerequisites

-

Add information about course prerequisites here.

-
- -
-

Course Staff

-
-
- -
- -

Staff Member #1

-

Biography of instructor/staff member #1

-
- -
-
- -
- -

Staff Member #2

-

Biography of instructor/staff member #2

-
-
- -
-
-

Frequently Asked Questions

-
-

Do I need to buy a textbook?

-

No, a free online version of Chemistry: Principles, Patterns, and Applications, First Edition by Bruce Averill and Patricia Eldredge will be available, though you can purchase a printed version (published by FlatWorld Knowledge) if you’d like.

-
- -
-

Question #2

-

Your answer would be displayed here.

-
-
-
diff --git a/common/test/data/due_date/chapter/c8ee0db7e5a84c85bac80b7013cf6512.xml b/common/test/data/due_date/chapter/c8ee0db7e5a84c85bac80b7013cf6512.xml deleted file mode 100644 index cdc5d294f8..0000000000 --- a/common/test/data/due_date/chapter/c8ee0db7e5a84c85bac80b7013cf6512.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/common/test/data/due_date/course.xml b/common/test/data/due_date/course.xml deleted file mode 100644 index e355f924b4..0000000000 --- a/common/test/data/due_date/course.xml +++ /dev/null @@ -1 +0,0 @@ - diff --git a/common/test/data/due_date/course/2013_fall.xml b/common/test/data/due_date/course/2013_fall.xml deleted file mode 100644 index 97ad3760ae..0000000000 --- a/common/test/data/due_date/course/2013_fall.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/common/test/data/due_date/policies/2013_fall/grading_policy.json b/common/test/data/due_date/policies/2013_fall/grading_policy.json deleted file mode 100644 index 272cb4fec6..0000000000 --- a/common/test/data/due_date/policies/2013_fall/grading_policy.json +++ /dev/null @@ -1 +0,0 @@ -{"GRADER": [{"short_label": "HW", "min_count": 12, "type": "Homework", "drop_count": 2, "weight": 0.15}, {"min_count": 12, "type": "Lab", "drop_count": 2, "weight": 0.15}, {"short_label": "Midterm", "min_count": 1, "type": "Midterm Exam", "drop_count": 0, "weight": 0.3}, {"short_label": "Final", "min_count": 1, "type": "Final Exam", "drop_count": 0, "weight": 0.4}], "GRADE_CUTOFFS": {"Pass": 0.5}} \ No newline at end of file diff --git a/common/test/data/due_date/policies/2013_fall/policy.json b/common/test/data/due_date/policies/2013_fall/policy.json deleted file mode 100644 index 42ba75ae29..0000000000 --- a/common/test/data/due_date/policies/2013_fall/policy.json +++ /dev/null @@ -1 +0,0 @@ -{"course/2013_fall": {"tabs": [{"type": "courseware"}, {"type": "course_info", "name": "Course Info"}, {"type": "textbooks"}, {"type": "discussion", "name": "Discussion"}, {"type": "wiki", "name": "Wiki"}, {"type": "progress", "name": "Progress"}], "display_name": "due_date", "discussion_topics": {"General": {"id": "i4x-edX-due_date-course-2013_fall"}}, "show_timezone": "false"}} \ No newline at end of file diff --git a/common/test/data/due_date/problem/d392c80f5c044e45a4a5f2d62f94efc5.xml b/common/test/data/due_date/problem/d392c80f5c044e45a4a5f2d62f94efc5.xml deleted file mode 100644 index 4e50ac396b..0000000000 --- a/common/test/data/due_date/problem/d392c80f5c044e45a4a5f2d62f94efc5.xml +++ /dev/null @@ -1,23 +0,0 @@ - -

-A multiple choice problem presents radio buttons for student -input. Students can only select a single option presented. Multiple Choice questions have been the subject of many areas of research due to the early invention and adoption of bubble sheets.

-

One of the main elements that goes into a good multiple choice question is the existence of good distractors. That is, each of the alternate responses presented to the student should be the result of a plausible mistake that a student might make. -

- -

What Apple device competed with the portable CD player?

- - - The iPad - Napster - The iPod - The vegetable peeler - - - -
-

Explanation

-

The release of the iPod allowed consumers to carry their entire music library with them in a format that did not rely on fragile and energy-intensive spinning disks.

-
-
-
diff --git a/common/test/data/due_date/sequential/c804fa32227142a1bd9d5bc183d4a20d.xml b/common/test/data/due_date/sequential/c804fa32227142a1bd9d5bc183d4a20d.xml deleted file mode 100644 index a26ed3789f..0000000000 --- a/common/test/data/due_date/sequential/c804fa32227142a1bd9d5bc183d4a20d.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/common/test/data/due_date/vertical/45640305a210424ebcc6f8e045fad0be.xml b/common/test/data/due_date/vertical/45640305a210424ebcc6f8e045fad0be.xml deleted file mode 100644 index 66b6fc546b..0000000000 --- a/common/test/data/due_date/vertical/45640305a210424ebcc6f8e045fad0be.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/lms/djangoapps/courseware/tests/test_views.py b/lms/djangoapps/courseware/tests/test_views.py index dbf4bf1994..17198c372d 100644 --- a/lms/djangoapps/courseware/tests/test_views.py +++ b/lms/djangoapps/courseware/tests/test_views.py @@ -1,9 +1,10 @@ """ Tests courseware views.py """ -from mock import MagicMock, patch -import datetime import unittest +from mock import MagicMock, patch +from datetime import datetime +from pytz import UTC from django.test import TestCase from django.http import Http404 @@ -18,12 +19,13 @@ from student.models import CourseEnrollment from student.tests.factories import AdminFactory from mitxmako.middleware import MakoMiddleware -from xmodule.modulestore.django import modulestore, clear_existing_modulestores -from xmodule.modulestore.tests.factories import CourseFactory +from xmodule.modulestore import Location +from xmodule.modulestore.django import modulestore +from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory +from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase +from student.tests.factories import UserFactory import courseware.views as views -from xmodule.modulestore import Location -from pytz import UTC from courseware.tests.modulestore_config import TEST_DATA_MIXED_MODULESTORE from course_modes.models import CourseMode import shoppingcart @@ -73,7 +75,7 @@ class ViewsTestCase(TestCase): def setUp(self): self.user = User.objects.create(username='dummy', password='123456', email='test@mit.edu') - self.date = datetime.datetime(2013, 1, 22, tzinfo=UTC) + self.date = datetime(2013, 1, 22, tzinfo=UTC) self.course_id = 'edX/toy/2012_Fall' self.enrollment = CourseEnrollment.enroll(self.user, self.course_id) self.enrollment.created = self.date @@ -109,7 +111,6 @@ class ViewsTestCase(TestCase): self.assertEqual(response.status_code, 200) self.assertIn(in_cart_span, response.content) - def test_user_groups(self): # depreciated function mock_user = MagicMock() @@ -254,98 +255,115 @@ class ViewsTestCase(TestCase): response = self.client.get(url) self.assertFalse('