Example #1
0
    def test_anonymised_migration_uses_operator__check_passes(self):
        executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
        plan = executor.migration_plan(executor.loader.graph.leaf_nodes())

        # Sanity check - confirm plan is what we expected from Django
        self.assertEqual(
            self.plan_to_names(plan),
            [
                ("anonymised_migration", "0002_migrate_anonymised"),
                ("anonymised_migration", "0003_auto_20201020_0102"),
            ],
        )

        # Run check
        errors = check_migrate_gdpr_anonymised(
            executor.loader.project_state().apps)
        self.assertEqual(len(errors), 0)
Example #2
0
    def test_missing_anonymised_migration__check_fails(self):
        executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
        plan = executor.migration_plan(executor.loader.graph.leaf_nodes())

        # Sanity check - confirm plan is what we expected from Django
        self.assertEqual(
            self.plan_to_names(plan),
            [("missing_anonymised_migration", "0002_auto_20201020_0102")],
        )

        # Run check
        errors = check_migrate_gdpr_anonymised(
            executor.loader.project_state().apps)
        self.assertEqual(len(errors), 1)
        error = errors[0]
        self.assertEqual(
            error.msg, "Removing anonymised field before its data is migrated")
        self.assertEqual(error.id, "gdpr_assist.E001")
Example #3
0
    def test_no_anonymised_migration_uses_flag__check_passes(self):
        executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
        plan = executor.migration_plan(executor.loader.graph.leaf_nodes())

        # Sanity check - confirm plan is what we expected from Django
        self.assertEqual(
            self.plan_to_names(plan),
            [
                ("no_anonymised_migration", "0001_initial"),
                ("gdpr_assist", "0002_privacyanonymised"),
                ('gdpr_assist', '0003_auto_20210205_1657'),
                ('gdpr_assist', '0004_auto_20211215_1057'),
                ("no_anonymised_migration", "0002_auto_20201020_0102"),
            ],
        )

        # Run check
        errors = check_migrate_gdpr_anonymised(
            executor.loader.project_state().apps)
        self.assertEqual(len(errors), 0)