|
4 | 4 | from django.test import override_settings |
5 | 5 | from django.test import TestCase |
6 | 6 | from mock import patch |
| 7 | +from morango.models import Certificate |
| 8 | +from morango.models import DatabaseIDModel |
| 9 | +from morango.models import DatabaseMaxCounter |
| 10 | +from morango.models import DeletedModels |
| 11 | +from morango.models import HardDeletedModels |
| 12 | +from morango.models import Store |
7 | 13 | from morango.sync.controller import MorangoProfileController |
8 | 14 |
|
9 | 15 | from .. import models as auth_models |
10 | | -from ..management.commands import deprovision |
11 | 16 | from .helpers import setup_device |
12 | 17 | from .test_api import ClassroomFactory |
13 | 18 | from .test_api import LearnerGroupFactory |
14 | 19 | from kolibri.core.auth.constants.morango_sync import PROFILE_FACILITY_DATA |
15 | 20 | from kolibri.core.content import models as content_models |
| 21 | +from kolibri.core.device.models import DevicePermissions |
| 22 | +from kolibri.core.device.models import DeviceSettings |
| 23 | +from kolibri.core.logger.models import AttemptLog |
| 24 | +from kolibri.core.logger.models import ContentSessionLog |
| 25 | +from kolibri.core.logger.models import ContentSummaryLog |
16 | 26 | from kolibri.core.logger.test.factory_logger import ContentSessionLogFactory |
17 | 27 | from kolibri.core.logger.test.factory_logger import ContentSummaryLogFactory |
18 | 28 | from kolibri.core.logger.test.factory_logger import FacilityUserFactory |
19 | 29 | from kolibri.core.logger.test.factory_logger import UserSessionLogFactory |
20 | 30 |
|
| 31 | +MODELS_DELETED_BY_DEPROVISION = [ |
| 32 | + AttemptLog, |
| 33 | + ContentSessionLog, |
| 34 | + ContentSummaryLog, |
| 35 | + auth_models.FacilityUser, |
| 36 | + auth_models.FacilityDataset, |
| 37 | + HardDeletedModels, |
| 38 | + Certificate, |
| 39 | + DatabaseIDModel, |
| 40 | + Store, |
| 41 | + DevicePermissions, |
| 42 | + DeletedModels, |
| 43 | + DeviceSettings, |
| 44 | + DatabaseMaxCounter, |
| 45 | +] |
| 46 | + |
21 | 47 |
|
22 | 48 | def count_instances(models): |
23 | 49 | return sum([model.objects.count() for model in models]) |
@@ -54,16 +80,18 @@ def setUp(self): |
54 | 80 | MorangoProfileController(PROFILE_FACILITY_DATA).serialize_into_store() |
55 | 81 |
|
56 | 82 | @patch("kolibri.core.auth.management.commands.deprovision.confirm_or_exit") |
57 | | - def test_setup_no_headers_bad_user_good_user(self, confirm_or_exit_mock): |
| 83 | + def test_deprovision_deletes_user_data_preserves_content( |
| 84 | + self, confirm_or_exit_mock |
| 85 | + ): |
58 | 86 | models_that_should_remain = [ |
59 | 87 | content_models.LocalFile, |
60 | 88 | content_models.ContentNode, |
61 | 89 | content_models.File, |
62 | 90 | content_models.AssessmentMetaData, |
63 | 91 | ] |
64 | | - assert count_instances(deprovision.MODELS_TO_DELETE) > 0 |
| 92 | + assert count_instances(MODELS_DELETED_BY_DEPROVISION) > 0 |
65 | 93 | initial_model_count = count_instances(models_that_should_remain) |
66 | 94 | assert initial_model_count > 0 |
67 | 95 | call_command("deprovision") |
68 | | - assert count_instances(deprovision.MODELS_TO_DELETE) == 0 |
| 96 | + assert count_instances(MODELS_DELETED_BY_DEPROVISION) == 0 |
69 | 97 | assert count_instances(models_that_should_remain) == initial_model_count |
0 commit comments