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
34ada8a2
Commit
34ada8a2
authored
Dec 29, 2014
by
Tim Babych
Committed by
Oleg Marshev
Jan 05, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support multiple ranges
parent
78eb4d29
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
47 deletions
+38
-47
notesapi/v1/models.py
+5
-16
notesapi/v1/tests/test_models.py
+0
-10
notesapi/v1/tests/test_views.py
+33
-21
No files found.
notesapi/v1/models.py
View file @
34ada8a2
...
@@ -12,10 +12,7 @@ class Note(models.Model):
...
@@ -12,10 +12,7 @@ class Note(models.Model):
usage_id
=
models
.
CharField
(
max_length
=
255
)
usage_id
=
models
.
CharField
(
max_length
=
255
)
text
=
models
.
TextField
(
default
=
""
)
text
=
models
.
TextField
(
default
=
""
)
quote
=
models
.
TextField
(
default
=
""
)
quote
=
models
.
TextField
(
default
=
""
)
range_start
=
models
.
CharField
(
max_length
=
2048
)
ranges
=
models
.
TextField
(
default
=
""
)
range_start_offset
=
models
.
IntegerField
()
range_end
=
models
.
CharField
(
max_length
=
2048
)
range_end_offset
=
models
.
IntegerField
()
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
created
=
models
.
DateTimeField
(
auto_now_add
=
True
)
updated
=
models
.
DateTimeField
(
auto_now
=
True
)
updated
=
models
.
DateTimeField
(
auto_now
=
True
)
...
@@ -42,13 +39,10 @@ class Note(models.Model):
...
@@ -42,13 +39,10 @@ class Note(models.Model):
raise
ValidationError
(
'Note must have a course_id and usage_id and user_id.'
)
raise
ValidationError
(
'Note must have a course_id and usage_id and user_id.'
)
ranges
=
note
.
get
(
'ranges'
)
ranges
=
note
.
get
(
'ranges'
)
if
ranges
is
None
or
len
(
ranges
)
!=
1
:
if
ranges
is
None
:
raise
ValidationError
(
'Note must contain
exactly
one range.'
)
raise
ValidationError
(
'Note must contain
at least
one range.'
)
self
.
range_start
=
ranges
[
0
][
'start'
]
self
.
ranges
=
json
.
dumps
(
ranges
)
self
.
range_start_offset
=
ranges
[
0
][
'startOffset'
]
self
.
range_end
=
ranges
[
0
][
'end'
]
self
.
range_end_offset
=
ranges
[
0
][
'endOffset'
]
def
as_dict
(
self
):
def
as_dict
(
self
):
"""
"""
...
@@ -64,12 +58,7 @@ class Note(models.Model):
...
@@ -64,12 +58,7 @@ class Note(models.Model):
'usage_id'
:
self
.
usage_id
,
'usage_id'
:
self
.
usage_id
,
'text'
:
self
.
text
,
'text'
:
self
.
text
,
'quote'
:
self
.
quote
,
'quote'
:
self
.
quote
,
'ranges'
:
[{
'ranges'
:
json
.
loads
(
self
.
ranges
),
'start'
:
self
.
range_start
,
'startOffset'
:
self
.
range_start_offset
,
'end'
:
self
.
range_end
,
'endOffset'
:
self
.
range_end_offset
}],
'created'
:
created
,
'created'
:
created
,
'updated'
:
updated
,
'updated'
:
updated
,
}
}
...
...
notesapi/v1/tests/test_models.py
View file @
34ada8a2
...
@@ -49,16 +49,6 @@ class NoteTest(TestCase):
...
@@ -49,16 +49,6 @@ class NoteTest(TestCase):
with
self
.
assertRaises
(
ValidationError
):
with
self
.
assertRaises
(
ValidationError
):
note
.
clean
(
payload
)
note
.
clean
(
payload
)
def
test_clean_many_ranges
(
self
):
note
=
Note
()
with
self
.
assertRaises
(
ValidationError
):
note
.
clean
({
'text'
:
'foo'
,
'quote'
:
'bar'
,
'ranges'
:
[{}
for
i
in
range
(
10
)]
# Too many ranges.
})
def
test_save
(
self
):
def
test_save
(
self
):
note
=
Note
()
note
=
Note
()
note
.
clean
(
self
.
note
)
note
.
clean
(
self
.
note
)
...
...
notesapi/v1/tests/test_views.py
View file @
34ada8a2
...
@@ -45,24 +45,6 @@ class BaseAnnotationViewTests(APITestCase):
...
@@ -45,24 +45,6 @@ class BaseAnnotationViewTests(APITestCase):
],
],
}
}
self
.
expected_note
=
{
# "created": "2014-11-26T00:00:00+00:00",
# "updated": "2014-11-26T00:00:00+00:00",
"user"
:
TEST_USER
,
"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
):
def
tearDown
(
self
):
for
note_id
in
note_searcher
.
all
()
.
values_list
(
'id'
):
for
note_id
in
note_searcher
.
all
()
.
values_list
(
'id'
):
get_es
()
.
delete
(
get_es
()
.
delete
(
...
@@ -140,7 +122,7 @@ class AnnotationViewTests(BaseAnnotationViewTests):
...
@@ -140,7 +122,7 @@ class AnnotationViewTests(BaseAnnotationViewTests):
del
annotation
[
'updated'
]
del
annotation
[
'updated'
]
del
annotation
[
'created'
]
del
annotation
[
'created'
]
self
.
assertEqual
(
annotation
,
self
.
expected_note
)
self
.
assertEqual
(
annotation
,
self
.
payload
)
expected_location
=
'/api/v1/annotations/{0}'
.
format
(
response
.
data
[
'id'
])
expected_location
=
'/api/v1/annotations/{0}'
.
format
(
response
.
data
[
'id'
])
self
.
assertTrue
(
self
.
assertTrue
(
...
@@ -201,11 +183,41 @@ class AnnotationViewTests(BaseAnnotationViewTests):
...
@@ -201,11 +183,41 @@ class AnnotationViewTests(BaseAnnotationViewTests):
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
expected_note
[
'id'
]
=
note_id
annotation
=
response
.
data
annotation
=
response
.
data
del
annotation
[
'id'
]
del
annotation
[
'updated'
]
del
annotation
[
'created'
]
self
.
assertEqual
(
annotation
,
self
.
payload
)
def
test_create_multirange
(
self
):
"""
Create a note that has several ranges and read it
"""
note
=
self
.
payload
.
copy
()
ranges
=
[{
"start"
:
"/p[1]"
,
"end"
:
"/p[1]"
,
"startOffset"
:
0
,
"endOffset"
:
10
,
},
{
"start"
:
"/p[2]"
,
"end"
:
"/p[2]"
,
"startOffset"
:
20
,
"endOffset"
:
22
,
}
]
note
[
'ranges'
]
=
ranges
note_id
=
self
.
_create_annotation
(
**
note
)[
'id'
]
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
note_id
})
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
annotation
=
response
.
data
del
annotation
[
'id'
]
del
annotation
[
'updated'
]
del
annotation
[
'updated'
]
del
annotation
[
'created'
]
del
annotation
[
'created'
]
self
.
assertEqual
(
annotation
,
self
.
expected_
note
)
self
.
assertEqual
(
annotation
,
note
)
def
test_read_notfound
(
self
):
def
test_read_notfound
(
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