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
60c7bdc9
Unverified
Commit
60c7bdc9
authored
Nov 02, 2017
by
M. Rehan
Committed by
GitHub
Nov 02, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #58 from edx/mrehan/error-types
Introduce error types in credentials api
parents
7d9cf989
498a73ef
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
17 deletions
+44
-17
Makefile
+1
-1
VEDA_OS01/enums.py
+12
-0
VEDA_OS01/tests/test_transcripts.py
+1
-2
VEDA_OS01/tests/test_views.py
+14
-5
VEDA_OS01/views.py
+16
-9
No files found.
Makefile
View file @
60c7bdc9
PEP8_THRESHOLD
=
4
9
PEP8_THRESHOLD
=
4
6
PYLINT_THRESHOLD
=
761
production-requirements
:
...
...
VEDA_OS01/enums.py
0 → 100644
View file @
60c7bdc9
"""
Module containing all the Enumerations used in the API.
"""
class
TranscriptionProviderErrorType
:
"""
Transcription provider's errors enumeration.
"""
INVALID_CREDENTIALS
=
1
INVALID_PROVIDER
=
2
MISSING_REQUIRED_ATTRIBUTES
=
3
VEDA_OS01/tests/test_transcripts.py
View file @
60c7bdc9
...
...
@@ -239,8 +239,7 @@ class Cielo24TranscriptTests(APITestCase):
self
.
assertTrue
(
responses
.
calls
[
0
]
.
request
.
url
,
(
'http://api.cielo24.com/job/get_caption'
'?api_token=i_am_key&job_id=
%28100%2
C
%29
&caption_format=SRT&v={cielo_api_version}'
)
.
format
(
'?api_token=i_am_key&job_id=
%28100%2
C
%29
&caption_format=SRT&v={cielo_api_version}'
)
.
format
(
cielo_api_version
=
transcripts
.
CIELO24_API_VERSION
)
)
...
...
VEDA_OS01/tests/test_views.py
View file @
60c7bdc9
...
...
@@ -9,9 +9,11 @@ from mock import patch
from
rest_framework
import
status
from
rest_framework.test
import
APITestCase
from
VEDA_OS01.enums
import
TranscriptionProviderErrorType
from
VEDA_OS01.models
import
TranscriptCredentials
,
TranscriptProvider
from
VEDA_OS01.views
import
CIELO24_LOGIN_URL
@ddt
class
TranscriptCredentialsTest
(
APITestCase
):
"""
...
...
@@ -48,8 +50,6 @@ class TranscriptCredentialsTest(APITestCase):
)
response_status_code
=
response
.
status_code
response
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response_status_code
,
status
.
HTTP_401_UNAUTHORIZED
)
@data
(
...
...
@@ -76,7 +76,10 @@ class TranscriptCredentialsTest(APITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
response
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
[
'message'
],
'Invalid provider {provider}.'
.
format
(
provider
=
provider
))
self
.
assertDictEqual
(
response
,
{
'message'
:
'Invalid provider {provider}.'
.
format
(
provider
=
provider
),
'error_type'
:
TranscriptionProviderErrorType
.
INVALID_PROVIDER
})
@data
(
(
...
...
@@ -133,7 +136,10 @@ class TranscriptCredentialsTest(APITestCase):
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
response
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
[
'message'
],
error_message
)
self
.
assertDictEqual
(
response
,
{
'message'
:
error_message
,
'error_type'
:
TranscriptionProviderErrorType
.
MISSING_REQUIRED_ATTRIBUTES
})
@data
(
{
...
...
@@ -206,7 +212,10 @@ class TranscriptCredentialsTest(APITestCase):
)
self
.
assertEqual
(
response
.
status_code
,
status
.
HTTP_400_BAD_REQUEST
)
response
=
json
.
loads
(
response
.
content
)
self
.
assertEqual
(
response
[
'message'
],
error_message
)
self
.
assertDictEqual
(
response
,
{
'message'
:
error_message
,
'error_type'
:
TranscriptionProviderErrorType
.
INVALID_CREDENTIALS
})
mock_logger
.
warning
.
assert_called_with
(
'[Transcript Credentials] Unable to get api token -- response
%
s -- status
%
s.'
,
json
.
dumps
({
'error'
:
error_message
}),
...
...
VEDA_OS01/views.py
View file @
60c7bdc9
...
...
@@ -16,6 +16,7 @@ from rest_framework.views import APIView
from
api
import
token_finisher
from
VEDA
import
utils
from
VEDA_OS01.enums
import
TranscriptionProviderErrorType
from
VEDA_OS01.models
import
Course
,
Video
,
URL
,
Encode
,
TranscriptCredentials
,
TranscriptProvider
from
VEDA_OS01.serializers
import
CourseSerializer
,
EncodeSerializer
,
VideoSerializer
,
URLSerializer
from
VEDA_OS01.transcripts
import
CIELO24_API_VERSION
...
...
@@ -30,6 +31,7 @@ CIELO24_LOGIN_URL = utils.build_url(
'/account/login'
)
class
CourseViewSet
(
viewsets
.
ModelViewSet
):
queryset
=
Course
.
objects
.
all
()
...
...
@@ -144,7 +146,7 @@ class TranscriptCredentialsView(APIView):
)
else
:
api_token
=
json
.
loads
(
response
.
content
)[
'ApiToken'
]
return
api_token
def
validate_missing_attributes
(
self
,
provider
,
attributes
,
credentials
):
...
...
@@ -159,7 +161,7 @@ class TranscriptCredentialsView(APIView):
missing
=
' and '
.
join
(
missing
)
)
return
error_message
return
TranscriptionProviderErrorType
.
MISSING_REQUIRED_ATTRIBUTES
,
error_message
def
validate_transcript_credentials
(
self
,
provider
,
**
credentials
):
"""
...
...
@@ -171,11 +173,11 @@ class TranscriptCredentialsView(APIView):
3PlayMedia - 'api_key' and 'api_secret_key' are required.
Cielo24 - Valid 'api_key' and 'username' are required.
"""
error_
message
,
validated_credentials
=
''
,
{}
error_
type
,
error_message
,
validated_credentials
=
None
,
''
,
{}
if
provider
in
[
TranscriptProvider
.
CIELO24
,
TranscriptProvider
.
THREE_PLAY
]:
if
provider
==
TranscriptProvider
.
CIELO24
:
must_have_props
=
(
'org'
,
'api_key'
,
'username'
)
error_message
=
self
.
validate_missing_attributes
(
provider
,
must_have_props
,
credentials
)
error_
type
,
error_
message
=
self
.
validate_missing_attributes
(
provider
,
must_have_props
,
credentials
)
if
not
error_message
:
# Get cielo api token and store it in api_key.
...
...
@@ -187,9 +189,10 @@ class TranscriptCredentialsView(APIView):
})
else
:
error_message
=
u'Invalid credentials supplied.'
error_type
=
TranscriptionProviderErrorType
.
INVALID_CREDENTIALS
else
:
must_have_props
=
(
'org'
,
'api_key'
,
'api_secret_key'
)
error_message
=
self
.
validate_missing_attributes
(
provider
,
must_have_props
,
credentials
)
error_
type
,
error_
message
=
self
.
validate_missing_attributes
(
provider
,
must_have_props
,
credentials
)
if
not
error_message
:
validated_credentials
.
update
({
'org'
:
credentials
[
'org'
],
...
...
@@ -198,8 +201,9 @@ class TranscriptCredentialsView(APIView):
})
else
:
error_message
=
u'Invalid provider {provider}.'
.
format
(
provider
=
provider
)
error_type
=
TranscriptionProviderErrorType
.
INVALID_PROVIDER
return
error_message
,
validated_credentials
return
error_
type
,
error_
message
,
validated_credentials
def
post
(
self
,
request
):
"""
...
...
@@ -224,7 +228,7 @@ class TranscriptCredentialsView(APIView):
* provider: A string representation of provider.
* org: A string representing the organizaton code.
* api_key: A string representing the provider api key.
* api_secret_key: (Required for 3Play only). A string representing the api secret key.
...
...
@@ -239,16 +243,19 @@ class TranscriptCredentialsView(APIView):
In case of error:
Return response with error message and 400 status code (HTTP 400 Bad Request).
{
"error_type": INVALID_CREDENTIALS
"message": "Error message."
}
"""
# Validate credentials
provider
=
request
.
data
.
pop
(
'provider'
,
None
)
error_message
,
validated_credentials
=
self
.
validate_transcript_credentials
(
provider
=
provider
,
**
request
.
data
)
error_type
,
error_message
,
validated_credentials
=
self
.
validate_transcript_credentials
(
provider
=
provider
,
**
request
.
data
)
if
error_message
:
return
Response
(
status
=
status
.
HTTP_400_BAD_REQUEST
,
data
=
dict
(
message
=
error_message
)
data
=
dict
(
error_type
=
error_type
,
message
=
error_message
)
)
TranscriptCredentials
.
objects
.
update_or_create
(
...
...
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