Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure deprovisioning management command deletes DMC #9208

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions kolibri/core/auth/management/commands/deprovision.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import logging
import sys

from morango.models import Buffer
from morango.models import Certificate
from morango.models import DatabaseIDModel
from morango.models import DatabaseMaxCounter
from morango.models import DeletedModels
from morango.models import HardDeletedModels
from morango.models import Store

from kolibri.core.auth.management.utils import confirm_or_exit
Expand All @@ -27,13 +28,14 @@
ContentSummaryLog,
FacilityUser,
FacilityDataset,
HardDeletedModels,
Certificate,
DatabaseIDModel,
Store,
Buffer,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is mostly my own ignorance, but why don't we want to delete the Buffer?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It ForeignKeys onto the TransferSession, so it was redundant -- it does still get deleted.

DevicePermissions,
DeletedModels,
DeviceSettings,
DatabaseMaxCounter,
]


Expand Down
8 changes: 6 additions & 2 deletions kolibri/core/auth/test/test_deprovisioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
from django.core.management import call_command
from django.test import TestCase
from mock import patch
from morango.sync.controller import MorangoProfileController

from .. import models as auth_models
from ..management.commands import deprovision
from .helpers import setup_device
from .test_api import ClassroomFactory
from .test_api import LearnerGroupFactory
from kolibri.core.auth.constants.morango_sync import PROFILE_FACILITY_DATA
from kolibri.core.content import models as content_models
from kolibri.core.logger.test.factory_logger import ContentSessionLogFactory
from kolibri.core.logger.test.factory_logger import ContentSummaryLogFactory
Expand Down Expand Up @@ -50,6 +52,7 @@ def setUp(self):
user=user, content_id=uuid.uuid4().hex, channel_id=uuid.uuid4().hex
)
UserSessionLogFactory.create(user=user)
MorangoProfileController(PROFILE_FACILITY_DATA).serialize_into_store()

@patch("kolibri.core.auth.management.commands.deprovision.confirm_or_exit")
def test_setup_no_headers_bad_user_good_user(self, confirm_or_exit_mock):
Expand All @@ -60,7 +63,8 @@ def test_setup_no_headers_bad_user_good_user(self, confirm_or_exit_mock):
content_models.AssessmentMetaData,
]
assert count_instances(deprovision.MODELS_TO_DELETE) > 0
assert count_instances(models_that_should_remain) > 0
initial_model_count = count_instances(models_that_should_remain)
assert initial_model_count > 0
call_command("deprovision")
assert count_instances(deprovision.MODELS_TO_DELETE) == 0
assert count_instances(models_that_should_remain) > 0
assert count_instances(models_that_should_remain) == initial_model_count