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
673a02ba
Commit
673a02ba
authored
Jan 06, 2015
by
Tim Babych
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
split AnnotationView tests into 3 classes
parent
94062a5e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
50 deletions
+60
-50
notesapi/v1/tests/test_views.py
+60
-50
No files found.
notesapi/v1/tests/test_views.py
View file @
673a02ba
...
@@ -87,9 +87,9 @@ class BaseAnnotationViewTests(APITestCase):
...
@@ -87,9 +87,9 @@ class BaseAnnotationViewTests(APITestCase):
return
result
.
data
return
result
.
data
class
AnnotationViewTests
(
BaseAnnotationViewTests
):
class
Annotation
List
ViewTests
(
BaseAnnotationViewTests
):
"""
"""
Test annotation
views, checking permissions
Test annotation
creation and listing by user and course
"""
"""
def
test_create_note
(
self
):
def
test_create_note
(
self
):
...
@@ -156,22 +156,6 @@ class AnnotationViewTests(BaseAnnotationViewTests):
...
@@ -156,22 +156,6 @@ class AnnotationViewTests(BaseAnnotationViewTests):
annotation
=
self
.
_get_annotation
(
note
[
'id'
])
annotation
=
self
.
_get_annotation
(
note
[
'id'
])
self
.
assertEqual
(
annotation
[
'text'
],
'test note text'
)
self
.
assertEqual
(
annotation
[
'text'
],
'test note text'
)
def
test_read
(
self
):
"""
Ensure we can get an existing annotation.
"""
note_id
=
self
.
_create_annotation
(
**
self
.
payload
)[
'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
[
'created'
]
self
.
assertEqual
(
annotation
,
self
.
payload
)
def
test_create_multirange
(
self
):
def
test_create_multirange
(
self
):
"""
"""
Create a note that has several ranges and read it
Create a note that has several ranges and read it
...
@@ -205,6 +189,59 @@ class AnnotationViewTests(BaseAnnotationViewTests):
...
@@ -205,6 +189,59 @@ class AnnotationViewTests(BaseAnnotationViewTests):
del
annotation
[
'created'
]
del
annotation
[
'created'
]
self
.
assertEqual
(
annotation
,
note
)
self
.
assertEqual
(
annotation
,
note
)
def
test_read_all_no_annotations
(
self
):
"""
Tests list all annotations endpoint when no annotations are present in database.
"""
url
=
reverse
(
'api:v1:annotations'
)
self
.
headers
[
"course_id"
]
=
"a/b/c"
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
len
(
response
.
data
),
0
,
"no annotation should be returned in response"
)
def
test_read_all
(
self
):
"""
Tests list all annotations.
"""
for
i
in
xrange
(
5
):
kwargs
=
{
'text'
:
'Foo_{}'
.
format
(
i
)}
self
.
_create_annotation
(
**
kwargs
)
url
=
reverse
(
'api:v1:annotations'
)
self
.
headers
[
"course_id"
]
=
"test-course-id"
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
len
(
response
.
data
),
5
,
"five annotations should be returned in response"
)
def
test_read_all_no_query_param
(
self
):
"""
Tests list all annotations when course_id query param is not present.
"""
url
=
reverse
(
'api:v1:annotations'
)
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
class
AnnotationDetailViewTests
(
BaseAnnotationViewTests
):
"""
Test one annotation updating, reading and deleting
"""
def
test_read
(
self
):
"""
Ensure we can get an existing annotation.
"""
note_id
=
self
.
_create_annotation
(
**
self
.
payload
)[
'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
[
'created'
]
self
.
assertEqual
(
annotation
,
self
.
payload
)
def
test_read_notfound
(
self
):
def
test_read_notfound
(
self
):
"""
"""
Case when no annotation is present with specific id.
Case when no annotation is present with specific id.
...
@@ -310,6 +347,11 @@ class AnnotationViewTests(BaseAnnotationViewTests):
...
@@ -310,6 +347,11 @@ class AnnotationViewTests(BaseAnnotationViewTests):
response
=
self
.
client
.
delete
(
url
,
self
.
headers
)
response
=
self
.
client
.
delete
(
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_404_NOT_FOUND
,
"response should be 404 NOT FOUND"
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_404_NOT_FOUND
,
"response should be 404 NOT FOUND"
)
class
AnnotationSearchlViewTests
(
BaseAnnotationViewTests
):
"""
Test annotation searching by user, course_id, usage_id and text
"""
def
test_search
(
self
):
def
test_search
(
self
):
"""
"""
Tests for search method.
Tests for search method.
...
@@ -408,38 +450,6 @@ class AnnotationViewTests(BaseAnnotationViewTests):
...
@@ -408,38 +450,6 @@ class AnnotationViewTests(BaseAnnotationViewTests):
self
.
assertEqual
(
results
[
'total'
],
1
)
self
.
assertEqual
(
results
[
'total'
],
1
)
self
.
assertEqual
(
results
[
'rows'
][
0
][
'text'
],
u'Third note'
)
self
.
assertEqual
(
results
[
'rows'
][
0
][
'text'
],
u'Third note'
)
def
test_read_all_no_annotations
(
self
):
"""
Tests list all annotations endpoint when no annotations are present in database.
"""
url
=
reverse
(
'api:v1:annotations'
)
self
.
headers
[
"course_id"
]
=
"a/b/c"
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
len
(
response
.
data
),
0
,
"no annotation should be returned in response"
)
def
test_read_all
(
self
):
"""
Tests list all annotations.
"""
for
i
in
xrange
(
5
):
kwargs
=
{
'text'
:
'Foo_{}'
.
format
(
i
)}
self
.
_create_annotation
(
**
kwargs
)
url
=
reverse
(
'api:v1:annotations'
)
self
.
headers
[
"course_id"
]
=
"test-course-id"
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
assertEqual
(
len
(
response
.
data
),
5
,
"five annotations should be returned in response"
)
def
test_read_all_no_query_param
(
self
):
"""
Tests list all annotations when course_id query param is not present.
"""
url
=
reverse
(
'api:v1:annotations'
)
response
=
self
.
client
.
get
(
url
,
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
@patch
(
'django.conf.settings.DISABLE_TOKEN_CHECK'
,
True
)
@patch
(
'django.conf.settings.DISABLE_TOKEN_CHECK'
,
True
)
class
AllowAllAnnotationViewTests
(
BaseAnnotationViewTests
):
class
AllowAllAnnotationViewTests
(
BaseAnnotationViewTests
):
...
...
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