Beispiel #1
0
    def test_migrate_certifications(self):
        def _check_old_certifications_unchanged():
            self.assertEquals(WorkerCertification.objects.filter(
                worker=self.worker,
                certification__workflow=self.workflow_old).count(), 4)
            self.assertEquals(WorkerCertification.objects.filter(
                worker=self.worker,
                certification__workflow=self.workflow_old,
                certification__slug='certification1',
                role=WorkerCertification.Role.ENTRY_LEVEL).count(), 1)
            self.assertEquals(WorkerCertification.objects.filter(
                worker=self.worker,
                certification__workflow=self.workflow_old,
                certification__slug='certification1',
                role=WorkerCertification.Role.REVIEWER).count(), 1)
            self.assertEquals(WorkerCertification.objects.filter(
                worker=self.worker,
                certification__workflow=self.workflow_old,
                certification__slug='certification2',
                role=WorkerCertification.Role.ENTRY_LEVEL).count(), 1)
            self.assertEquals(WorkerCertification.objects.filter(
                worker=self.worker,
                certification__workflow=self.workflow_old,
                certification__slug='certification2',
                role=WorkerCertification.Role.REVIEWER).count(), 1)

        _check_old_certifications_unchanged()
        # New workflow should have no worker certifications
        self.assertEquals(WorkerCertification.objects.filter(
            worker=self.worker,
            certification__workflow=self.workflow_new).count(), 0)

        # Migrate `certification1`
        migrate_certifications(
            self.workflow_old.slug,
            self.workflow_new.slug,
            ['certification1'])

        _check_old_certifications_unchanged()

        # New workflow should have only `certification1` worker certifications
        self.assertEquals(WorkerCertification.objects.filter(
            worker=self.worker,
            certification__workflow=self.workflow_new).count(), 2)
        self.assertEquals(WorkerCertification.objects.filter(
            worker=self.worker,
            certification__workflow=self.workflow_new,
            certification__slug='certification1',
            role=WorkerCertification.Role.ENTRY_LEVEL).count(), 1)
        self.assertEquals(WorkerCertification.objects.filter(
            worker=self.worker,
            certification__workflow=self.workflow_new,
            certification__slug='certification1',
            role=WorkerCertification.Role.REVIEWER).count(), 1)

        # Migrate all source certifications
        migrate_certifications(
            self.workflow_old.slug,
            self.workflow_new.slug,
            [])

        _check_old_certifications_unchanged()

        # `certification2` should now be migrated as well
        self.assertEquals(WorkerCertification.objects.filter(
            worker=self.worker,
            certification__workflow=self.workflow_new).count(), 4)
        self.assertEquals(WorkerCertification.objects.filter(
            worker=self.worker,
            certification__workflow=self.workflow_new,
            certification__slug='certification1',
            role=WorkerCertification.Role.ENTRY_LEVEL).count(), 1)
        self.assertEquals(WorkerCertification.objects.filter(
            worker=self.worker,
            certification__workflow=self.workflow_new,
            certification__slug='certification1',
            role=WorkerCertification.Role.REVIEWER).count(), 1)
        self.assertEquals(WorkerCertification.objects.filter(
            worker=self.worker,
            certification__workflow=self.workflow_new,
            certification__slug='certification2',
            role=WorkerCertification.Role.ENTRY_LEVEL).count(), 1)
        self.assertEquals(WorkerCertification.objects.filter(
            worker=self.worker,
            certification__workflow=self.workflow_new,
            certification__slug='certification2',
            role=WorkerCertification.Role.REVIEWER).count(), 1)
Beispiel #2
0
    def test_migrate_certifications(self):
        def _check_old_certifications_unchanged():
            self.assertEquals(
                WorkerCertification.objects.filter(
                    worker=self.worker, certification__workflow=self.workflow_old
                ).count(),
                4,
            )
            self.assertEquals(
                WorkerCertification.objects.filter(
                    worker=self.worker,
                    certification__workflow=self.workflow_old,
                    certification__slug="certification1",
                    role=WorkerCertification.Role.ENTRY_LEVEL,
                ).count(),
                1,
            )
            self.assertEquals(
                WorkerCertification.objects.filter(
                    worker=self.worker,
                    certification__workflow=self.workflow_old,
                    certification__slug="certification1",
                    role=WorkerCertification.Role.REVIEWER,
                ).count(),
                1,
            )
            self.assertEquals(
                WorkerCertification.objects.filter(
                    worker=self.worker,
                    certification__workflow=self.workflow_old,
                    certification__slug="certification2",
                    role=WorkerCertification.Role.ENTRY_LEVEL,
                ).count(),
                1,
            )
            self.assertEquals(
                WorkerCertification.objects.filter(
                    worker=self.worker,
                    certification__workflow=self.workflow_old,
                    certification__slug="certification2",
                    role=WorkerCertification.Role.REVIEWER,
                ).count(),
                1,
            )

        _check_old_certifications_unchanged()
        # New workflow should have no worker certifications
        self.assertEquals(
            WorkerCertification.objects.filter(worker=self.worker, certification__workflow=self.workflow_new).count(), 0
        )

        # Migrate `certification1`
        migrate_certifications(self.workflow_old.slug, self.workflow_new.slug, ["certification1"])

        _check_old_certifications_unchanged()

        # New workflow should have only `certification1` worker certifications
        self.assertEquals(
            WorkerCertification.objects.filter(worker=self.worker, certification__workflow=self.workflow_new).count(), 2
        )
        self.assertEquals(
            WorkerCertification.objects.filter(
                worker=self.worker,
                certification__workflow=self.workflow_new,
                certification__slug="certification1",
                role=WorkerCertification.Role.ENTRY_LEVEL,
            ).count(),
            1,
        )
        self.assertEquals(
            WorkerCertification.objects.filter(
                worker=self.worker,
                certification__workflow=self.workflow_new,
                certification__slug="certification1",
                role=WorkerCertification.Role.REVIEWER,
            ).count(),
            1,
        )

        # Migrate all source certifications
        migrate_certifications(self.workflow_old.slug, self.workflow_new.slug, [])

        _check_old_certifications_unchanged()

        # `certification2` should now be migrated as well
        self.assertEquals(
            WorkerCertification.objects.filter(worker=self.worker, certification__workflow=self.workflow_new).count(), 4
        )
        self.assertEquals(
            WorkerCertification.objects.filter(
                worker=self.worker,
                certification__workflow=self.workflow_new,
                certification__slug="certification1",
                role=WorkerCertification.Role.ENTRY_LEVEL,
            ).count(),
            1,
        )
        self.assertEquals(
            WorkerCertification.objects.filter(
                worker=self.worker,
                certification__workflow=self.workflow_new,
                certification__slug="certification1",
                role=WorkerCertification.Role.REVIEWER,
            ).count(),
            1,
        )
        self.assertEquals(
            WorkerCertification.objects.filter(
                worker=self.worker,
                certification__workflow=self.workflow_new,
                certification__slug="certification2",
                role=WorkerCertification.Role.ENTRY_LEVEL,
            ).count(),
            1,
        )
        self.assertEquals(
            WorkerCertification.objects.filter(
                worker=self.worker,
                certification__workflow=self.workflow_new,
                certification__slug="certification2",
                role=WorkerCertification.Role.REVIEWER,
            ).count(),
            1,
        )
 def handle(self, *args, **options):
     migrate_certifications(
         options['source_workflow_slug'],
         options['destination_workflow_slug'],
         options['certifications'])
 def handle(self, *args, **options):
     migrate_certifications(options['source_workflow_slug'],
                            options['destination_workflow_slug'],
                            options['certifications'])