Skip to content

Commit

Permalink
feat: remove content transmission audits without a catalog uuid (#1793)
Browse files Browse the repository at this point in the history
* feat: remove transmission audits without catalog uuids

* fix: updated changelog

* fix: bumped version

* fix: updated test
  • Loading branch information
katrinan029 committed Jul 24, 2023
1 parent d13c093 commit aa37d50
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ Change Log
Unreleased
----------
[4.0.4]
--------
feat: remove content transmission audits without a catalog uuid

[4.0.3]
-------
fix: changing sap transmit metadata flow to account for rate limiting
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Your project description goes here.
"""

__version__ = "4.0.3"
__version__ = "4.0.4"

default_app_config = "enterprise.apps.EnterpriseConfig"
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Remove content transmission audit records that do not contain a catalog UUID.
"""
import logging

from django.core.management.base import BaseCommand

from integrated_channels.integrated_channel.management.commands import IntegratedChannelCommandMixin
from integrated_channels.integrated_channel.tasks import remove_null_catalog_transmission_audits

LOGGER = logging.getLogger(__name__)


class Command(IntegratedChannelCommandMixin, BaseCommand):
"""
Remove content transmission audit records that do not contain a catalog UUID.
./manage.py lms remove_null_catalog_transmission_audits
"""

def handle(self, *args, **options):
"""
Filter content transmission audit records that do not contain a catalog UUID and remove them.
"""
try:
remove_null_catalog_transmission_audits.delay()
except Exception as exc: # pylint: disable=broad-except
LOGGER.exception(
f'''Failed to remove content transmission audits that do not
contain a catalog UUID. Task failed with exception: {exc}'''
)
25 changes: 25 additions & 0 deletions integrated_channels/integrated_channel/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ def _log_batch_task_finish(task_name, channel_code, job_user_id,
))


@shared_task
@set_code_owner_attribute
def remove_null_catalog_transmission_audits():
"""
Task to remove content transmission audit records that do not contain a catalog UUID.
"""
start = time.time()

_log_batch_task_start('remove_null_catalog_transmission_audits', None, None, None)

deleted_null_catalog_uuids = ContentMetadataItemTransmission.objects.filter(
enterprise_customer_catalog_uuid=None
).delete()

duration_seconds = time.time() - start
_log_batch_task_finish(
'remove_null_catalog_transmission_audits',
channel_code=None,
job_user_id=None,
integrated_channel_full_config=None,
duration_seconds=duration_seconds,
extra_message=f"{deleted_null_catalog_uuids[0]} transmission audits with no catalog UUIDs removed"
)


@shared_task
@set_code_owner_attribute
def remove_duplicate_transmission_audits():
Expand Down
32 changes: 32 additions & 0 deletions tests/test_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -2012,3 +2012,35 @@ def test_invalid_audits(self):
assert moodle_config.last_sync_errored_at == old_timestamp
assert moodle_config.last_content_sync_errored_at == old_timestamp
assert moodle_config.last_learner_sync_errored_at is None


@mark.django_db
@ddt.ddt
class TestRemoveNullCatalogTransmissionAuditsManagementCommand(unittest.TestCase, EnterpriseMockMixin):
"""
Test the ``remove_null_catalog_transmission_audits`` management command.
"""
def setUp(self):
self.enterprise_customer_1 = factories.EnterpriseCustomerFactory(
name='Wonka Factory',
)
self.enterprise_customer_2 = factories.EnterpriseCustomerFactory(
name='Hershey LLC',
)
factories.ContentMetadataItemTransmissionFactory(
enterprise_customer=self.enterprise_customer_1,
enterprise_customer_catalog_uuid=None
)
factories.ContentMetadataItemTransmissionFactory(
enterprise_customer=self.enterprise_customer_2,
enterprise_customer_catalog_uuid="d9efab41-5e09-4094-977a-96313b3dca08"
)
super().setUp()

def test_normal_run(self):
assert ContentMetadataItemTransmission.objects.all().count() == 2
call_command('remove_null_catalog_transmission_audits')
assert ContentMetadataItemTransmission.objects.all().count() == 1
assert ContentMetadataItemTransmission.objects.filter(
enterprise_customer_catalog_uuid=None
).count() == 0

0 comments on commit aa37d50

Please sign in to comment.