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
9cf318ce
Commit
9cf318ce
authored
Oct 24, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Course id clash command
parent
9f104eb6
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
91 additions
and
0 deletions
+91
-0
cms/djangoapps/contentstore/management/commands/course_id_clash.py
+51
-0
cms/djangoapps/contentstore/management/commands/tests/__init__.py
+0
-0
cms/djangoapps/contentstore/management/commands/tests/test_course_id_clash.py
+40
-0
No files found.
cms/djangoapps/contentstore/management/commands/course_id_clash.py
0 → 100644
View file @
9cf318ce
"""
Script for finding all courses whose org/name pairs == other courses when ignoring case
"""
from
django.core.management.base
import
BaseCommand
from
xmodule.modulestore.django
import
modulestore
#
# To run from command line: ./manage.py cms --settings dev course_id_clash
#
class
Command
(
BaseCommand
):
"""
Script for finding all courses whose org/name pairs == other courses when ignoring case
"""
help
=
'List all courses ids which may collide when ignoring case'
def
handle
(
self
,
*
args
,
**
options
):
mstore
=
modulestore
()
if
hasattr
(
mstore
,
'collection'
):
map_fn
=
'''
function () {
emit(this._id.org.toLowerCase()+this._id.course.toLowerCase(), {target: this._id});
}
'''
reduce_fn
=
'''
function (idpair, matches) {
var result = {target: []};
matches.forEach(function (match) {
result.target.push(match.target);
});
return result;
}
'''
finalize
=
'''
function(key, reduced) {
if (Array.isArray(reduced.target)) {
return reduced;
}
else {return null;}
}
'''
results
=
mstore
.
collection
.
map_reduce
(
map_fn
,
reduce_fn
,
{
'inline'
:
True
},
query
=
{
'_id.category'
:
'course'
},
finalize
=
finalize
)
results
=
results
.
get
(
'results'
)
for
entry
in
results
:
if
entry
.
get
(
'value'
)
is
not
None
:
print
'{:-^40}'
.
format
(
entry
.
get
(
'_id'
))
for
course_id
in
entry
.
get
(
'value'
)
.
get
(
'target'
):
print
' {}/{}/{}'
.
format
(
course_id
.
get
(
'org'
),
course_id
.
get
(
'course'
),
course_id
.
get
(
'name'
))
cms/djangoapps/contentstore/management/commands/tests/__init__.py
0 → 100644
View file @
9cf318ce
cms/djangoapps/contentstore/management/commands/tests/test_course_id_clash.py
0 → 100644
View file @
9cf318ce
import
sys
from
StringIO
import
StringIO
from
django.test
import
TestCase
from
django.core.management
import
call_command
from
xmodule.modulestore.tests.factories
import
CourseFactory
class
ClashIdTestCase
(
TestCase
):
"""
Test for course_id_clash.
"""
def
test_course_clash
(
self
):
"""
Test for course_id_clash.
"""
expected
=
[]
# clashing courses
course
=
CourseFactory
.
create
(
org
=
"test"
,
course
=
"courseid"
,
display_name
=
"run1"
)
expected
.
append
(
course
.
location
.
course_id
)
course
=
CourseFactory
.
create
(
org
=
"TEST"
,
course
=
"courseid"
,
display_name
=
"RUN12"
)
expected
.
append
(
course
.
location
.
course_id
)
course
=
CourseFactory
.
create
(
org
=
"test"
,
course
=
"CourseId"
,
display_name
=
"aRUN123"
)
expected
.
append
(
course
.
location
.
course_id
)
# not clashing courses
not_expected
=
[]
course
=
CourseFactory
.
create
(
org
=
"test"
,
course
=
"course2"
,
display_name
=
"run1"
)
not_expected
.
append
(
course
.
location
.
course_id
)
course
=
CourseFactory
.
create
(
org
=
"test1"
,
course
=
"courseid"
,
display_name
=
"run1"
)
not_expected
.
append
(
course
.
location
.
course_id
)
course
=
CourseFactory
.
create
(
org
=
"test"
,
course
=
"courseid0"
,
display_name
=
"run1"
)
not_expected
.
append
(
course
.
location
.
course_id
)
old_stdout
=
sys
.
stdout
sys
.
stdout
=
mystdout
=
StringIO
()
call_command
(
'course_id_clash'
,
stdout
=
mystdout
)
sys
.
stdout
=
old_stdout
result
=
mystdout
.
getvalue
()
for
courseid
in
expected
:
self
.
assertIn
(
courseid
,
result
)
for
courseid
in
not_expected
:
self
.
assertNotIn
(
courseid
,
result
)
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