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
6acae5b4
Commit
6acae5b4
authored
Dec 10, 2012
by
Christina Roberts
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Show error if organization name has invalid characters
parent
495b5824
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
15 deletions
+25
-15
cms/djangoapps/contentstore/tests/tests.py
+19
-12
cms/djangoapps/contentstore/views.py
+5
-2
common/lib/xmodule/xmodule/modulestore/__init__.py
+1
-1
No files found.
cms/djangoapps/contentstore/tests/tests.py
View file @
6acae5b4
import
json
import
json
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.test.client
import
Client
from
django.test.client
import
Client
from
mock
import
patch
,
Mock
from
override_settings
import
override_settings
from
override_settings
import
override_settings
from
django.conf
import
settings
from
django.conf
import
settings
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
...
@@ -9,9 +8,7 @@ from path import path
...
@@ -9,9 +8,7 @@ from path import path
from
student.models
import
Registration
from
student.models
import
Registration
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
xmodule.modulestore.django
import
modulestore
import
xmodule.modulestore.django
import
xmodule.modulestore.django
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.xml_importer
import
import_from_xml
from
xmodule.modulestore.xml_importer
import
import_from_xml
import
copy
import
copy
from
factories
import
*
from
factories
import
*
...
@@ -23,33 +20,33 @@ def parse_json(response):
...
@@ -23,33 +20,33 @@ def parse_json(response):
def
user
(
email
):
def
user
(
email
):
'''look up a user by email'''
"""look up a user by email"""
return
User
.
objects
.
get
(
email
=
email
)
return
User
.
objects
.
get
(
email
=
email
)
def
registration
(
email
):
def
registration
(
email
):
'''look up registration object by email'''
"""look up registration object by email"""
return
Registration
.
objects
.
get
(
user__email
=
email
)
return
Registration
.
objects
.
get
(
user__email
=
email
)
class
ContentStoreTestCase
(
TestCase
):
class
ContentStoreTestCase
(
TestCase
):
def
_login
(
self
,
email
,
pw
):
def
_login
(
self
,
email
,
pw
):
'''
Login. View should always return 200. The success/fail is in the
"""
Login. View should always return 200. The success/fail is in the
returned json
'''
returned json
"""
resp
=
self
.
client
.
post
(
reverse
(
'login_post'
),
resp
=
self
.
client
.
post
(
reverse
(
'login_post'
),
{
'email'
:
email
,
'password'
:
pw
})
{
'email'
:
email
,
'password'
:
pw
})
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
return
resp
return
resp
def
login
(
self
,
email
,
pw
):
def
login
(
self
,
email
,
pw
):
'''Login, check that it worked.'''
"""Login, check that it worked."""
resp
=
self
.
_login
(
email
,
pw
)
resp
=
self
.
_login
(
email
,
pw
)
data
=
parse_json
(
resp
)
data
=
parse_json
(
resp
)
self
.
assertTrue
(
data
[
'success'
])
self
.
assertTrue
(
data
[
'success'
])
return
resp
return
resp
def
_create_account
(
self
,
username
,
email
,
pw
):
def
_create_account
(
self
,
username
,
email
,
pw
):
'''Try to create an account. No error checking'''
"""Try to create an account. No error checking"""
resp
=
self
.
client
.
post
(
'/create_account'
,
{
resp
=
self
.
client
.
post
(
'/create_account'
,
{
'username'
:
username
,
'username'
:
username
,
'email'
:
email
,
'email'
:
email
,
...
@@ -63,7 +60,7 @@ class ContentStoreTestCase(TestCase):
...
@@ -63,7 +60,7 @@ class ContentStoreTestCase(TestCase):
return
resp
return
resp
def
create_account
(
self
,
username
,
email
,
pw
):
def
create_account
(
self
,
username
,
email
,
pw
):
'''Create the account and check that it worked'''
"""Create the account and check that it worked"""
resp
=
self
.
_create_account
(
username
,
email
,
pw
)
resp
=
self
.
_create_account
(
username
,
email
,
pw
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
data
=
parse_json
(
resp
)
data
=
parse_json
(
resp
)
...
@@ -75,8 +72,8 @@ class ContentStoreTestCase(TestCase):
...
@@ -75,8 +72,8 @@ class ContentStoreTestCase(TestCase):
return
resp
return
resp
def
_activate_user
(
self
,
email
):
def
_activate_user
(
self
,
email
):
'''
Look up the activation key for the user, then hit the activate view.
"""
Look up the activation key for the user, then hit the activate view.
No error checking
'''
No error checking
"""
activation_key
=
registration
(
email
)
.
activation_key
activation_key
=
registration
(
email
)
.
activation_key
# and now we try to activate
# and now we try to activate
...
@@ -257,6 +254,16 @@ class ContentStoreTest(TestCase):
...
@@ -257,6 +254,16 @@ class ContentStoreTest(TestCase):
self
.
assertEqual
(
data
[
'ErrMsg'
],
self
.
assertEqual
(
data
[
'ErrMsg'
],
'There is already a course defined with the same organization and course number.'
)
'There is already a course defined with the same organization and course number.'
)
def
test_create_course_with_bad_organization
(
self
):
"""Test new course creation - error path for bad organization name"""
self
.
course_data
[
'org'
]
=
'University of California, Berkeley'
resp
=
self
.
client
.
post
(
reverse
(
'create_new_course'
),
self
.
course_data
)
data
=
parse_json
(
resp
)
self
.
assertEqual
(
resp
.
status_code
,
200
)
self
.
assertEqual
(
data
[
'ErrMsg'
],
"Unable to create course 'Robot Super Course'.
\n\n
Invalid characters in 'University of California, Berkeley'."
)
def
test_course_index_view_with_no_courses
(
self
):
def
test_course_index_view_with_no_courses
(
self
):
"""Test viewing the index page with no courses"""
"""Test viewing the index page with no courses"""
# Create a course so there is something to view
# Create a course so there is something to view
...
...
cms/djangoapps/contentstore/views.py
View file @
6acae5b4
...
@@ -23,7 +23,7 @@ from django.core.urlresolvers import reverse
...
@@ -23,7 +23,7 @@ from django.core.urlresolvers import reverse
from
django.conf
import
settings
from
django.conf
import
settings
from
xmodule.modulestore
import
Location
from
xmodule.modulestore
import
Location
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
from
xmodule.modulestore.exceptions
import
ItemNotFoundError
,
InvalidLocationError
from
xmodule.x_module
import
ModuleSystem
from
xmodule.x_module
import
ModuleSystem
from
xmodule.error_module
import
ErrorDescriptor
from
xmodule.error_module
import
ErrorDescriptor
from
xmodule.errortracker
import
exc_info_to_str
from
xmodule.errortracker
import
exc_info_to_str
...
@@ -1053,7 +1053,10 @@ def create_new_course(request):
...
@@ -1053,7 +1053,10 @@ def create_new_course(request):
number
=
request
.
POST
.
get
(
'number'
)
number
=
request
.
POST
.
get
(
'number'
)
display_name
=
request
.
POST
.
get
(
'display_name'
)
display_name
=
request
.
POST
.
get
(
'display_name'
)
dest_location
=
Location
(
'i4x'
,
org
,
number
,
'course'
,
Location
.
clean
(
display_name
))
try
:
dest_location
=
Location
(
'i4x'
,
org
,
number
,
'course'
,
Location
.
clean
(
display_name
))
except
InvalidLocationError
as
e
:
return
HttpResponse
(
json
.
dumps
({
'ErrMsg'
:
"Unable to create course '"
+
display_name
+
"'.
\n\n
"
+
e
.
message
}))
# see if the course already exists
# see if the course already exists
existing_course
=
None
existing_course
=
None
...
...
common/lib/xmodule/xmodule/modulestore/__init__.py
View file @
6acae5b4
...
@@ -153,7 +153,7 @@ class Location(_LocationBase):
...
@@ -153,7 +153,7 @@ class Location(_LocationBase):
def
check
(
val
,
regexp
):
def
check
(
val
,
regexp
):
if
val
is
not
None
and
regexp
.
search
(
val
)
is
not
None
:
if
val
is
not
None
and
regexp
.
search
(
val
)
is
not
None
:
log
.
debug
(
'invalid characters val="
%
s", list_="
%
s"'
%
(
val
,
list_
))
log
.
debug
(
'invalid characters val="
%
s", list_="
%
s"'
%
(
val
,
list_
))
raise
InvalidLocationError
(
location
)
raise
InvalidLocationError
(
"Invalid characters in '
%
s'."
%
(
val
)
)
list_
=
list
(
list_
)
list_
=
list
(
list_
)
for
val
in
list_
[:
4
]
+
[
list_
[
5
]]:
for
val
in
list_
[:
4
]
+
[
list_
[
5
]]:
...
...
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