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
5d4a23ac
Commit
5d4a23ac
authored
Dec 30, 2014
by
Oleg Marshev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve coverage.
parent
5ee1a3a8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
1 deletions
+37
-1
notesapi/v1/tests/test_views.py
+37
-1
No files found.
notesapi/v1/tests/test_views.py
View file @
5d4a23ac
...
...
@@ -13,7 +13,7 @@ from rest_framework.test import APITestCase
from
elasticutils.contrib.django
import
get_es
from
.helpers
import
get_id_token
from
notesapi.v1.models
import
NoteMappingType
,
note_searcher
from
notesapi.v1.models
import
NoteMappingType
,
note_searcher
,
Note
from
notesapi.management.commands.create_index
import
Command
as
CreateIndexCommand
TEST_USER
=
"test_user_id"
...
...
@@ -131,6 +131,29 @@ class AnnotationViewTests(BaseAnnotationViewTests):
self
.
assertEqual
(
response
.
data
[
'user'
],
TEST_USER
)
@patch
(
'django.conf.settings.ES_DISABLED'
,
True
)
def
test_create_es_disabled
(
self
):
"""
Ensure we can create note in database when elasticsearch is disabled.
"""
url
=
reverse
(
'api:v1:annotations'
)
response
=
self
.
client
.
post
(
url
,
self
.
payload
,
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
Note
.
objects
.
get
(
id
=
response
.
data
[
'id'
])
self
.
assertEqual
(
note_searcher
.
filter
(
id
=
response
.
data
[
'id'
])
.
count
(),
0
)
def
test_delete_es_disabled
(
self
):
"""
Ensure we can create note in database when elasticsearch is disabled.
"""
url
=
reverse
(
'api:v1:annotations'
)
response
=
self
.
client
.
post
(
url
,
self
.
payload
,
format
=
'json'
)
get_es
()
.
indices
.
refresh
()
self
.
assertEqual
(
note_searcher
.
filter
(
id
=
response
.
data
[
'id'
])
.
count
(),
1
)
with
patch
(
'django.conf.settings.ES_DISABLED'
,
True
):
Note
.
objects
.
get
(
id
=
response
.
data
[
'id'
])
.
delete
()
self
.
assertEqual
(
note_searcher
.
filter
(
id
=
response
.
data
[
'id'
])
.
count
(),
1
)
def
test_create_ignore_created
(
self
):
"""
Test if annotation 'created' field is not used by API.
...
...
@@ -244,6 +267,19 @@ class AnnotationViewTests(BaseAnnotationViewTests):
self
.
assertEqual
(
annotation
[
'text'
],
"Bar"
,
"annotation wasn't updated in db"
)
self
.
assertEqual
(
response
.
data
[
'text'
],
"Bar"
,
"update annotation should be returned in response"
)
def
test_update_fail
(
self
):
"""
Ensure can not update an existing annotation with bad note.
"""
data
=
self
.
_create_annotation
(
text
=
u"Foo"
)
# Bad note. Only id and user is present.
payload
=
{
'id'
:
data
[
'id'
],
'user'
:
TEST_USER
}
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
data
[
'id'
]})
response
=
self
.
client
.
put
(
url
,
payload
,
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
def
test_update_without_payload_id
(
self
):
"""
Test if update will be performed when there is no id in payload.
...
...
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