Commit fc042c9b by Amir Qayyum Khan Committed by GitHub

Merge branch 'master' into fix/aq/support_django_oauth_toolkit

parents f09445ed 9fb891fb
......@@ -15,7 +15,11 @@ 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']:
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')
......@@ -27,5 +31,3 @@ class Command(BaseCommand):
num_changed=num_changed, num_failed=num_failed, num_total=num_total
)
)
else:
raise CommandError("Unknown argment: {}".format(subcommand))
"""
This directory contains tests for third_party_auth app.
"""
"""
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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment