-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #288 from openedx/saleem-latif/ENT-5010
ENT-5010: feat: Created a new management command for adding dummy data for learner progress report v2.
- Loading branch information
Showing
16 changed files
with
207 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
enterprise_data/management/commands/create_enterprise_learner_lpr_v1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
""" | ||
Management command for creating enterprise learner. | ||
""" | ||
|
||
|
||
import sys | ||
|
||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
import enterprise_data.tests.test_utils | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
Management command for creating `EnterpriseLearner` instances for dummy data for learner progress report (LPR) V1. | ||
""" | ||
help = 'Creates an EnterpriseLearner with randomized data.' | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument( | ||
'enterprise_customer_uuid', | ||
type=str, | ||
help='UUID for an enterprise' | ||
) | ||
|
||
def handle(self, *args, **options): | ||
enterprise_customer_uuid = options['enterprise_customer_uuid'] | ||
try: | ||
ent_user = enterprise_data.tests.test_utils.EnterpriseLearnerFactory( | ||
enterprise_customer_uuid=enterprise_customer_uuid | ||
) | ||
except Exception as exc: | ||
info = ( | ||
'Error trying to create EnterpriseLearner with uuid ' | ||
'{}: {}'.format(enterprise_customer_uuid, exc) | ||
) | ||
raise CommandError(info) from exc | ||
|
||
info = '\n\nCreated EnterpriseLearner with id {} for enterprise with uuid {}\n'.format( | ||
ent_user.enterprise_user_id, | ||
ent_user.enterprise_customer_uuid | ||
) | ||
sys.stdout.write(info) | ||
|
||
# TODO: Need to update this to the correct comment for LPR V1 once that is added. | ||
info = ( | ||
'You can create some enrollments for this user by running the following ' | ||
'command:\n\n ./manage.py create_enterprise_enrollment {} {}\n\n'.format( | ||
ent_user.enterprise_customer_uuid, | ||
ent_user.enterprise_user_id, | ||
) | ||
) | ||
sys.stdout.write(info) |
49 changes: 49 additions & 0 deletions
49
enterprise_data/management/commands/tests/test_create_enterprise_learner_lpr_v1.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
Tests for create_enterprise_learner_lpr_v1 management command | ||
""" | ||
from unittest import TestCase, mock | ||
|
||
from pytest import mark | ||
|
||
from django.core.management import call_command | ||
|
||
from enterprise_data.models import EnterpriseLearner | ||
from enterprise_data.tests.test_utils import EnterpriseLearnerFactory | ||
|
||
|
||
@mark.django_db | ||
class TestCreateEnterpriseLearnerCommand(TestCase): | ||
""" | ||
Tests to validate the behavior of `./manage.py create_enterprise_learner_lpr_v1` management command. | ||
""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.uuid = 'a'*32 | ||
|
||
def test_create_enterprise_learner(self): | ||
""" | ||
Management command should successfully be able to create EnterpriseLearner | ||
""" | ||
assert EnterpriseLearner.objects.count() == 0 | ||
|
||
args = [self.uuid] | ||
call_command('create_enterprise_learner_lpr_v1', *args) | ||
|
||
assert EnterpriseLearner.objects.count() == 1 | ||
assert EnterpriseLearner.objects.filter(enterprise_customer_uuid=args[0]).count() == 1 | ||
|
||
def test_create_enterprise_learner_error(self): | ||
""" | ||
Management command should handle exceptions gracefully. | ||
""" | ||
EnterpriseLearnerFactory(enterprise_customer_uuid=self.uuid) | ||
assert EnterpriseLearner.objects.count() == 1 | ||
|
||
args = [self.uuid] | ||
with mock.patch('enterprise_data.tests.test_utils.EnterpriseLearnerFactory') as mock_factory: | ||
mock_factory.side_effect = [Exception] | ||
with self.assertRaises(Exception): | ||
call_command('create_enterprise_learner_lpr_v1', *args) | ||
|
||
assert EnterpriseLearner.objects.count() == 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ django-fernet-fields | |
django-model-utils | ||
edx-rbac | ||
rules | ||
factory_boy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
# | ||
# make upgrade | ||
# | ||
click==8.0.3 | ||
click==8.0.4 | ||
# via pip-tools | ||
pep517==0.12.0 | ||
# via pip-tools | ||
|
Oops, something went wrong.