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
aad5096c
Commit
aad5096c
authored
May 09, 2013
by
Arthur Barrett
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add more tests for update and delete actions
parent
2838dba1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
67 additions
and
5 deletions
+67
-5
lms/djangoapps/notes/tests.py
+67
-5
No files found.
lms/djangoapps/notes/tests.py
View file @
aad5096c
...
@@ -70,6 +70,9 @@ class ApiTest(TestCase):
...
@@ -70,6 +70,9 @@ class ApiTest(TestCase):
'tags'
:
'a,b,c'
'tags'
:
'a,b,c'
}
}
# Make sure no note with this ID ever exists for testing purposes
self
.
NOTE_ID_DOES_NOT_EXIST
=
99999
def
mock_api_enabled
(
self
,
is_enabled
):
def
mock_api_enabled
(
self
,
is_enabled
):
return
(
lambda
request
,
course_id
:
is_enabled
)
return
(
lambda
request
,
course_id
:
is_enabled
)
...
@@ -208,11 +211,9 @@ class ApiTest(TestCase):
...
@@ -208,11 +211,9 @@ class ApiTest(TestCase):
self
.
assertEqual
(
content
[
'user_id'
],
note
.
user_id
)
self
.
assertEqual
(
content
[
'user_id'
],
note
.
user_id
)
def
test_note_doesnt_exist_to_read
(
self
):
def
test_note_doesnt_exist_to_read
(
self
):
NOTE_ID_DOES_NOT_EXIST
=
99999
self
.
login
()
self
.
login
()
resp
=
self
.
client
.
get
(
self
.
url
(
'notes_api_note'
,
{
resp
=
self
.
client
.
get
(
self
.
url
(
'notes_api_note'
,
{
'note_id'
:
NOTE_ID_DOES_NOT_EXIST
'note_id'
:
self
.
NOTE_ID_DOES_NOT_EXIST
}))
}))
self
.
assertEqual
(
resp
.
status_code
,
404
)
self
.
assertEqual
(
resp
.
status_code
,
404
)
self
.
assertEqual
(
resp
.
content
,
''
)
self
.
assertEqual
(
resp
.
content
,
''
)
...
@@ -228,9 +229,70 @@ class ApiTest(TestCase):
...
@@ -228,9 +229,70 @@ class ApiTest(TestCase):
self
.
assertEqual
(
resp
.
status_code
,
403
)
self
.
assertEqual
(
resp
.
status_code
,
403
)
self
.
assertEqual
(
resp
.
content
,
''
)
self
.
assertEqual
(
resp
.
content
,
''
)
@unittest.skip
(
"skipping update test stub"
)
def
test_delete_note
(
self
):
self
.
login
()
notes
=
self
.
create_notes
(
1
)
self
.
assertEqual
(
len
(
notes
),
1
)
note
=
notes
[
0
]
resp
=
self
.
client
.
delete
(
self
.
url
(
'notes_api_note'
,
{
'note_id'
:
note
.
id
}))
self
.
assertEqual
(
resp
.
status_code
,
204
)
self
.
assertEqual
(
resp
.
content
,
''
)
with
self
.
assertRaises
(
models
.
Note
.
DoesNotExist
):
models
.
Note
.
objects
.
get
(
pk
=
note
.
id
)
def
test_note_does_not_exist_to_delete
(
self
):
self
.
login
()
resp
=
self
.
client
.
delete
(
self
.
url
(
'notes_api_note'
,
{
'note_id'
:
self
.
NOTE_ID_DOES_NOT_EXIST
}))
self
.
assertEqual
(
resp
.
status_code
,
404
)
self
.
assertEqual
(
resp
.
content
,
''
)
def
test_student_doesnt_have_permission_to_delete_note
(
self
):
notes
=
self
.
create_notes
(
1
)
self
.
assertEqual
(
len
(
notes
),
1
)
note
=
notes
[
0
]
self
.
login
(
as_student
=
self
.
student2
)
resp
=
self
.
client
.
delete
(
self
.
url
(
'notes_api_note'
,
{
'note_id'
:
note
.
id
}))
self
.
assertEqual
(
resp
.
status_code
,
403
)
self
.
assertEqual
(
resp
.
content
,
''
)
try
:
models
.
Note
.
objects
.
get
(
pk
=
note
.
id
)
except
models
.
Note
.
DoesNotExist
:
self
.
fail
(
'note should exist and not be deleted because the student does not have permission to do so'
)
def
test_update_note
(
self
):
def
test_update_note
(
self
):
pass
notes
=
self
.
create_notes
(
1
)
note
=
notes
[
0
]
updated_dict
=
note
.
as_dict
()
updated_dict
.
update
({
'text'
:
'itchy and scratchy'
,
'tags'
:
[
'simpsons'
,
'cartoons'
,
'animation'
]
})
self
.
login
()
resp
=
self
.
client
.
put
(
self
.
url
(
'notes_api_note'
,
{
'note_id'
:
note
.
id
}),
json
.
dumps
(
updated_dict
),
content_type
=
'application/json'
,
HTTP_X_REQUESTED_WITH
=
'XMLHttpRequest'
)
self
.
assertEqual
(
resp
.
status_code
,
303
)
self
.
assertEqual
(
resp
.
content
,
''
)
actual
=
models
.
Note
.
objects
.
get
(
pk
=
note
.
id
)
actual_dict
=
actual
.
as_dict
()
for
field
in
[
'text'
,
'tags'
]:
self
.
assertEqual
(
actual_dict
[
field
],
updated_dict
[
field
])
@unittest.skip
(
"skipping search test stub"
)
@unittest.skip
(
"skipping search test stub"
)
def
test_search_note
(
self
):
def
test_search_note
(
self
):
...
...
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