-
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 #290 from openedx/Muneeb/ENT-5008
feat: add create_dummy_data command for LPR v1 and add tests
- Loading branch information
Showing
5 changed files
with
85 additions
and
3 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
43 changes: 43 additions & 0 deletions
43
enterprise_data/management/commands/create_dummy_data_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,43 @@ | ||
""" | ||
management command for creating enterprise enrollments in bulk | ||
""" | ||
|
||
from random import choice | ||
|
||
from django.core.management.base import BaseCommand, CommandError | ||
|
||
from enterprise_data.tests.test_utils import EnterpriseLearnerEnrollmentFactory, EnterpriseLearnerFactory | ||
|
||
|
||
class Command(BaseCommand): | ||
""" | ||
management command class for creating enterprise enrollments in bulk for learner progress report (LPR) v1 | ||
""" | ||
help = 'Creates 10 enterprise learners with 5 random enterprise learner enrollments each with random consent grants' | ||
|
||
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: | ||
for _ in range(10): | ||
ent_user = EnterpriseLearnerFactory( | ||
enterprise_customer_uuid=enterprise_customer_uuid | ||
) | ||
for _ in range(5): | ||
EnterpriseLearnerEnrollmentFactory( | ||
enterprise_customer_uuid=enterprise_customer_uuid, | ||
enterprise_user_id=ent_user.enterprise_user_id, | ||
is_consent_granted=choice([True, False]), | ||
) | ||
except Exception as exc: | ||
info = ( | ||
'Error trying to create Enrollments for enterprise ' | ||
'{}: {}'.format(enterprise_customer_uuid, exc) | ||
) | ||
raise CommandError(info) from exc |
35 changes: 35 additions & 0 deletions
35
enterprise_data/management/commands/tests/test_create_dummy_data_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,35 @@ | ||
""" | ||
Tests for create_dummy_data_lpr_v1 management command | ||
""" | ||
import uuid | ||
from unittest import TestCase | ||
|
||
from pytest import mark | ||
|
||
from django.core.management import call_command | ||
|
||
from enterprise_data.models import EnterpriseLearner, EnterpriseLearnerEnrollment | ||
|
||
|
||
@mark.django_db | ||
class TestCreateEnterpriseLearnerCommand(TestCase): | ||
""" | ||
Tests to validate the behavior of `./manage.py create_dummy_data_lpr_v1` management command. | ||
""" | ||
|
||
def setUp(self): | ||
super().setUp() | ||
self.enterprise_customer_uuid = uuid.uuid4() | ||
|
||
def test_create_enterprise_learners_with_enrollments(self): | ||
""" | ||
Management command should successfully be able to create 10 EnterpriseLearners with 5 enrollments each | ||
""" | ||
assert EnterpriseLearner.objects.count() == 0 | ||
assert EnterpriseLearnerEnrollment.objects.count() == 0 | ||
|
||
args = [self.enterprise_customer_uuid] | ||
call_command('create_dummy_data_lpr_v1', *args) | ||
|
||
assert EnterpriseLearner.objects.count() == 10 | ||
assert EnterpriseLearnerEnrollment.objects.count() == 50 |
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