From 9f4e51a241780b23a7ba9dc5f667ae9162d25b6a Mon Sep 17 00:00:00 2001 From: Thomas Tracy Date: Mon, 29 Mar 2021 10:04:59 -0400 Subject: [PATCH] feat: Add command to generate credentials config (#27088) Adds a command to create an API connection to credentials for testing program certificates on devstack. This command is not meant to be ran manually, and will be included in a provisioning type script that will be added later. --- .../create_credentials_api_configuration.py | 21 +++++++++++++ ...st_create_credentials_api_configuration.py | 30 +++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 openedx/core/djangoapps/credentials/management/commands/create_credentials_api_configuration.py create mode 100644 openedx/core/djangoapps/credentials/management/commands/tests/test_create_credentials_api_configuration.py diff --git a/openedx/core/djangoapps/credentials/management/commands/create_credentials_api_configuration.py b/openedx/core/djangoapps/credentials/management/commands/create_credentials_api_configuration.py new file mode 100644 index 0000000000..c90fa67d54 --- /dev/null +++ b/openedx/core/djangoapps/credentials/management/commands/create_credentials_api_configuration.py @@ -0,0 +1,21 @@ +""" Command to create a credentials api configuration """ +from django.core.management.base import BaseCommand, CommandError +from openedx.core.djangoapps.credentials.models import CredentialsApiConfig + + +class Command(BaseCommand): + """ + Creates a api configuration between LMS <--> Credentials service. + This command is meant to be used in combination with other commands to + create a fully connected path to awarding program certificates in devstack. + """ + + # pylint: disable=unused-argument + def handle(self, *args, **kwargs): + try: + CredentialsApiConfig.objects.create( + enabled=True, + enable_learner_issuance=True, + ) + except Exception as e: + raise CommandError from e diff --git a/openedx/core/djangoapps/credentials/management/commands/tests/test_create_credentials_api_configuration.py b/openedx/core/djangoapps/credentials/management/commands/tests/test_create_credentials_api_configuration.py new file mode 100644 index 0000000000..ff002bdb10 --- /dev/null +++ b/openedx/core/djangoapps/credentials/management/commands/tests/test_create_credentials_api_configuration.py @@ -0,0 +1,30 @@ +""" +Tests for the create_credentials_api_configuration command +""" + +from unittest import TestCase + +import mock +import pytest +from django.core.management import call_command + +from openedx.core.djangoapps.credentials.models import CredentialsApiConfig +from openedx.core.djangolib.testing.utils import skip_unless_lms + +from ..create_credentials_api_configuration import Command + +COMMAND_MODULE = "openedx.core.djangoapps.credentials.management.commands.create_credentials_api_configuration" + + +@skip_unless_lms +@pytest.mark.django_db +class CertAllowlistGenerationTests(TestCase): + """ + Tests for the create_credentials_api_configuration management command + """ + + @mock.patch(COMMAND_MODULE) + # pylint: disable=unused-argument + def test_successful_generation(self, mock_command): + call_command(Command()) + assert len(CredentialsApiConfig.objects.all()) > 0