Commit b4e400ba by Victor Shnayder Committed by Calen Pennington

Make tests pass again again

* Move lazyproperty decorator into xmodule so it's accessible during tests
* add default xqueue to test system
parent 932a9be7
...@@ -3,7 +3,7 @@ import time ...@@ -3,7 +3,7 @@ import time
import dateutil.parser import dateutil.parser
import logging import logging
from util.decorators import lazyproperty from xmodule.util.decorators import lazyproperty
from xmodule.graders import load_grading_policy from xmodule.graders import load_grading_policy
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.seq_module import SequenceDescriptor, SequenceModule from xmodule.seq_module import SequenceDescriptor, SequenceModule
...@@ -40,80 +40,80 @@ class CourseDescriptor(SequenceDescriptor): ...@@ -40,80 +40,80 @@ class CourseDescriptor(SequenceDescriptor):
@property @property
def grader(self): def grader(self):
return self.__grading_policy['GRADER'] return self.__grading_policy['GRADER']
@property @property
def grade_cutoffs(self): def grade_cutoffs(self):
return self.__grading_policy['GRADE_CUTOFFS'] return self.__grading_policy['GRADE_CUTOFFS']
@lazyproperty @lazyproperty
def __grading_policy(self): def __grading_policy(self):
policy_string = "" policy_string = ""
try: try:
with self.system.resources_fs.open("grading_policy.json") as grading_policy_file: with self.system.resources_fs.open("grading_policy.json") as grading_policy_file:
policy_string = grading_policy_file.read() policy_string = grading_policy_file.read()
except (IOError, ResourceNotFoundError): except (IOError, ResourceNotFoundError):
log.warning("Unable to load course settings file from grading_policy.json in course " + self.id) log.warning("Unable to load course settings file from grading_policy.json in course " + self.id)
grading_policy = load_grading_policy(policy_string) grading_policy = load_grading_policy(policy_string)
return grading_policy return grading_policy
@lazyproperty @lazyproperty
def grading_context(self): def grading_context(self):
""" """
This returns a dictionary with keys necessary for quickly grading This returns a dictionary with keys necessary for quickly grading
a student. They are used by grades.grade() a student. They are used by grades.grade()
The grading context has two keys: The grading context has two keys:
graded_sections - This contains the sections that are graded, as graded_sections - This contains the sections that are graded, as
well as all possible children modules that can affect the well as all possible children modules that can affect the
grading. This allows some sections to be skipped if the student grading. This allows some sections to be skipped if the student
hasn't seen any part of it. hasn't seen any part of it.
The format is a dictionary keyed by section-type. The values are The format is a dictionary keyed by section-type. The values are
arrays of dictionaries containing arrays of dictionaries containing
"section_descriptor" : The section descriptor "section_descriptor" : The section descriptor
"xmoduledescriptors" : An array of xmoduledescriptors that "xmoduledescriptors" : An array of xmoduledescriptors that
could possibly be in the section, for any student could possibly be in the section, for any student
all_descriptors - This contains a list of all xmodules that can all_descriptors - This contains a list of all xmodules that can
effect grading a student. This is used to efficiently fetch effect grading a student. This is used to efficiently fetch
all the xmodule state for a StudentModuleCache without walking all the xmodule state for a StudentModuleCache without walking
the descriptor tree again. the descriptor tree again.
""" """
all_descriptors = [] all_descriptors = []
graded_sections = {} graded_sections = {}
def yield_descriptor_descendents(module_descriptor): def yield_descriptor_descendents(module_descriptor):
for child in module_descriptor.get_children(): for child in module_descriptor.get_children():
yield child yield child
for module_descriptor in yield_descriptor_descendents(child): for module_descriptor in yield_descriptor_descendents(child):
yield module_descriptor yield module_descriptor
for c in self.get_children(): for c in self.get_children():
sections = [] sections = []
for s in c.get_children(): for s in c.get_children():
if s.metadata.get('graded', False): if s.metadata.get('graded', False):
# TODO: Only include modules that have a score here # TODO: Only include modules that have a score here
xmoduledescriptors = [child for child in yield_descriptor_descendents(s)] xmoduledescriptors = [child for child in yield_descriptor_descendents(s)]
section_description = { 'section_descriptor' : s, 'xmoduledescriptors' : xmoduledescriptors} section_description = { 'section_descriptor' : s, 'xmoduledescriptors' : xmoduledescriptors}
section_format = s.metadata.get('format', "") section_format = s.metadata.get('format', "")
graded_sections[ section_format ] = graded_sections.get( section_format, [] ) + [section_description] graded_sections[ section_format ] = graded_sections.get( section_format, [] ) + [section_description]
all_descriptors.extend(xmoduledescriptors) all_descriptors.extend(xmoduledescriptors)
all_descriptors.append(s) all_descriptors.append(s)
return { 'graded_sections' : graded_sections, return { 'graded_sections' : graded_sections,
'all_descriptors' : all_descriptors,} 'all_descriptors' : all_descriptors,}
@staticmethod @staticmethod
def id_to_location(course_id): def id_to_location(course_id):
'''Convert the given course_id (org/course/name) to a location object. '''Convert the given course_id (org/course/name) to a location object.
......
...@@ -32,7 +32,7 @@ i4xs = ModuleSystem( ...@@ -32,7 +32,7 @@ i4xs = ModuleSystem(
user=Mock(), user=Mock(),
filestore=fs.osfs.OSFS(os.path.dirname(os.path.realpath(__file__))), filestore=fs.osfs.OSFS(os.path.dirname(os.path.realpath(__file__))),
debug=True, debug=True,
xqueue=None, xqueue={'default_queuename': 'testqueue'},
is_staff=False is_staff=False
) )
......
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