コード例 #1
0
ファイル: test_actions.py プロジェクト: opendatateam/udata
    def test_purge_sources(self):
        periodic_task = PeriodicTask.objects.create(
            task='harvest',
            name=faker.name(),
            description=faker.sentence(),
            enabled=True,
            crontab=PeriodicTask.Crontab()
        )
        now = datetime.now()
        to_delete = HarvestSourceFactory.create_batch(2, deleted=now)
        to_delete.append(
            HarvestSourceFactory(periodic_task=periodic_task, deleted=now)
        )
        to_keep = HarvestSourceFactory.create_batch(2)
        harvest_job = HarvestJobFactory(source=to_delete[0])

        result = actions.purge_sources()

        assert result == len(to_delete)
        assert len(HarvestSource.objects) == len(to_keep)
        assert PeriodicTask.objects.filter(id=periodic_task.id).count() == 0
        assert HarvestJob.objects(id=harvest_job.id).count() == 0