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
3674d4fe
Commit
3674d4fe
authored
Nov 01, 2013
by
Don Mitchell
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1484 from edx/dhm/course_id_clash
Course id clash command
parents
9f104eb6
32a6df0f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
95 additions
and
1 deletions
+95
-1
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
+42
-0
common/lib/xmodule/xmodule/modulestore/tests/factories.py
+2
-1
No files found.
cms/djangoapps/contentstore/management/commands/course_id_clash.py
0 → 100644
View file @
3674d4fe
"""
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 @
3674d4fe
cms/djangoapps/contentstore/management/commands/tests/test_course_id_clash.py
0 → 100644
View file @
3674d4fe
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
from
nose.plugins.skip
import
SkipTest
@SkipTest
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
)
common/lib/xmodule/xmodule/modulestore/tests/factories.py
View file @
3674d4fe
...
...
@@ -46,7 +46,8 @@ class CourseFactory(XModuleFactory):
# passed in via **kwargs. However, some of those aren't actual field values,
# so pop those off for use separately
org
=
kwargs
.
pop
(
'org'
,
None
)
number
=
kwargs
.
pop
(
'number'
,
kwargs
.
pop
(
'course'
,
None
))
# because the factory provides a default 'number' arg, prefer the non-defaulted 'course' arg if any
number
=
kwargs
.
pop
(
'course'
,
kwargs
.
pop
(
'number'
,
None
))
store
=
kwargs
.
pop
(
'modulestore'
)
location
=
Location
(
'i4x'
,
org
,
number
,
'course'
,
Location
.
clean
(
kwargs
.
get
(
'display_name'
)))
...
...
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