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
23c49ecc
Commit
23c49ecc
authored
Dec 26, 2014
by
Tim Babych
Committed by
Oleg Marshev
Jan 05, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
enable search
parent
e7967f31
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
20 deletions
+20
-20
notesapi/v1/tests/test_views.py
+17
-19
notesapi/v1/views.py
+3
-1
No files found.
notesapi/v1/tests/test_views.py
View file @
23c49ecc
...
...
@@ -87,12 +87,10 @@ class BaseAnnotationViewTests(APITestCase):
"""
Create annotation
"""
opts
=
{
'user'
:
TEST_USER
,
}
opts
=
self
.
payload
.
copy
()
opts
.
update
(
kwargs
)
url
=
reverse
(
'api:v1:annotations'
)
response
=
self
.
client
.
post
(
url
,
self
.
payload
,
format
=
'json'
)
response
=
self
.
client
.
post
(
url
,
opts
,
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
es
.
indices
.
refresh
()
return
response
.
data
.
copy
()
...
...
@@ -295,21 +293,21 @@ class AnnotationViewTests(BaseAnnotationViewTests):
# response = self.client.delete(url, self.headers)
# self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND, "response should be 404 NOT FOUND")
#
def test_search(self):
#
"""
#
Tests for search method.
#
"""
#
note_1 = self._create_annotation(text=u'First one')
#
note_2 = self._create_annotation(text=u'Second note')
#
note_3 = self._create_annotation(text=u'Third note')
#
results = self._get_search_results()
#
self.assertEqual(results['total'], 3)
#
results = self._get_search_results("text=Second")
#
self.assertEqual(results['total'], 1)
#
self.assertEqual(len(results['rows']), 1)
#
self.assertEqual(results['rows'][0]['text'], 'Second note')
def
test_search
(
self
):
"""
Tests for search method.
"""
note_1
=
self
.
_create_annotation
(
text
=
u'First one'
)
note_2
=
self
.
_create_annotation
(
text
=
u'Second note'
)
note_3
=
self
.
_create_annotation
(
text
=
u'Third note'
)
results
=
self
.
_get_search_results
()
self
.
assertEqual
(
results
[
'total'
],
3
)
results
=
self
.
_get_search_results
(
"text=Second"
)
self
.
assertEqual
(
results
[
'total'
],
1
)
self
.
assertEqual
(
len
(
results
[
'rows'
]),
1
)
self
.
assertEqual
(
results
[
'rows'
][
0
][
'text'
],
'Second note'
)
# def test_search_ordering(self):
# """
...
...
notesapi/v1/views.py
View file @
23c49ecc
...
...
@@ -25,7 +25,9 @@ class AnnotationSearchView(APIView):
"""
Search annotations.
"""
params
=
self
.
request
.
QUERY_PARAMS
.
dict
()
params
=
{}
for
k
,
v
in
self
.
request
.
QUERY_PARAMS
.
dict
()
.
items
():
params
[
k
]
=
v
.
lower
()
results
=
NoteMappingType
.
process_result
(
list
(
note_searcher
.
filter
(
**
params
)
.
values_dict
(
"_source"
))
)
...
...
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