Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
edx-platform
Commits
214a3bd2
Commit
214a3bd2
authored
Oct 17, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pylint/pep8 cleanups
parent
ee2a3750
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
19 deletions
+20
-19
lms/djangoapps/courseware/courses.py
+12
-14
lms/djangoapps/courseware/tests/test_courses.py
+8
-5
No files found.
lms/djangoapps/courseware/courses.py
View file @
214a3bd2
...
...
@@ -51,6 +51,7 @@ def get_course_by_id(course_id, depth=0):
except
InvalidLocationError
:
raise
Http404
(
"Invalid location"
)
def
get_course_with_access
(
user
,
course_id
,
action
,
depth
=
0
):
"""
Given a course_id, look up the corresponding course descriptor,
...
...
@@ -85,24 +86,24 @@ def course_image_url(course):
if
course
.
static_asset_path
or
modulestore
()
.
get_modulestore_type
(
course
.
location
.
course_id
)
==
XML_MODULESTORE_TYPE
:
return
'/static/'
+
(
course
.
static_asset_path
or
getattr
(
course
,
'data_dir'
,
''
))
+
"/images/course_image.jpg"
else
:
loc
=
course
.
location
.
_
replace
(
tag
=
'c4x'
,
category
=
'asset'
,
name
=
course
.
course_image
)
loc
=
course
.
location
.
replace
(
tag
=
'c4x'
,
category
=
'asset'
,
name
=
course
.
course_image
)
_path
=
StaticContent
.
get_url_path_from_location
(
loc
)
return
_path
def
find_file
(
f
s
,
dirs
,
filename
):
def
find_file
(
f
ilesystem
,
dirs
,
filename
):
"""
Looks for a filename in a list of dirs on a filesystem, in the specified order.
f
s
: an OSFS filesystem
f
ilesystem
: an OSFS filesystem
dirs: a list of path objects
filename: a string
Returns d / filename if found in dir d, else raises ResourceNotFoundError.
"""
for
d
in
dirs
:
filepath
=
path
(
d
)
/
filename
if
f
s
.
exists
(
filepath
):
for
d
irectory
in
dirs
:
filepath
=
path
(
d
irectory
)
/
filename
if
f
ilesystem
.
exists
(
filepath
):
return
filepath
raise
ResourceNotFoundError
(
"Could not find {0}"
.
format
(
filename
))
...
...
@@ -146,7 +147,7 @@ def get_course_about_section(course, section_key):
request
=
get_request_for_thread
()
loc
=
course
.
location
.
_
replace
(
category
=
'about'
,
name
=
section_key
)
loc
=
course
.
location
.
replace
(
category
=
'about'
,
name
=
section_key
)
# Use an empty cache
field_data_cache
=
FieldDataCache
([],
course
.
id
,
request
.
user
)
...
...
@@ -182,7 +183,6 @@ def get_course_about_section(course, section_key):
raise
KeyError
(
"Invalid about key "
+
str
(
section_key
))
def
get_course_info_section
(
request
,
course
,
section_key
):
"""
This returns the snippet of html to be rendered on the course info page,
...
...
@@ -194,8 +194,6 @@ def get_course_info_section(request, course, section_key):
- updates
- guest_updates
"""
loc
=
Location
(
course
.
location
.
tag
,
course
.
location
.
org
,
course
.
location
.
course
,
'course_info'
,
section_key
)
# Use an empty cache
...
...
@@ -237,13 +235,13 @@ def get_course_syllabus_section(course, section_key):
if
section_key
in
[
'syllabus'
,
'guest_syllabus'
]:
try
:
fs
=
course
.
system
.
resources_fs
f
ilesy
s
=
course
.
system
.
resources_fs
# first look for a run-specific version
dirs
=
[
path
(
"syllabus"
)
/
course
.
url_name
,
path
(
"syllabus"
)]
filepath
=
find_file
(
fs
,
dirs
,
section_key
+
".html"
)
with
f
s
.
open
(
filepath
)
as
htmlF
ile
:
filepath
=
find_file
(
f
ilesy
s
,
dirs
,
section_key
+
".html"
)
with
f
ilesys
.
open
(
filepath
)
as
html_f
ile
:
return
replace_static_urls
(
html
F
ile
.
read
()
.
decode
(
'utf-8'
),
html
_f
ile
.
read
()
.
decode
(
'utf-8'
),
getattr
(
course
,
'data_dir'
,
None
),
course_id
=
course
.
location
.
course_id
,
static_asset_path
=
course
.
static_asset_path
,
...
...
lms/djangoapps/courseware/tests/test_courses.py
View file @
214a3bd2
# -*- coding: utf-8 -*-
"""
Tests for course access
"""
import
mock
from
django.test
import
TestCase
...
...
@@ -9,11 +12,12 @@ from xmodule.modulestore.django import get_default_store_name_for_current_reques
CMS_BASE_TEST
=
'testcms'
class
CoursesTest
(
TestCase
):
def
test_get_course_by_id_invalid_chars
(
self
):
"""
Test that `get_course_by_id` throws a 404, rather than
an exception, when faced with unexpected characters
an exception, when faced with unexpected characters
(such as unicode characters, and symbols such as = and ' ')
"""
with
self
.
assertRaises
(
Http404
):
...
...
@@ -30,13 +34,12 @@ class CoursesTest(TestCase):
self
.
assertEqual
(
"//{}/"
.
format
(
CMS_BASE_TEST
),
get_cms_course_link_by_id
(
"too/too/many/slashes"
))
self
.
assertEqual
(
"//{}/org/num/course/name"
.
format
(
CMS_BASE_TEST
),
get_cms_course_link_by_id
(
'org/num/name'
))
@mock.patch
(
'xmodule.modulestore.django.get_current_request_hostname'
,
mock
.
Mock
(
return_value
=
'preview.localhost'
))
@override_settings
(
HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS
=
{
'preview
\
.'
:
'draft'
})
def
test_default_modulestore_preview_mapping
(
self
):
@override_settings
(
HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS
=
{
r
'preview\.'
:
'draft'
})
def
test_default_modulestore_preview_mapping
(
self
):
self
.
assertEqual
(
get_default_store_name_for_current_request
(),
'draft'
)
@mock.patch
(
'xmodule.modulestore.django.get_current_request_hostname'
,
mock
.
Mock
(
return_value
=
'localhost'
))
@override_settings
(
HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS
=
{
'preview
\
.'
:
'draft'
})
@override_settings
(
HOSTNAME_MODULESTORE_DEFAULT_MAPPINGS
=
{
r
'preview\.'
:
'draft'
})
def
test_default_modulestore_published_mapping
(
self
):
self
.
assertEqual
(
get_default_store_name_for_current_request
(),
'default'
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment