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
d9f39f83
Commit
d9f39f83
authored
Nov 27, 2014
by
Oleg Marshev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add more checking response statuses.
parent
ccf6a6c6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
8 deletions
+20
-8
notesapi/v1/tests/test_views.py
+20
-8
No files found.
notesapi/v1/tests/test_views.py
View file @
d9f39f83
...
@@ -133,9 +133,9 @@ class AnnotationViewTests(APITestCase):
...
@@ -133,9 +133,9 @@ class AnnotationViewTests(APITestCase):
"""
"""
self
.
payload
[
'created'
]
=
'abc'
self
.
payload
[
'created'
]
=
'abc'
response
=
self
.
client
.
post
(
reverse
(
'api:v1:annotations'
),
self
.
payload
,
format
=
'json'
,
**
self
.
headers
)
response
=
self
.
client
.
post
(
reverse
(
'api:v1:annotations'
),
self
.
payload
,
format
=
'json'
,
**
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
annotation
=
self
.
_get_annotation
(
response
.
data
[
'id'
])
annotation
=
self
.
_get_annotation
(
response
.
data
[
'id'
])
self
.
assertNotEqual
(
annotation
[
'created'
],
'abc'
,
"annotation 'created' field should not be used by API"
)
self
.
assertNotEqual
(
annotation
[
'created'
],
'abc'
,
"annotation 'created' field should not be used by API"
)
def
test_create_ignore_updated
(
self
):
def
test_create_ignore_updated
(
self
):
...
@@ -144,9 +144,9 @@ class AnnotationViewTests(APITestCase):
...
@@ -144,9 +144,9 @@ class AnnotationViewTests(APITestCase):
"""
"""
self
.
payload
[
'updated'
]
=
'abc'
self
.
payload
[
'updated'
]
=
'abc'
response
=
self
.
client
.
post
(
reverse
(
'api:v1:annotations'
),
self
.
payload
,
format
=
'json'
,
**
self
.
headers
)
response
=
self
.
client
.
post
(
reverse
(
'api:v1:annotations'
),
self
.
payload
,
format
=
'json'
,
**
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_201_CREATED
)
annotation
=
self
.
_get_annotation
(
response
.
data
[
'id'
])
annotation
=
self
.
_get_annotation
(
response
.
data
[
'id'
])
self
.
assertNotEqual
(
annotation
[
'updated'
],
'abc'
,
"annotation 'updated' field should not be used by API"
)
self
.
assertNotEqual
(
annotation
[
'updated'
],
'abc'
,
"annotation 'updated' field should not be used by API"
)
@unittest.skip
(
"Unskip when auth will be done."
)
@unittest.skip
(
"Unskip when auth will be done."
)
...
@@ -192,6 +192,8 @@ class AnnotationViewTests(APITestCase):
...
@@ -192,6 +192,8 @@ class AnnotationViewTests(APITestCase):
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
"test_id"
})
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
"test_id"
})
response
=
self
.
client
.
get
(
url
,
**
self
.
headers
)
response
=
self
.
client
.
get
(
url
,
**
self
.
headers
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
self
.
expected_note
[
'id'
]
=
'test_id'
self
.
expected_note
[
'id'
]
=
'test_id'
self
.
expected_note
[
'consumer'
]
=
'mockconsumer'
self
.
expected_note
[
'consumer'
]
=
'mockconsumer'
self
.
assertEqual
(
response
.
data
,
self
.
expected_note
)
self
.
assertEqual
(
response
.
data
,
self
.
expected_note
)
...
@@ -212,8 +214,9 @@ class AnnotationViewTests(APITestCase):
...
@@ -212,8 +214,9 @@ class AnnotationViewTests(APITestCase):
payload
=
{
'id'
:
'123'
,
'text'
:
'Bar'
}
payload
=
{
'id'
:
'123'
,
'text'
:
'Bar'
}
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
123
})
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
123
})
response
=
self
.
client
.
put
(
url
,
payload
,
format
=
'json'
)
response
=
self
.
client
.
put
(
url
,
payload
,
format
=
'json'
)
annotation
=
self
.
_get_annotation
(
'123'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
annotation
=
self
.
_get_annotation
(
'123'
)
self
.
assertEqual
(
annotation
[
'text'
],
"Bar"
,
"annotation wasn't updated in db"
)
self
.
assertEqual
(
annotation
[
'text'
],
"Bar"
,
"annotation wasn't updated in db"
)
self
.
assertEqual
(
response
.
data
[
'text'
],
"Bar"
,
"update annotation should be returned in response"
)
self
.
assertEqual
(
response
.
data
[
'text'
],
"Bar"
,
"update annotation should be returned in response"
)
...
@@ -221,13 +224,14 @@ class AnnotationViewTests(APITestCase):
...
@@ -221,13 +224,14 @@ class AnnotationViewTests(APITestCase):
"""
"""
Test if update will be performed when there is no id in payload.
Test if update will be performed when there is no id in payload.
Use i
d from URL, regardless of what arrives in JSON payload.
Tests if id is use
d from URL, regardless of what arrives in JSON payload.
"""
"""
self
.
_create_annotation
(
text
=
u"Foo"
,
id
=
'123'
)
self
.
_create_annotation
(
text
=
u"Foo"
,
id
=
'123'
)
payload
=
{
'text'
:
'Bar'
}
payload
=
{
'text'
:
'Bar'
}
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
123
})
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
123
})
response
=
self
.
client
.
put
(
url
,
payload
,
format
=
'json'
)
response
=
self
.
client
.
put
(
url
,
payload
,
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
annotation
=
self
.
_get_annotation
(
'123'
)
annotation
=
self
.
_get_annotation
(
'123'
)
self
.
assertEqual
(
annotation
[
'text'
],
"Bar"
,
"annotation wasn't updated in db"
)
self
.
assertEqual
(
annotation
[
'text'
],
"Bar"
,
"annotation wasn't updated in db"
)
...
@@ -236,13 +240,14 @@ class AnnotationViewTests(APITestCase):
...
@@ -236,13 +240,14 @@ class AnnotationViewTests(APITestCase):
"""
"""
Test if update will be performed when there is wrong id in payload.
Test if update will be performed when there is wrong id in payload.
Use i
d from URL, regardless of what arrives in JSON payload.
Tests if id is use
d from URL, regardless of what arrives in JSON payload.
"""
"""
self
.
_create_annotation
(
text
=
u"Foo"
,
id
=
'123'
)
self
.
_create_annotation
(
text
=
u"Foo"
,
id
=
'123'
)
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
123
})
url
=
reverse
(
'api:v1:annotations_detail'
,
kwargs
=
{
'annotation_id'
:
123
})
payload
=
{
'text'
:
'Bar'
,
'id'
:
'abc'
}
payload
=
{
'text'
:
'Bar'
,
'id'
:
'abc'
}
response
=
self
.
client
.
put
(
url
,
payload
,
format
=
'json'
)
response
=
self
.
client
.
put
(
url
,
payload
,
format
=
'json'
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_200_OK
)
annotation
=
self
.
_get_annotation
(
'123'
)
annotation
=
self
.
_get_annotation
(
'123'
)
self
.
assertEqual
(
annotation
[
'text'
],
"Bar"
,
"annotation wasn't updated in db"
)
self
.
assertEqual
(
annotation
[
'text'
],
"Bar"
,
"annotation wasn't updated in db"
)
...
@@ -280,13 +285,18 @@ class AnnotationViewTests(APITestCase):
...
@@ -280,13 +285,18 @@ class AnnotationViewTests(APITestCase):
"""
"""
Tests for search method.
Tests for search method.
"""
"""
note_1
=
self
.
_create_annotation
(
text
=
u'
Note 1
'
,
user
=
u'user_3'
)
note_1
=
self
.
_create_annotation
(
text
=
u'
First one
'
,
user
=
u'user_3'
)
note_2
=
self
.
_create_annotation
(
text
=
u'
Note 2
'
,
user
=
u'user_2'
)
note_2
=
self
.
_create_annotation
(
text
=
u'
Second note
'
,
user
=
u'user_2'
)
note_3
=
self
.
_create_annotation
(
text
=
u'
Note 3
'
,
user
=
u'user_3'
)
note_3
=
self
.
_create_annotation
(
text
=
u'
Third note
'
,
user
=
u'user_3'
)
results
=
self
.
_get_search_results
()
results
=
self
.
_get_search_results
()
self
.
assertEqual
(
results
[
'total'
],
3
)
self
.
assertEqual
(
results
[
'total'
],
3
)
results
=
self
.
_get_search_results
(
"text=Second"
)
self
.
assertEqual
(
results
[
'total'
],
1
)
self
.
assertEqual
(
len
(
results
[
'rows'
]),
1
)
self
.
assertEqual
(
results
[
'rows'
][
0
][
'text'
],
'Second note'
)
results
=
self
.
_get_search_results
(
'limit=1'
)
results
=
self
.
_get_search_results
(
'limit=1'
)
self
.
assertEqual
(
results
[
'total'
],
3
)
self
.
assertEqual
(
results
[
'total'
],
3
)
self
.
assertEqual
(
len
(
results
[
'rows'
]),
1
)
self
.
assertEqual
(
len
(
results
[
'rows'
]),
1
)
...
@@ -348,6 +358,7 @@ class AnnotationViewTests(APITestCase):
...
@@ -348,6 +358,7 @@ class AnnotationViewTests(APITestCase):
"""
"""
url
=
reverse
(
'api:v1:annotations'
)
url
=
reverse
(
'api:v1:annotations'
)
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
(
len
(
response
.
data
),
0
,
"no annotation should be returned in response"
)
self
.
assertEqual
(
len
(
response
.
data
),
0
,
"no annotation should be returned in response"
)
def
test_read_all
(
self
):
def
test_read_all
(
self
):
...
@@ -362,4 +373,5 @@ class AnnotationViewTests(APITestCase):
...
@@ -362,4 +373,5 @@ class AnnotationViewTests(APITestCase):
url
=
reverse
(
'api:v1:annotations'
)
url
=
reverse
(
'api:v1:annotations'
)
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
(
len
(
response
.
data
),
5
,
"five annotations should be returned in response"
)
self
.
assertEqual
(
len
(
response
.
data
),
5
,
"five annotations should be returned in response"
)
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