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
cb527f1e
Commit
cb527f1e
authored
Oct 17, 2016
by
Saleem Latif
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix NameError issue for saml mangemement command
parent
046ee7bd
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 @
cb527f1e
...
...
@@ -15,17 +15,19 @@ class Command(BaseCommand):
parser
.
add_argument
(
'--pull'
,
action
=
'store_true'
,
help
=
"Pull updated metadata from external IDPs"
)
def
handle
(
self
,
*
args
,
**
options
):
if
options
[
'pull'
]:
log_handler
=
logging
.
StreamHandler
(
self
.
stdout
)
log_handler
.
setLevel
(
logging
.
DEBUG
)
log
=
logging
.
getLogger
(
'third_party_auth.tasks'
)
log
.
propagate
=
False
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
)
should_pull_saml_metadata
=
options
.
get
(
'pull'
,
False
)
if
not
should_pull_saml_metadata
:
raise
CommandError
(
"Command can only be used with '--pull' option."
)
log_handler
=
logging
.
StreamHandler
(
self
.
stdout
)
log_handler
.
setLevel
(
logging
.
DEBUG
)
log
=
logging
.
getLogger
(
'third_party_auth.tasks'
)
log
.
propagate
=
False
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 @
cb527f1e
"""
This directory contains tests for third_party_auth app.
"""
common/djangoapps/third_party_auth/management/commands/tests/test_saml.py
0 → 100644
View file @
cb527f1e
"""
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