Merge branch 'master' into fix/aq/support_django_oauth_toolkit
This commit is contained in:
@@ -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(
|
||||
"\nDone. 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(
|
||||
"\nDone. 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))
|
||||
)
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
"""
|
||||
This directory contains tests for third_party_auth app.
|
||||
"""
|
||||
@@ -0,0 +1,31 @@
|
||||
"""
|
||||
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)
|
||||
Reference in New Issue
Block a user