Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-video-pipeline
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-video-pipeline
Commits
fbac44ce
Commit
fbac44ce
authored
Nov 06, 2017
by
muhammad-ammar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
heartbeat endpoint
EDUCATOR-1632
parent
60c7bdc9
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
71 additions
and
11 deletions
+71
-11
VEDA/urls.py
+6
-1
VEDA_OS01/tests/test_views.py
+25
-1
VEDA_OS01/views.py
+40
-9
No files found.
VEDA/urls.py
View file @
fbac44ce
...
@@ -50,5 +50,10 @@ urlpatterns = [
...
@@ -50,5 +50,10 @@ urlpatterns = [
regex
=
r'^3playmedia/transcripts/handle/(?P<token>[\w]+)$'
,
regex
=
r'^3playmedia/transcripts/handle/(?P<token>[\w]+)$'
,
view
=
transcripts
.
ThreePlayMediaCallbackHandlerView
.
as_view
(),
view
=
transcripts
.
ThreePlayMediaCallbackHandlerView
.
as_view
(),
name
=
'3play_media_callback'
name
=
'3play_media_callback'
)
),
url
(
r'^heartbeat/$'
,
view
=
views
.
heartbeat
,
name
=
'heartbeat'
),
]
]
VEDA_OS01/tests/test_views.py
View file @
fbac44ce
""" Views tests """
""" Views tests """
import
json
import
json
import
responses
import
responses
from
ddt
import
data
,
ddt
,
unpack
from
ddt
import
data
,
ddt
,
unpack
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.urlresolvers
import
reverse
from
django.core.urlresolvers
import
reverse
from
django.db.utils
import
DatabaseError
from
mock
import
patch
from
mock
import
patch
from
rest_framework
import
status
from
rest_framework
import
status
from
rest_framework.test
import
APITestCase
from
rest_framework.test
import
APITestCase
...
@@ -221,3 +222,26 @@ class TranscriptCredentialsTest(APITestCase):
...
@@ -221,3 +222,26 @@ class TranscriptCredentialsTest(APITestCase):
json
.
dumps
({
'error'
:
error_message
}),
json
.
dumps
({
'error'
:
error_message
}),
status
.
HTTP_400_BAD_REQUEST
status
.
HTTP_400_BAD_REQUEST
)
)
class
HeartbeatTests
(
APITestCase
):
"""
Tests for hearbeat endpoint.
"""
def
test_heartbeat
(
self
):
"""
Test that heartbeat endpoint gives expected response upon success.
"""
response
=
self
.
client
.
get
(
reverse
(
'heartbeat'
))
assert
response
.
status_code
==
200
assert
json
.
loads
(
response
.
content
)
==
{
'OK'
:
True
}
@patch
(
'django.db.backends.utils.CursorWrapper'
)
def
test_heartbeat_failure_db
(
self
,
mocked_cursor_wrapper
):
"""
Test that heartbeat endpoint gives expected response when there is an error.
"""
mocked_cursor_wrapper
.
side_effect
=
DatabaseError
response
=
self
.
client
.
get
(
reverse
(
'heartbeat'
))
assert
response
.
status_code
==
500
assert
json
.
loads
(
response
.
content
)
==
{
'OK'
:
False
}
VEDA_OS01/views.py
View file @
fbac44ce
...
@@ -2,26 +2,28 @@
...
@@ -2,26 +2,28 @@
import
json
import
json
import
logging
import
logging
import
requests
from
django.http
import
HttpResponse
import
requests
from
django.http
import
HttpResponseRedirect
from
django.db
import
connection
from
django.db.utils
import
DatabaseError
from
django.http
import
HttpResponse
,
HttpResponseRedirect
,
JsonResponse
from
django.views.decorators.csrf
import
csrf_exempt
from
django.views.decorators.csrf
import
csrf_exempt
from
rest_framework
import
filters
,
renderers
,
status
,
viewsets
from
rest_framework
import
filters
,
renderers
,
status
,
viewsets
from
rest_framework.decorators
import
detail_route
from
rest_framework.decorators
import
(
api_view
,
detail_route
,
permission_classes
)
from
rest_framework.permissions
import
AllowAny
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
api
import
token_finisher
from
api
import
token_finisher
from
VEDA
import
utils
from
VEDA
import
utils
from
VEDA_OS01.enums
import
TranscriptionProviderErrorType
from
VEDA_OS01.enums
import
TranscriptionProviderErrorType
from
VEDA_OS01.models
import
Course
,
Video
,
URL
,
Encode
,
TranscriptCredentials
,
TranscriptProvider
from
VEDA_OS01.models
import
(
URL
,
Course
,
Encode
,
TranscriptCredentials
,
from
VEDA_OS01.serializers
import
CourseSerializer
,
EncodeSerializer
,
VideoSerializer
,
URLSerializer
TranscriptProvider
,
Video
)
from
VEDA_OS01.serializers
import
(
CourseSerializer
,
EncodeSerializer
,
URLSerializer
,
VideoSerializer
)
from
VEDA_OS01.transcripts
import
CIELO24_API_VERSION
from
VEDA_OS01.transcripts
import
CIELO24_API_VERSION
LOGGER
=
logging
.
getLogger
(
__name__
)
LOGGER
=
logging
.
getLogger
(
__name__
)
...
@@ -284,3 +286,32 @@ def user_login(request):
...
@@ -284,3 +286,32 @@ def user_login(request):
return
HttpResponseRedirect
(
request
.
path
)
return
HttpResponseRedirect
(
request
.
path
)
else
:
else
:
return
HttpResponseRedirect
(
'../admin'
)
# settings.LOGIN_REDIRECT_URL)
return
HttpResponseRedirect
(
'../admin'
)
# settings.LOGIN_REDIRECT_URL)
@api_view
([
'GET'
])
@permission_classes
([
AllowAny
])
def
heartbeat
(
request
):
# pylint: disable=unused-argument
"""
View to check if database is reachable and ready to handle requests.
"""
try
:
db_status
()
except
DatabaseError
:
return
JsonResponse
(
{
'OK'
:
False
},
status
=
status
.
HTTP_500_INTERNAL_SERVER_ERROR
)
return
JsonResponse
(
{
'OK'
:
True
},
status
=
status
.
HTTP_200_OK
)
def
db_status
():
"""
Return database status.
"""
with
connection
.
cursor
()
as
cursor
:
cursor
.
execute
(
'SELECT 1'
)
cursor
.
fetchone
()
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