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
d3c1929d
Commit
d3c1929d
authored
Dec 26, 2014
by
Tim Babych
Committed by
Oleg Marshev
Jan 05, 2015
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
delete is in
parent
84b6db7c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
39 additions
and
32 deletions
+39
-32
notesapi/v1/models.py
+17
-7
notesapi/v1/tests/test_views.py
+20
-18
notesapi/v1/views.py
+2
-7
No files found.
notesapi/v1/models.py
View file @
d3c1929d
...
@@ -2,10 +2,9 @@ import json
...
@@ -2,10 +2,9 @@ import json
from
django.db
import
models
from
django.db
import
models
from
django.core.exceptions
import
ValidationError
from
django.core.exceptions
import
ValidationError
from
django.conf
import
settings
from
django.conf
import
settings
from
django.db.models
.signals
import
post_save
from
django.db.models
import
signals
from
django.dispatch
import
receiver
from
django.dispatch
import
receiver
from
elasticutils.contrib.django
import
Indexable
,
MappingType
from
elasticutils.contrib.django
import
Indexable
,
MappingType
,
get_es
class
Note
(
models
.
Model
):
class
Note
(
models
.
Model
):
user_id
=
models
.
CharField
(
max_length
=
255
)
user_id
=
models
.
CharField
(
max_length
=
255
)
...
@@ -77,11 +76,22 @@ class Note(models.Model):
...
@@ -77,11 +76,22 @@ class Note(models.Model):
@receiver
(
post_save
,
sender
=
Note
)
@receiver
(
signals
.
post_save
,
sender
=
Note
)
def
update_in_index
(
sender
,
instance
,
**
kw
):
def
update_in_index
(
sender
,
instance
,
**
kw
):
if
settings
.
ES_DISABLED
:
if
settings
.
ES_DISABLED
:
return
return
NoteMappingType
.
bulk_index
([
instance
.
as_dict
()],
id_field
=
'id'
)
NoteMappingType
.
bulk_index
([
instance
.
as_dict
()],
id_field
=
'id'
)
@receiver
(
signals
.
post_delete
,
sender
=
Note
)
def
delete_in_index
(
sender
,
instance
,
**
kw
):
if
settings
.
ES_DISABLED
:
return
get_es
()
.
delete
(
index
=
settings
.
ES_INDEXES
[
'default'
],
doc_type
=
NoteMappingType
.
get_mapping_type_name
(),
id
=
instance
.
id
)
class
NoteMappingType
(
MappingType
,
Indexable
):
class
NoteMappingType
(
MappingType
,
Indexable
):
...
...
notesapi/v1/tests/test_views.py
View file @
d3c1929d
import
jwt
import
jwt
from
calendar
import
timegm
from
calendar
import
timegm
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
time
import
sleep
from
mock
import
patch
from
mock
import
patch
import
unittest
import
unittest
...
@@ -274,25 +273,28 @@ class AnnotationViewTests(BaseAnnotationViewTests):
...
@@ -274,25 +273,28 @@ class AnnotationViewTests(BaseAnnotationViewTests):
# response = self.client.put(url, payload, format='json')
# response = self.client.put(url, payload, format='json')
# self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
# self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
# def test_delete(self):
def
test_delete
(
self
):
# """
"""
# Ensure we can delete an existing annotation.
Ensure we can delete an existing annotation.
# """
"""
# kwargs = dict(text=u"Bar", id='456')
note
=
self
.
_create_annotation
()
# self._create_annotation(**kwargs)
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
note
[
'id'
]})
# url = reverse('api:v1:annotations_detail', kwargs={'annotation_id': 456})
# response = self.client.delete(url, self.headers)
# self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT, "response should be 204 NO CONTENT"
)
response
=
self
.
client
.
delete
(
url
,
self
.
headers
)
# self.assertEqual(self._get_annotation('456'), None, "annotation wasn't deleted in db
")
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_204_NO_CONTENT
,
"response should be 204 NO CONTENT
"
)
# def test_delete_notfound(self):
get_es
()
.
indices
.
refresh
()
# """
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
note
[
'id'
]})
# Case when no annotation is present with specific id when trying to delete.
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
# """
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_404_NOT_FOUND
)
# url = reverse('api:v1:annotations_detail', kwargs={'annotation_id': 123})
# response = self.client.delete(url, self.headers)
def
test_delete_notfound
(
self
):
# self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND, "response should be 404 NOT FOUND")
"""
Case when no annotation is present with specific id when trying to delete.
"""
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
123
})
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
):
def
test_search
(
self
):
"""
"""
...
...
notesapi/v1/views.py
View file @
d3c1929d
...
@@ -84,13 +84,11 @@ class AnnotationDetailView(APIView):
...
@@ -84,13 +84,11 @@ class AnnotationDetailView(APIView):
Get an existing annotation.
Get an existing annotation.
"""
"""
note_id
=
self
.
kwargs
.
get
(
'annotation_id'
)
note_id
=
self
.
kwargs
.
get
(
'annotation_id'
)
if
not
note_searcher
.
filter
(
id
=
note_id
)
.
count
():
return
Response
(
False
,
status
=
status
.
HTTP_404_NOT_FOUND
)
results
=
NoteMappingType
.
process_result
(
results
=
NoteMappingType
.
process_result
(
list
(
note_searcher
.
filter
(
id
=
note_id
)
.
values_dict
(
"_source"
))
list
(
note_searcher
.
filter
(
id
=
note_id
)
.
values_dict
(
"_source"
))
)
)
if
not
results
:
return
Response
(
False
,
status
=
status
.
HTTP_404_NOT_FOUND
)
return
Response
(
results
[
0
])
return
Response
(
results
[
0
])
def
put
(
self
,
*
args
,
**
kwargs
):
# pylint: disable=unused-argument
def
put
(
self
,
*
args
,
**
kwargs
):
# pylint: disable=unused-argument
...
@@ -130,9 +128,6 @@ class AnnotationDetailView(APIView):
...
@@ -130,9 +128,6 @@ class AnnotationDetailView(APIView):
return
Response
(
'Annotation not found! No update performed.'
,
status
=
status
.
HTTP_404_NOT_FOUND
)
return
Response
(
'Annotation not found! No update performed.'
,
status
=
status
.
HTTP_404_NOT_FOUND
)
note
.
delete
()
note
.
delete
()
es_note
.
delete
()
# FIXME
# Annotation deleted successfully.
# Annotation deleted successfully.
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
return
Response
(
status
=
status
.
HTTP_204_NO_CONTENT
)
...
...
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