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
3d9affca
Commit
3d9affca
authored
Nov 03, 2016
by
Mushtaq Ali
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
heartbeat end point should send JsonResponse. - TNL-5244
parent
7fcd875e
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
6 deletions
+9
-6
notesserver/test_views.py
+4
-3
notesserver/views.py
+5
-3
No files found.
notesserver/test_views.py
View file @
3d9affca
import
json
import
datetime
from
unittest
import
skipIf
from
mock
import
patch
,
Mock
...
...
@@ -17,7 +18,7 @@ class OperationalEndpointsTest(APITestCase):
"""
response
=
self
.
client
.
get
(
reverse
(
'heartbeat'
))
self
.
assertEquals
(
response
.
status_code
,
200
)
self
.
assertEquals
(
response
.
data
,
{
"OK"
:
True
})
self
.
assertEquals
(
json
.
loads
(
response
.
content
)
,
{
"OK"
:
True
})
@skipIf
(
settings
.
ES_DISABLED
,
"Do not test if Elasticsearch service is disabled."
)
@patch
(
'notesserver.views.get_es'
)
...
...
@@ -28,7 +29,7 @@ class OperationalEndpointsTest(APITestCase):
mocked_get_es
.
return_value
.
ping
.
return_value
=
False
response
=
self
.
client
.
get
(
reverse
(
'heartbeat'
))
self
.
assertEquals
(
response
.
status_code
,
500
)
self
.
assertEquals
(
response
.
data
,
{
"OK"
:
False
,
"check"
:
"es"
})
self
.
assertEquals
(
json
.
loads
(
response
.
content
)
,
{
"OK"
:
False
,
"check"
:
"es"
})
@patch
(
"django.db.backends.utils.CursorWrapper"
)
def
test_heartbeat_failure_db
(
self
,
mocked_cursor_wrapper
):
...
...
@@ -38,7 +39,7 @@ class OperationalEndpointsTest(APITestCase):
mocked_cursor_wrapper
.
side_effect
=
Exception
response
=
self
.
client
.
get
(
reverse
(
'heartbeat'
))
self
.
assertEquals
(
response
.
status_code
,
500
)
self
.
assertEquals
(
response
.
data
,
{
"OK"
:
False
,
"check"
:
"db"
})
self
.
assertEquals
(
json
.
loads
(
response
.
content
)
,
{
"OK"
:
False
,
"check"
:
"db"
})
def
test_root
(
self
):
"""
...
...
notesserver/views.py
View file @
3d9affca
...
...
@@ -3,6 +3,8 @@ import datetime
from
django.db
import
connection
from
django.conf
import
settings
from
django.http
import
JsonResponse
from
rest_framework
import
status
from
rest_framework.permissions
import
AllowAny
from
rest_framework.response
import
Response
...
...
@@ -38,12 +40,12 @@ def heartbeat(request): # pylint: disable=unused-argument
try
:
db_status
()
except
Exception
:
return
Response
({
"OK"
:
False
,
"check"
:
"db"
},
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
return
Json
Response
({
"OK"
:
False
,
"check"
:
"db"
},
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
if
not
settings
.
ES_DISABLED
and
not
get_es
()
.
ping
():
return
Response
({
"OK"
:
False
,
"check"
:
"es"
},
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
return
Json
Response
({
"OK"
:
False
,
"check"
:
"es"
},
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
return
Response
({
"OK"
:
True
}
)
return
JsonResponse
({
"OK"
:
True
},
status
=
status
.
HTTP_200_OK
)
@api_view
([
'GET'
])
...
...
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