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
a7427735
Commit
a7427735
authored
Jan 06, 2015
by
Tim Babych
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add order_by('-updated') in list all notes view, test
parent
be57ec26
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
23 deletions
+37
-23
notesapi/v1/tests/test_views.py
+36
-19
notesapi/v1/views.py
+1
-4
No files found.
notesapi/v1/tests/test_views.py
View file @
a7427735
...
...
@@ -67,7 +67,7 @@ class BaseAnnotationViewTests(APITestCase):
def
_get_annotation
(
self
,
annotation_id
):
"""
Fetch annotation
directly from elasticsearch.
Fetch annotation
"""
call_command
(
'update_index'
)
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
annotation_id
})
...
...
@@ -75,16 +75,6 @@ class BaseAnnotationViewTests(APITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
return
response
.
data
def
_get_search_results
(
self
,
**
kwargs
):
"""
Helper for search method. All keyword parameters are passed in GET
"""
q
=
QueryDict
(
"user="
+
TEST_USER
,
mutable
=
True
)
q
.
update
(
kwargs
)
url
=
reverse
(
'api:v1:annotations_search'
)
+
'?{}'
.
format
(
q
.
urlencode
())
result
=
self
.
client
.
get
(
url
)
return
result
.
data
class
AnnotationListViewTests
(
BaseAnnotationViewTests
):
"""
...
...
@@ -192,9 +182,9 @@ class AnnotationListViewTests(BaseAnnotationViewTests):
"""
Tests list all annotations endpoint when no annotations are present in database.
"""
url
=
reverse
(
'api:v1:annotations'
)
self
.
headers
[
"course_id"
]
=
"a/b/c"
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
headers
=
self
.
headers
.
copy
(
)
headers
[
"course_id"
]
=
"a/b/c"
response
=
self
.
client
.
get
(
reverse
(
'api:v1:annotations'
),
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
len
(
response
.
data
),
0
,
"no annotation should be returned in response"
)
...
...
@@ -206,18 +196,35 @@ class AnnotationListViewTests(BaseAnnotationViewTests):
kwargs
=
{
'text'
:
'Foo_{}'
.
format
(
i
)}
self
.
_create_annotation
(
**
kwargs
)
url
=
reverse
(
'api:v1:annotations'
)
self
.
headers
[
"course_id"
]
=
"test-course-id"
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
headers
=
self
.
headers
.
copy
(
)
headers
[
"course_id"
]
=
"test-course-id"
response
=
self
.
client
.
get
(
reverse
(
'api:v1:annotations'
),
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
len
(
response
.
data
),
5
,
"five annotations should be returned in response"
)
def
test_read_all_ordering
(
self
):
"""
Tests ordering of listing of all notes.
Sorting is by descending order (most recent first).
"""
self
.
_create_annotation
(
text
=
u'First one'
)
self
.
_create_annotation
(
text
=
u'Second note'
)
self
.
_create_annotation
(
text
=
u'Third note'
)
headers
=
self
.
headers
.
copy
()
headers
[
"course_id"
]
=
"test-course-id"
results
=
self
.
client
.
get
(
reverse
(
'api:v1:annotations'
),
headers
)
.
data
self
.
assertEqual
(
results
[
0
][
'text'
],
'Third note'
)
self
.
assertEqual
(
results
[
1
][
'text'
],
'Second note'
)
self
.
assertEqual
(
results
[
2
][
'text'
],
'First one'
)
def
test_read_all_no_query_param
(
self
):
"""
Tests list all annotations when course_id query param is not present.
"""
url
=
reverse
(
'api:v1:annotations'
)
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
response
=
self
.
client
.
get
(
reverse
(
'api:v1:annotations'
),
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
...
...
@@ -351,6 +358,16 @@ class AnnotationSearchlViewTests(BaseAnnotationViewTests):
"""
Test annotation searching by user, course_id, usage_id and text
"""
def
_get_search_results
(
self
,
**
kwargs
):
"""
Helper for search method. All keyword parameters are passed in GET
"""
q
=
QueryDict
(
"user="
+
TEST_USER
,
mutable
=
True
)
q
.
update
(
kwargs
)
url
=
reverse
(
'api:v1:annotations_search'
)
+
'?{}'
.
format
(
q
.
urlencode
())
result
=
self
.
client
.
get
(
url
)
return
result
.
data
def
test_search
(
self
):
"""
Tests for search method.
...
...
notesapi/v1/views.py
View file @
a7427735
...
...
@@ -88,10 +88,7 @@ class AnnotationListView(APIView):
if
'course_id'
not
in
params
:
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
)
try
:
results
=
Note
.
objects
.
filter
(
course_id
=
params
[
'course_id'
],
user_id
=
params
[
'user'
])
except
Note
.
DoesNotExist
:
pass
results
=
Note
.
objects
.
filter
(
course_id
=
params
[
'course_id'
],
user_id
=
params
[
'user'
])
.
order_by
(
'-updated'
)
return
Response
([
result
.
as_dict
()
for
result
in
results
])
...
...
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