Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
E
edx-platform
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-platform
Commits
fc042c9b
Commit
fc042c9b
authored
Oct 18, 2016
by
Amir Qayyum Khan
Committed by
GitHub
Oct 18, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into fix/aq/support_django_oauth_toolkit
parents
f09445ed
9fb891fb
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
13 deletions
+49
-13
common/djangoapps/third_party_auth/management/commands/saml.py
+15
-13
common/djangoapps/third_party_auth/management/commands/tests/__init__.py
+3
-0
common/djangoapps/third_party_auth/management/commands/tests/test_saml.py
+31
-0
No files found.
common/djangoapps/third_party_auth/management/commands/saml.py
View file @
fc042c9b
...
@@ -15,17 +15,19 @@ class Command(BaseCommand):
...
@@ -15,17 +15,19 @@ class Command(BaseCommand):
parser
.
add_argument
(
'--pull'
,
action
=
'store_true'
,
help
=
"Pull updated metadata from external IDPs"
)
parser
.
add_argument
(
'--pull'
,
action
=
'store_true'
,
help
=
"Pull updated metadata from external IDPs"
)
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
if
options
[
'pull'
]:
should_pull_saml_metadata
=
options
.
get
(
'pull'
,
False
)
log_handler
=
logging
.
StreamHandler
(
self
.
stdout
)
log_handler
.
setLevel
(
logging
.
DEBUG
)
if
not
should_pull_saml_metadata
:
log
=
logging
.
getLogger
(
'third_party_auth.tasks'
)
raise
CommandError
(
"Command can only be used with '--pull' option."
)
log
.
propagate
=
False
log
.
addHandler
(
log_handler
)
log_handler
=
logging
.
StreamHandler
(
self
.
stdout
)
num_changed
,
num_failed
,
num_total
=
fetch_saml_metadata
()
log_handler
.
setLevel
(
logging
.
DEBUG
)
self
.
stdout
.
write
(
log
=
logging
.
getLogger
(
'third_party_auth.tasks'
)
"
\n
Done. Fetched {num_total} total. {num_changed} were updated and {num_failed} failed.
\n
"
.
format
(
log
.
propagate
=
False
num_changed
=
num_changed
,
num_failed
=
num_failed
,
num_total
=
num_total
log
.
addHandler
(
log_handler
)
)
num_changed
,
num_failed
,
num_total
=
fetch_saml_metadata
()
self
.
stdout
.
write
(
"
\n
Done. Fetched {num_total} total. {num_changed} were updated and {num_failed} failed.
\n
"
.
format
(
num_changed
=
num_changed
,
num_failed
=
num_failed
,
num_total
=
num_total
)
)
else
:
)
raise
CommandError
(
"Unknown argment: {}"
.
format
(
subcommand
))
common/djangoapps/third_party_auth/management/commands/tests/__init__.py
0 → 100644
View file @
fc042c9b
"""
This directory contains tests for third_party_auth app.
"""
common/djangoapps/third_party_auth/management/commands/tests/test_saml.py
0 → 100644
View file @
fc042c9b
"""
Tests for `saml` management command, this command fetches saml metadata from providers and updates
existing data accordingly.
"""
import
unittest
from
django.test
import
TestCase
from
django.core.management
import
call_command
from
django.core.management.base
import
CommandError
from
django.conf
import
settings
@unittest.skipUnless
(
settings
.
ROOT_URLCONF
==
'lms.urls'
,
'Test only valid in lms'
)
class
TestSAMLCommand
(
TestCase
):
"""
Test django management command for fetching saml metadata.
"""
def
test_raises_command_error_for_invalid_arguments
(
self
):
"""
Test that management command raises `CommandError` with a proper message in case of
invalid command arguments.
This test would fail with an error if ValueError is raised.
"""
# Call `saml` command without any argument so that it raises a CommandError
with
self
.
assertRaisesMessage
(
CommandError
,
"Command can only be used with '--pull' option."
):
call_command
(
"saml"
)
# Call `saml` command without any argument so that it raises a CommandError
with
self
.
assertRaisesMessage
(
CommandError
,
"Command can only be used with '--pull' option."
):
call_command
(
"saml"
,
pull
=
False
)
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