Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
course-discovery
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
course-discovery
Commits
2f0bcab9
Commit
2f0bcab9
authored
Feb 11, 2016
by
Bill DeRusha
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add client_credential flow to refresh management cmd
ECOM-3602
parent
330ea8bc
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
53 additions
and
15 deletions
+53
-15
course_discovery/apps/courses/management/commands/refresh_all_courses.py
+14
-4
course_discovery/apps/courses/tests/test_refresh_all_courses.py
+36
-9
docs/getting_started.rst
+1
-1
requirements/base.txt
+1
-1
requirements/test.txt
+1
-0
No files found.
course_discovery/apps/courses/management/commands/refresh_all_courses.py
View file @
2f0bcab9
import
logging
from
django.core.management
import
BaseCommand
,
CommandError
from
django.conf
import
settings
from
django.core.management
import
BaseCommand
from
edx_rest_api_client.client
import
EdxRestApiClient
from
course_discovery.apps.courses.models
import
Course
...
...
@@ -23,8 +25,16 @@ class Command(BaseCommand):
access_token
=
options
.
get
(
'access_token'
)
if
not
access_token
:
msg
=
'Courses cannot be migrated if no access token is supplied.'
logger
.
error
(
msg
)
raise
CommandError
(
msg
)
logger
.
info
(
'No access token provided. Retrieving access token using client_credential flow...'
)
try
:
access_token
,
__
=
EdxRestApiClient
.
get_oauth_access_token
(
'{root}/access_token'
.
format
(
root
=
settings
.
SOCIAL_AUTH_EDX_OIDC_URL_ROOT
),
settings
.
SOCIAL_AUTH_EDX_OIDC_KEY
,
settings
.
SOCIAL_AUTH_EDX_OIDC_SECRET
)
except
Exception
:
logger
.
exception
(
'No access token provided or acquired through client_credential flow.'
)
raise
Course
.
refresh_all
(
access_token
=
access_token
)
course_discovery/apps/courses/tests/test_refresh_all_courses.py
View file @
2f0bcab9
import
mock
from
django.core.management
import
CommandError
,
call_command
""" Tests for Refresh All Courses management command. """
from
django.core.management
import
call_command
from
django.test
import
TestCase
from
django.test.utils
import
override_settings
from
edx_rest_api_client.client
import
EdxRestApiClient
import
httpretty
from
mock
import
patch
from
course_discovery.apps.courses.models
import
Course
@override_settings
(
SOCIAL_AUTH_EDX_OIDC_URL_ROOT
=
"http://auth-url.com/oauth2"
,
SOCIAL_AUTH_EDX_OIDC_KEY
=
"client_id"
,
SOCIAL_AUTH_EDX_OIDC_SECRET
=
"client_secret"
)
class
RefreshAllCoursesCommandTests
(
TestCase
):
""" Tests for refresh_all_courses management command. """
cmd
=
'refresh_all_courses'
def
test_call
(
self
):
""" Verify the management command calls Course.refresh_all(). """
def
test_call
_with_access_token
(
self
):
""" Verify the management command calls Course.refresh_all()
with access token
. """
access_token
=
'secret'
with
mock
.
patch
(
'course_discovery.apps.courses.models.Course.
refresh_all'
)
as
mock_refresh
:
with
patch
.
object
(
Course
,
'
refresh_all'
)
as
mock_refresh
:
call_command
(
self
.
cmd
,
access_token
=
access_token
)
mock_refresh
.
assert_called_once_with
(
access_token
=
access_token
)
def
test_call_without_access_token
(
self
):
""" Verify the command requires an access token. """
with
self
.
assertRaisesRegex
(
CommandError
,
'Courses cannot be migrated if no access token is supplied.'
):
call_command
(
self
.
cmd
)
@httpretty.activate
def
test_call_with_client_credentials
(
self
):
""" Verify the management command calls Course.refresh_all() with client credentials. """
access_token
=
'secret'
with
patch
.
object
(
EdxRestApiClient
,
'get_oauth_access_token'
)
as
mock_access_token
:
mock_access_token
.
return_value
=
(
access_token
,
None
)
with
patch
.
object
(
Course
,
'refresh_all'
)
as
mock_refresh
:
call_command
(
self
.
cmd
)
mock_refresh
.
assert_called_once_with
(
access_token
=
access_token
)
@httpretty.activate
def
test_call_with_client_credentials_error
(
self
):
""" Verify the command requires an access token to complete. """
with
patch
.
object
(
EdxRestApiClient
,
'get_oauth_access_token'
)
as
mock_access_token
:
mock_access_token
.
side_effect
=
Exception
()
with
self
.
assertRaises
(
Exception
):
call_command
(
self
.
cmd
)
docs/getting_started.rst
View file @
2f0bcab9
Getting Started
===============
If you have not already done so, create/activate a `virtualenv`_. Unless otherwise stated, assume all terminal code
If you have not already done so, create/activate a `virtualenv`_
running Python 3
. Unless otherwise stated, assume all terminal code
below is executed within the virtualenv.
.. _virtualenv: https://virtualenvwrapper.readthedocs.org/en/latest/
...
...
requirements/base.txt
View file @
2f0bcab9
...
...
@@ -5,6 +5,6 @@ djangorestframework == 3.3.1
djangorestframework-jwt==1.7.2
django-rest-swagger[reST]==0.3.4
edx-auth-backends == 0.1.3
edx-rest-api-client==1.
2.1
edx-rest-api-client==1.
5.0
elasticsearch>=1.0.0,<2.0.0
pytz == 2015.7
requirements/test.txt
View file @
2f0bcab9
...
...
@@ -7,6 +7,7 @@ django-dynamic-fixture == 1.8.5
django-nose == 1.4.2
edx-lint == 0.4.0
factory-boy==2.6.0
httpretty==0.8.14
mock == 1.3.0
nose-ignore-docstring == 0.2
pep8 == 1.6.2
...
...
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