Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-notes-api
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-notes-api
Commits
ed625054
Commit
ed625054
authored
Nov 26, 2014
by
Oleg Marshev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove refresh parameter.
parent
c89ad455
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
29 deletions
+39
-29
notesapi/v1/tests/test_views.py
+31
-26
notesapi/v1/views.py
+8
-3
No files found.
notesapi/v1/tests/test_views.py
View file @
ed625054
...
...
@@ -28,6 +28,22 @@ class AnnotationViewTests(APITestCase):
token
=
auth
.
encode_token
(
payload
,
self
.
user
.
consumer
.
secret
)
self
.
headers
=
{
'x-annotator-auth-token'
:
token
}
self
.
payload
=
{
"user"
:
"test-user-id"
,
"usage_id"
:
"test-usage-id"
,
"course_id"
:
"test-course-id"
,
"text"
:
"test note text"
,
"quote"
:
"test note quote"
,
"ranges"
:
[
{
"start"
:
"/p[1]"
,
"end"
:
"/p[1]"
,
"startOffset"
:
0
,
"endOffset"
:
10
,
}
],
}
def
tearDown
(
self
):
annotation
.
Annotation
.
drop_all
()
...
...
@@ -58,16 +74,25 @@ class AnnotationViewTests(APITestCase):
result
=
self
.
client
.
get
(
url
,
**
self
.
headers
)
return
result
.
data
def
test_create_no_payload
(
self
):
"""
Test if no payload is sent when creating a note.
"""
url
=
reverse
(
'api:v1:annotations'
)
response
=
self
.
client
.
post
(
url
,
{},
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
def
test_create_note
(
self
):
"""
Ensure we can create a new note.
"""
url
=
reverse
(
'api:v1:annotations'
)
payload
=
{
'text'
:
'testing notes'
}
response
=
self
.
client
.
post
(
url
,
payload
,
format
=
'json'
)
response
=
self
.
client
.
post
(
url
,
self
.
payload
,
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
self
.
assertIn
(
'id'
,
response
.
data
,
"annotation id should be returned in response"
)
self
.
assertIn
(
'created'
,
response
.
data
,
"annotation created field should be returned in response"
)
self
.
assertIn
(
'updated'
,
response
.
data
,
"annotation updated field be returned in response"
)
expected_location
=
'/api/v1/annotations/{0}'
.
format
(
response
.
data
[
'id'
])
self
.
assertTrue
(
...
...
@@ -82,8 +107,8 @@ class AnnotationViewTests(APITestCase):
"""
Test if annotation 'created' field is not used by API.
"""
payload
=
{
'created'
:
'abc'
}
response
=
self
.
client
.
post
(
reverse
(
'api:v1:annotations'
),
payload
,
format
=
'json'
,
**
self
.
headers
)
self
.
payload
[
'created'
]
=
'abc'
response
=
self
.
client
.
post
(
reverse
(
'api:v1:annotations'
),
self
.
payload
,
format
=
'json'
,
**
self
.
headers
)
annotation
=
self
.
_get_annotation
(
response
.
data
[
'id'
])
...
...
@@ -93,8 +118,8 @@ class AnnotationViewTests(APITestCase):
"""
Test if annotation 'updated' field is not used by API.
"""
payload
=
{
'updated'
:
'abc'
}
response
=
self
.
client
.
post
(
reverse
(
'api:v1:annotations'
),
payload
,
format
=
'json'
,
**
self
.
headers
)
self
.
payload
[
'updated'
]
=
'abc'
response
=
self
.
client
.
post
(
reverse
(
'api:v1:annotations'
),
self
.
payload
,
format
=
'json'
,
**
self
.
headers
)
annotation
=
self
.
_get_annotation
(
response
.
data
[
'id'
])
...
...
@@ -133,26 +158,6 @@ class AnnotationViewTests(APITestCase):
self
.
assertEqual
(
annotation_1
[
'name'
],
'foo'
)
self
.
assertEqual
(
annotation_2
[
'name'
],
'bar'
)
@patch
(
'notesapi.v1.views.Annotation'
,
autospec
=
Annotation
)
def
test_create_refresh
(
self
,
mocked_annotation
):
"""
Ensure save was with refresh.
"""
mocked_annotation
.
return_value
.
__getitem__
=
lambda
x
,
y
:
'test_id'
url
=
reverse
(
'api:v1:annotations'
)
+
'?refresh=true'
response
=
self
.
client
.
post
(
url
,
{},
format
=
'json'
,
**
self
.
headers
)
mocked_annotation
.
return_value
.
save
.
assert_called_once_with
(
refresh
=
True
)
@patch
(
'notesapi.v1.views.Annotation'
,
autospec
=
Annotation
)
def
test_create_disable_refresh
(
self
,
mocked_annotation
):
"""
Ensure save was without refresh.
"""
mocked_annotation
.
return_value
.
__getitem__
=
lambda
x
,
y
:
'test_id'
url
=
reverse
(
'api:v1:annotations'
)
+
'?refresh=false'
response
=
self
.
client
.
post
(
url
,
{},
format
=
'json'
,
**
self
.
headers
)
mocked_annotation
.
return_value
.
save
.
assert_called_once_with
(
refresh
=
False
)
def
test_read
(
self
):
"""
Ensure we can get an existing annotation.
...
...
notesapi/v1/views.py
View file @
ed625054
...
...
@@ -63,11 +63,16 @@ class AnnotationListView(APIView):
def
post
(
self
,
request
,
*
args
,
**
kwargs
):
"""
Create a new annotation.
Returns 400 request if bad payload is sent or it was empty object.
"""
annotation
=
Annotation
(
_filter_input
(
request
.
DATA
,
CREATE_FILTER_FIELDS
))
filtered_payload
=
_filter_input
(
request
.
DATA
,
CREATE_FILTER_FIELDS
)
if
len
(
filtered_payload
)
==
0
:
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
refresh
=
request
.
QUERY_PARAMS
.
get
(
'refresh'
)
!=
u'false'
annotation
.
save
(
refresh
=
refresh
)
annotation
=
Annotation
(
filtered_payload
)
annotation
.
save
(
refresh
=
True
)
location
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
annotation
[
'id'
]})
...
...
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