Commit 573abb80 by Calen Pennington

Merge pull request #321 from edx/cale/pylint-errors

Pylint errors
parents 0be0df1b 87edb5ae
"""
Provide names as exported by older mongo.py module
"""
from xmodule.modulestore.mongo.base import MongoModuleStore, MongoKeyValueStore, MongoUsage from xmodule.modulestore.mongo.base import MongoModuleStore, MongoKeyValueStore, MongoUsage
# Backwards compatibility for prod systems that refererence # Backwards compatibility for prod systems that refererence
......
"""
Modulestore backed by Mongodb.
Stores individual XModules as single documents with the following
structure:
{
'_id': <location.as_dict>,
'metadata': <dict containing all Scope.settings fields>
'definition': <dict containing all Scope.content fields>
'definition.children': <list of all child location.url()s>
}
"""
import pymongo import pymongo
import sys import sys
import logging import logging
...@@ -19,8 +33,7 @@ from xblock.runtime import DbModel, KeyValueStore, InvalidScopeError ...@@ -19,8 +33,7 @@ from xblock.runtime import DbModel, KeyValueStore, InvalidScopeError
from xblock.core import Scope from xblock.core import Scope
from xmodule.modulestore import ModuleStoreBase, Location, namedtuple_to_son from xmodule.modulestore import ModuleStoreBase, Location, namedtuple_to_son
from xmodule.modulestore.exceptions import (ItemNotFoundError, from xmodule.modulestore.exceptions import ItemNotFoundError, DuplicateItemError
DuplicateItemError)
from xmodule.modulestore.inheritance import own_metadata, INHERITABLE_METADATA, inherit_metadata from xmodule.modulestore.inheritance import own_metadata, INHERITABLE_METADATA, inherit_metadata
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
...@@ -32,6 +45,7 @@ log = logging.getLogger(__name__) ...@@ -32,6 +45,7 @@ log = logging.getLogger(__name__)
def get_course_id_no_run(location): def get_course_id_no_run(location):
''' '''
Return the first two components of the course_id for this location (org/course)
''' '''
return "/".join([location.org, location.course]) return "/".join([location.org, location.course])
...@@ -615,6 +629,9 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -615,6 +629,9 @@ class MongoModuleStore(ModuleStoreBase):
return item return item
def fire_updated_modulestore_signal(self, course_id, location): def fire_updated_modulestore_signal(self, course_id, location):
"""
Send a signal using `self.modulestore_update_signal`, if that has been set
"""
if self.modulestore_update_signal is not None: if self.modulestore_update_signal is not None:
self.modulestore_update_signal.send(self, modulestore=self, course_id=course_id, self.modulestore_update_signal.send(self, modulestore=self, course_id=course_id,
location=location) location=location)
...@@ -758,5 +775,3 @@ class MongoModuleStore(ModuleStoreBase): ...@@ -758,5 +775,3 @@ class MongoModuleStore(ModuleStoreBase):
are loaded on demand, rather than up front are loaded on demand, rather than up front
""" """
return {} return {}
"""
A ModuleStore that knows about a special version 'draft'. Modules
marked as 'draft' are read in preference to modules without the 'draft'
version by this ModuleStore (so, access to i4x://org/course/cat/name
returns the i4x://org/course/cat/name@draft object if that exists,
and otherwise returns i4x://org/course/cat/name).
"""
from datetime import datetime from datetime import datetime
from xmodule.modulestore import Location, namedtuple_to_son from xmodule.modulestore import Location, namedtuple_to_son
...@@ -217,7 +225,6 @@ class DraftModuleStore(MongoModuleStore): ...@@ -217,7 +225,6 @@ class DraftModuleStore(MongoModuleStore):
def _query_children_for_cache_children(self, items): def _query_children_for_cache_children(self, items):
# first get non-draft in a round-trip # first get non-draft in a round-trip
queried_children = []
to_process_non_drafts = super(DraftModuleStore, self)._query_children_for_cache_children(items) to_process_non_drafts = super(DraftModuleStore, self)._query_children_for_cache_children(items)
to_process_dict = {} to_process_dict = {}
...@@ -243,7 +250,6 @@ class DraftModuleStore(MongoModuleStore): ...@@ -243,7 +250,6 @@ class DraftModuleStore(MongoModuleStore):
to_process_dict[draft_as_non_draft_loc] = draft to_process_dict[draft_as_non_draft_loc] = draft
# convert the dict - which is used for look ups - back into a list # convert the dict - which is used for look ups - back into a list
for key, value in to_process_dict.iteritems(): queried_children = to_process_dict.values()
queried_children.append(value)
return queried_children return queried_children
"""
Methods for exporting course data to XML
"""
import logging import logging
from xmodule.modulestore import Location from xmodule.modulestore import Location
from xmodule.modulestore.inheritance import own_metadata from xmodule.modulestore.inheritance import own_metadata
from fs.osfs import OSFS from fs.osfs import OSFS
from json import dumps from json import dumps
import json import json
from json.encoder import JSONEncoder
import datetime import datetime
class EdxJSONEncoder(json.JSONEncoder): class EdxJSONEncoder(json.JSONEncoder):
"""
Custom JSONEncoder that handles `Location` and `datetime.datetime` objects.
`Location`s are encoded as their url string form, and `datetime`s as
ISO date strings
"""
def default(self, obj): def default(self, obj):
if isinstance(obj, Location): if isinstance(obj, Location):
return obj.url() return obj.url()
...@@ -22,7 +32,19 @@ class EdxJSONEncoder(json.JSONEncoder): ...@@ -22,7 +32,19 @@ class EdxJSONEncoder(json.JSONEncoder):
else: else:
return super(EdxJSONEncoder, self).default(obj) return super(EdxJSONEncoder, self).default(obj)
def export_to_xml(modulestore, contentstore, course_location, root_dir, course_dir, draft_modulestore=None): def export_to_xml(modulestore, contentstore, course_location, root_dir, course_dir, draft_modulestore=None):
"""
Export all modules from `modulestore` and content from `contentstore` as xml to `root_dir`.
`modulestore`: A `ModuleStore` object that is the source of the modules to export
`contentstore`: A `ContentStore` object that is the source of the content to export
`course_location`: The `Location` of the `CourseModuleDescriptor` to export
`root_dir`: The directory to write the exported xml to
`course_dir`: The name of the directory inside `root_dir` to write the course content to
`draft_modulestore`: An optional `DraftModuleStore` that contains draft content, which will be exported
alongside the public content in the course.
"""
course = modulestore.get_item(course_location) course = modulestore.get_item(course_location)
......
# Tests for xmodule.util.date_utils """Tests for xmodule.util.date_utils"""
from nose.tools import assert_equals, assert_false from nose.tools import assert_equals, assert_false
from xmodule.util.date_utils import get_default_time_display, almost_same_datetime from xmodule.util.date_utils import get_default_time_display, almost_same_datetime
...@@ -19,6 +19,7 @@ def test_get_default_time_display(): ...@@ -19,6 +19,7 @@ def test_get_default_time_display():
"Mar 12, 1992 at 15:03", "Mar 12, 1992 at 15:03",
get_default_time_display(test_time, False)) get_default_time_display(test_time, False))
def test_get_default_time_display_notz(): def test_get_default_time_display_notz():
test_time = datetime(1992, 3, 12, 15, 3, 30) test_time = datetime(1992, 3, 12, 15, 3, 30)
assert_equals( assert_equals(
...@@ -31,8 +32,10 @@ def test_get_default_time_display_notz(): ...@@ -31,8 +32,10 @@ def test_get_default_time_display_notz():
"Mar 12, 1992 at 15:03", "Mar 12, 1992 at 15:03",
get_default_time_display(test_time, False)) get_default_time_display(test_time, False))
# pylint: disable=W0232 # pylint: disable=W0232
class NamelessTZ(tzinfo): class NamelessTZ(tzinfo):
"""Static timezone for testing"""
def utcoffset(self, _dt): def utcoffset(self, _dt):
return timedelta(hours=-3) return timedelta(hours=-3)
...@@ -40,6 +43,7 @@ class NamelessTZ(tzinfo): ...@@ -40,6 +43,7 @@ class NamelessTZ(tzinfo):
def dst(self, _dt): def dst(self, _dt):
return timedelta(0) return timedelta(0)
def test_get_default_time_display_no_tzname(): def test_get_default_time_display_no_tzname():
assert_equals("", get_default_time_display(None)) assert_equals("", get_default_time_display(None))
test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=NamelessTZ()) test_time = datetime(1992, 3, 12, 15, 3, 30, tzinfo=NamelessTZ())
...@@ -53,6 +57,7 @@ def test_get_default_time_display_no_tzname(): ...@@ -53,6 +57,7 @@ def test_get_default_time_display_no_tzname():
"Mar 12, 1992 at 15:03", "Mar 12, 1992 at 15:03",
get_default_time_display(test_time, False)) get_default_time_display(test_time, False))
def test_almost_same_datetime(): def test_almost_same_datetime():
assert almost_same_datetime( assert almost_same_datetime(
datetime(2013, 5, 3, 10, 20, 30), datetime(2013, 5, 3, 10, 20, 30),
......
"""
Tests of XML export
"""
import unittest import unittest
import pytz import pytz
from datetime import datetime, timedelta, tzinfo from datetime import datetime, timedelta, tzinfo
from fs.osfs import OSFS from fs.osfs import OSFS
from mock import Mock
from path import path from path import path
from tempfile import mkdtemp from tempfile import mkdtemp
import shutil import shutil
...@@ -136,19 +139,22 @@ class RoundTripTestCase(unittest.TestCase): ...@@ -136,19 +139,22 @@ class RoundTripTestCase(unittest.TestCase):
class TestEdxJsonEncoder(unittest.TestCase): class TestEdxJsonEncoder(unittest.TestCase):
"""
Tests for xml_exporter.EdxJSONEncoder
"""
def setUp(self): def setUp(self):
self.encoder = EdxJSONEncoder() self.encoder = EdxJSONEncoder()
class OffsetTZ(tzinfo): class OffsetTZ(tzinfo):
"""A timezone with non-None utcoffset""" """A timezone with non-None utcoffset"""
def utcoffset(self, dt): def utcoffset(self, _dt):
return timedelta(hours=4) return timedelta(hours=4)
self.offset_tz = OffsetTZ() self.offset_tz = OffsetTZ()
class NullTZ(tzinfo): class NullTZ(tzinfo):
"""A timezone with None as its utcoffset""" """A timezone with None as its utcoffset"""
def utcoffset(self, dt): def utcoffset(self, _dt):
return None return None
self.null_utc_tz = NullTZ() self.null_utc_tz = NullTZ()
......
"""
Convenience methods for working with datetime objects
"""
import datetime import datetime
def get_default_time_display(dt, show_timezone=True): def get_default_time_display(dt, show_timezone=True):
""" """
......
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