Skip to content

Commit

Permalink
Merge pull request #288 from openedx/saleem-latif/ENT-5010
Browse files Browse the repository at this point in the history
ENT-5010: feat: Created a new management command for adding dummy data for learner progress report v2.
  • Loading branch information
saleem-latif committed Mar 2, 2022
2 parents 57681b5 + 1022022 commit 0b720ed
Show file tree
Hide file tree
Showing 16 changed files with 207 additions and 77 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Unreleased
----------

=========================
[4.1.0] - 2022-03-01
---------------------
* Created a new management command for adding dummy data for learner progress report v1.

[4.0.0] - 2022-02-14
---------------------
* Dropped support for Django 2.2, 3.0 and 3.1
Expand Down
2 changes: 1 addition & 1 deletion enterprise_data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Enterprise data api application. This Django app exposes API endpoints used by enterprises.
"""

__version__ = "4.0.0"
__version__ = "4.1.0"

default_app_config = "enterprise_data.apps.EnterpriseDataAppConfig" # pylint: disable=invalid-name
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)
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
14 changes: 10 additions & 4 deletions enterprise_data/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,21 @@ class Meta:

enterprise_user_id = factory.lazy_attribute(lambda x: FAKER.random_int(min=1)) # pylint: disable=no-member
enterprise_customer_uuid = str(FAKER.uuid4()) # pylint: disable=no-member
lms_user_created = datetime(2011, 1, 1, tzinfo=pytz.utc)
enterprise_user_created = FAKER.past_datetime(start_date='-30d')
enterprise_user_modified = FAKER.past_datetime(start_date='-30d')
enterprise_user_active = FAKER.pybool()
lms_user_id = factory.lazy_attribute(
lambda x: FAKER.random_int(min=1, max=999999) # pylint: disable=no-member
)
is_linked = FAKER.pybool()
user_username = factory.Sequence('robot{}'.format)
user_email = factory.lazy_attribute(lambda x: FAKER.email()) # pylint: disable=no-member
lms_user_created = FAKER.past_datetime(start_date='-60d')
lms_last_login = FAKER.past_datetime(start_date='-10d')
lms_user_country = factory.lazy_attribute(lambda x: FAKER.country_code()) # pylint: disable=no-member
enterprise_sso_uid = factory.lazy_attribute(lambda x: FAKER.text(max_nb_chars=255)) # pylint: disable=no-member
last_activity_date = datetime(2012, 1, 1).date()
lms_user_id = factory.lazy_attribute(
lambda x: FAKER.random_int(min=1, max=999999) # pylint: disable=no-member
)
created_at = FAKER.past_datetime(start_date='-30d')


class EnterpriseLearnerEnrollmentFactory(factory.django.DjangoModelFactory):
Expand Down
1 change: 1 addition & 0 deletions requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ django-fernet-fields
django-model-utils
edx-rbac
rules
factory_boy
15 changes: 10 additions & 5 deletions requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ asn1crypto==1.4.0
# via
# oscrypto
# snowflake-connector-python
awscli==1.22.55
awscli==1.22.64
# via -r requirements/reporting.in
bcrypt==3.2.0
# via paramiko
billiard==3.6.4.0
# via celery
boto3==1.21.0
boto3==1.21.9
# via -r requirements/reporting.in
botocore==1.24.0
botocore==1.24.9
# via
# awscli
# boto3
Expand Down Expand Up @@ -104,6 +104,10 @@ edx-rbac==1.6.0
# via -r requirements/base.in
edx-rest-api-client==5.5.0
# via -r requirements/base.in
factory-boy==3.2.1
# via -r requirements/base.in
faker==13.3.0
# via factory-boy
future==0.18.2
# via pyjwkest
idna==3.3
Expand All @@ -120,7 +124,7 @@ kombu==4.6.11
# via celery
monotonic==1.6
# via py2neo
newrelic==7.4.0.172
newrelic==7.6.0.173
# via edx-django-utils
oscrypto==1.2.1
# via snowflake-connector-python
Expand Down Expand Up @@ -172,6 +176,7 @@ python-dateutil==2.8.2
# via
# botocore
# edx-drf-extensions
# faker
# vertica-python
pytz==2021.3
# via
Expand All @@ -194,7 +199,7 @@ rsa==4.7.2
# via awscli
rules==3.1
# via -r requirements/base.in
s3transfer==0.5.1
s3transfer==0.5.2
# via
# awscli
# boto3
Expand Down
8 changes: 4 additions & 4 deletions requirements/ci.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ charset-normalizer==2.0.12
# via requests
codecov==2.1.12
# via -r requirements/ci.in
coverage==6.3.1
coverage==6.3.2
# via codecov
distlib==0.3.4
# via virtualenv
filelock==3.5.0
filelock==3.6.0
# via
# tox
# virtualenv
idna==3.3
# via requests
packaging==21.3
# via tox
platformdirs==2.5.0
platformdirs==2.5.1
# via virtualenv
pluggy==1.0.0
# via tox
Expand All @@ -48,5 +48,5 @@ tox-battery==0.5.2
# -r requirements/ci.in
urllib3==1.26.8
# via requests
virtualenv==20.13.1
virtualenv==20.13.2
# via tox
37 changes: 21 additions & 16 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@ astroid==2.9.3
# via
# pylint
# pylint-celery
awscli==1.22.55
awscli==1.22.64
# via -r requirements/reporting.in
bcrypt==3.2.0
# via paramiko
billiard==3.6.4.0
# via celery
bleach==4.1.0
# via readme-renderer
boto3==1.21.0
boto3==1.21.9
# via -r requirements/reporting.in
botocore==1.24.0
botocore==1.24.9
# via
# awscli
# boto3
Expand All @@ -50,7 +50,7 @@ charset-normalizer==2.0.12
# via
# requests
# snowflake-connector-python
click==8.0.3
click==8.0.4
# via
# click-log
# code-annotations
Expand Down Expand Up @@ -137,7 +137,11 @@ edx-rbac==1.6.0
# via -r requirements/base.in
edx-rest-api-client==5.5.0
# via -r requirements/base.in
filelock==3.5.0
factory-boy==3.2.1
# via -r requirements/base.in
faker==13.3.0
# via factory-boy
filelock==3.6.0
# via
# tox
# virtualenv
Expand All @@ -147,7 +151,7 @@ idna==3.3
# via
# requests
# snowflake-connector-python
importlib-metadata==4.11.1
importlib-metadata==4.11.2
# via
# keyring
# twine
Expand All @@ -171,13 +175,13 @@ kombu==4.6.11
# via celery
lazy-object-proxy==1.7.1
# via astroid
markupsafe==2.0.1
markupsafe==2.1.0
# via jinja2
mccabe==0.6.1
# via pylint
monotonic==1.6
# via py2neo
newrelic==7.4.0.172
newrelic==7.6.0.173
# via edx-django-utils
oscrypto==1.2.1
# via snowflake-connector-python
Expand All @@ -190,7 +194,7 @@ pansi==2020.7.3
# via py2neo
paramiko==2.9.2
# via -r requirements/reporting.in
path==16.3.0
path==16.4.0
# via edx-i18n-tools
pbr==5.8.1
# via stevedore
Expand All @@ -202,7 +206,7 @@ pip-tools==6.5.1
# via -r requirements/dev-enterprise_data.in
pkginfo==1.8.2
# via twine
platformdirs==2.5.0
platformdirs==2.5.1
# via
# pylint
# virtualenv
Expand Down Expand Up @@ -253,7 +257,7 @@ pylint==2.12.2
# pylint-plugin-utils
pylint-celery==0.3
# via edx-lint
pylint-django==2.5.0
pylint-django==2.5.2
# via edx-lint
pylint-plugin-utils==0.7
# via
Expand All @@ -273,8 +277,9 @@ python-dateutil==2.8.2
# via
# botocore
# edx-drf-extensions
# faker
# vertica-python
python-slugify==5.0.2
python-slugify==6.1.1
# via code-annotations
pytz==2021.3
# via
Expand Down Expand Up @@ -310,7 +315,7 @@ rsa==4.7.2
# via awscli
rules==3.1
# via -r requirements/base.in
s3transfer==0.5.1
s3transfer==0.5.2
# via
# awscli
# boto3
Expand Down Expand Up @@ -347,7 +352,7 @@ stevedore==3.5.0
# code-annotations
# edx-django-utils
# edx-opaque-keys
testfixtures==6.18.3
testfixtures==6.18.4
# via -r requirements/quality.in
text-unidecode==1.3
# via python-slugify
Expand All @@ -365,7 +370,7 @@ tox-battery==0.5.2
# via
# -c requirements/constraints.txt
# -r requirements/dev-enterprise_data.in
tqdm==4.62.3
tqdm==4.63.0
# via twine
twine==3.8.0
# via -r requirements/dev-enterprise_data.in
Expand All @@ -387,7 +392,7 @@ vine==1.3.0
# via
# amqp
# celery
virtualenv==20.13.1
virtualenv==20.13.2
# via tox
webencodings==0.5.1
# via bleach
Expand Down
2 changes: 1 addition & 1 deletion requirements/pip.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ wheel==0.37.1
# The following packages are considered to be unsafe in a requirements file:
pip==20.0.2
# via -r requirements/pip.in
setuptools==60.9.1
setuptools==60.9.3
# via -r requirements/pip.in
2 changes: 1 addition & 1 deletion requirements/pip_tools.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#
# make upgrade
#
click==8.0.3
click==8.0.4
# via pip-tools
pep517==0.12.0
# via pip-tools
Expand Down
Loading

0 comments on commit 0b720ed

Please sign in to comment.