From e684cf7ee00a537d4cb9728723af7f9a35fac9d2 Mon Sep 17 00:00:00 2001 From: henrrypg Date: Tue, 18 Oct 2022 14:48:47 -0500 Subject: [PATCH 1/3] feat: add cli command to generate report --- openedx/features/survey_report/application.py | 6 ++++++ .../survey_report/management/__init__.py | 0 .../management/commands/__init__.py | 0 .../management/commands/generate_report.py | 21 +++++++++++++++++++ .../management/commands/tests/__init__.py | 0 .../commands/tests/test_generate_report.py | 13 ++++++++++++ 6 files changed, 40 insertions(+) create mode 100644 openedx/features/survey_report/application.py create mode 100644 openedx/features/survey_report/management/__init__.py create mode 100644 openedx/features/survey_report/management/commands/__init__.py create mode 100644 openedx/features/survey_report/management/commands/generate_report.py create mode 100644 openedx/features/survey_report/management/commands/tests/__init__.py create mode 100644 openedx/features/survey_report/management/commands/tests/test_generate_report.py diff --git a/openedx/features/survey_report/application.py b/openedx/features/survey_report/application.py new file mode 100644 index 000000000000..7a564949f42d --- /dev/null +++ b/openedx/features/survey_report/application.py @@ -0,0 +1,6 @@ +""" +Contains the logic for generating a survey report. +""" + +def generate_report() -> None: + """Generate a survey report for all courses in the system.""" diff --git a/openedx/features/survey_report/management/__init__.py b/openedx/features/survey_report/management/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/openedx/features/survey_report/management/commands/__init__.py b/openedx/features/survey_report/management/commands/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/openedx/features/survey_report/management/commands/generate_report.py b/openedx/features/survey_report/management/commands/generate_report.py new file mode 100644 index 000000000000..ebc96356ebc3 --- /dev/null +++ b/openedx/features/survey_report/management/commands/generate_report.py @@ -0,0 +1,21 @@ +""" +CLI command to generate survey report. +""" + +from django.core.management.base import BaseCommand, CommandError +from openedx.features.survey_report.application import generate_report + +class Command(BaseCommand): + """ + Command to generate survey report. + """ + + help = 'This command will generate survey report.' + + def handle(self, *args, **options): + try: + generate_report() + except Exception as error: + raise CommandError('An error has ocurred while report was generating.') from error + + self.stdout.write(self.style.SUCCESS('Survey report has been generated successfully.')) diff --git a/openedx/features/survey_report/management/commands/tests/__init__.py b/openedx/features/survey_report/management/commands/tests/__init__.py new file mode 100644 index 000000000000..e69de29bb2d1 diff --git a/openedx/features/survey_report/management/commands/tests/test_generate_report.py b/openedx/features/survey_report/management/commands/tests/test_generate_report.py new file mode 100644 index 000000000000..ab2982301e59 --- /dev/null +++ b/openedx/features/survey_report/management/commands/tests/test_generate_report.py @@ -0,0 +1,13 @@ +""" +Test for generate_report command. +""" + +from io import StringIO +from django.core.management import call_command +from django.test import TestCase + +class GenerateReportTest(TestCase): + def test_command_output(self): + out = StringIO() + call_command('generate_report', stdout=out) + self.assertIn('Survey report has been generated successfully.', out.getvalue()) From aad277e3ff2074e79d9927abd49e1aff423dc6c6 Mon Sep 17 00:00:00 2001 From: henrrypg Date: Tue, 18 Oct 2022 16:41:56 -0500 Subject: [PATCH 2/3] docs: update docstrings --- openedx/features/survey_report/application.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/openedx/features/survey_report/application.py b/openedx/features/survey_report/application.py index 7a564949f42d..9ebba689351e 100644 --- a/openedx/features/survey_report/application.py +++ b/openedx/features/survey_report/application.py @@ -1,6 +1,6 @@ """ -Contains the logic for generating a survey report. +Contains the logic for manage a survey report. """ def generate_report() -> None: - """Generate a survey report for all courses in the system.""" + """ Generate a report with relevant data.""" From 7dcd3ff7e815fddf8c8de7ba3c443d18d98d4d3c Mon Sep 17 00:00:00 2001 From: Alejandro Cardenas Date: Thu, 20 Oct 2022 07:14:47 -0500 Subject: [PATCH 3/3] chore: update management command docstring --- .../survey_report/management/commands/generate_report.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/openedx/features/survey_report/management/commands/generate_report.py b/openedx/features/survey_report/management/commands/generate_report.py index ebc96356ebc3..29e9bb89bb93 100644 --- a/openedx/features/survey_report/management/commands/generate_report.py +++ b/openedx/features/survey_report/management/commands/generate_report.py @@ -7,10 +7,15 @@ class Command(BaseCommand): """ - Command to generate survey report. + Management command to generate a new survey report with + non-sensitive data. """ - help = 'This command will generate survey report.' + help = """ + This command will create a new survey report using some + models to get the total number oof courses offered, currently active learners, + learners ever registered, and generated certificates. + """ def handle(self, *args, **options): try: