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
2eff9cdc
Commit
2eff9cdc
authored
Dec 30, 2014
by
Oleg Marshev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some mapping type tests.
parent
5d4a23ac
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletions
+30
-1
notesapi/v1/models.py
+12
-1
notesapi/v1/tests/test_models.py
+18
-0
No files found.
notesapi/v1/models.py
View file @
2eff9cdc
...
@@ -82,6 +82,10 @@ def delete_in_index(sender, instance, **kwargs):
...
@@ -82,6 +82,10 @@ def delete_in_index(sender, instance, **kwargs):
class
NoteMappingType
(
MappingType
,
Indexable
):
class
NoteMappingType
(
MappingType
,
Indexable
):
"""
Mapping type for Note.
"""
@classmethod
@classmethod
def
get_model
(
cls
):
def
get_model
(
cls
):
return
Note
return
Note
...
@@ -107,7 +111,9 @@ class NoteMappingType(MappingType, Indexable):
...
@@ -107,7 +111,9 @@ class NoteMappingType(MappingType, Indexable):
@classmethod
@classmethod
def
extract_document
(
cls
,
obj_id
,
obj
=
None
):
def
extract_document
(
cls
,
obj_id
,
obj
=
None
):
"""Converts this instance into an Elasticsearch document"""
"""
Converts this instance into an Elasticsearch document.
"""
if
obj
is
None
:
if
obj
is
None
:
obj
=
cls
.
get_model
()
.
objects
.
get
(
pk
=
obj_id
)
obj
=
cls
.
get_model
()
.
objects
.
get
(
pk
=
obj_id
)
...
@@ -115,6 +121,11 @@ class NoteMappingType(MappingType, Indexable):
...
@@ -115,6 +121,11 @@ class NoteMappingType(MappingType, Indexable):
@staticmethod
@staticmethod
def
process_result
(
data
):
def
process_result
(
data
):
"""
Prepares result for response.
Also prepares ranges field and highlighting.
"""
for
i
,
item
in
enumerate
(
data
):
for
i
,
item
in
enumerate
(
data
):
if
isinstance
(
item
,
dict
):
if
isinstance
(
item
,
dict
):
for
k
,
v
in
item
.
items
():
for
k
,
v
in
item
.
items
():
...
...
notesapi/v1/tests/test_models.py
View file @
2eff9cdc
...
@@ -58,3 +58,21 @@ class NoteTest(TestCase):
...
@@ -58,3 +58,21 @@ class NoteTest(TestCase):
note
.
clean
(
self
.
note
)
note
.
clean
(
self
.
note
)
note
.
save
()
note
.
save
()
self
.
assertEqual
(
NoteMappingType
.
extract_document
(
note
.
id
),
note
.
as_dict
())
self
.
assertEqual
(
NoteMappingType
.
extract_document
(
note
.
id
),
note
.
as_dict
())
def
test_get_model
(
self
):
self
.
assertIsInstance
(
NoteMappingType
.
get_model
()(),
Note
)
def
test_get_mapping
(
self
):
expected_mapping
=
{
'properties'
:
{
'id'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
,
'store'
:
True
},
'user'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
,
'store'
:
True
},
'course_id'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
,
'store'
:
True
},
'usage_id'
:
{
'type'
:
'string'
,
'index'
:
'not_analyzed'
,
'store'
:
True
},
'text'
:
{
'type'
:
'string'
,
'analyzer'
:
'snowball'
,
'store'
:
True
},
'quote'
:
{
'type'
:
'string'
,
'analyzer'
:
'snowball'
,
'store'
:
True
},
'created'
:
{
'type'
:
'date'
,
'store'
:
True
},
'updated'
:
{
'type'
:
'date'
,
'store'
:
True
},
}
}
self
.
assertEqual
(
NoteMappingType
.
get_mapping
(),
expected_mapping
)
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