Ejemplo n.º 1
0
    def test_success(self, upload_obj):
        expired_at = timezone.now()
        upload_obj.expired_at = expired_at
        upload_obj.save(update_fields=["expired_at"])
        assert not upload_obj.deleted

        cleanup_upload(upload_obj.id, model=self.model)
        with pytest.raises(Upload.DoesNotExist):
            Upload.objects.get(id=upload_obj.id)
Ejemplo n.º 2
0
    def test_skip_cleanup(self, upload_obj):
        expired_at = timezone.now() + timedelta(minutes=1)
        upload_obj.expired_at = expired_at
        upload_obj.save(update_fields=["expired_at"])
        assert not upload_obj.deleted

        cleanup_upload(upload_obj.id, model=self.model)
        upload_obj = Upload.objects.get(id=upload_obj.id)
        assert not upload_obj.deleted
Ejemplo n.º 3
0
 def test_cleanup_not_found(self, mocker):
     mocked_logger = mocker.patch("core.tasks.logger")
     obj_id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"
     cleanup_upload(obj_id, model=self.model)
     mocked_logger.info.assert_called_once_with(
         "Datasource %s %s not found" % (self.model, obj_id),
         extra={
             "MESSAGE_ID": "datasource_not_found",
             "MODEL": self.model,
             "DATASOURCE_ID": obj_id,
             "TASK": "cleanup_upload",
         },
     )
Ejemplo n.º 4
0
 def test_dataregistry_failed(self, url_obj, mocker):
     mocked_logger = mocker.patch("core.tasks.logger")
     url_obj.urls = ["file:///file.json"]
     url_obj.save(update_fields=["urls"])
     assert not url_obj.deleted
     task = cleanup_upload(url_obj.id, model=self.model)
     assert not url_obj.deleted
     assert not task
     mocked_logger.debug.called_once_with(
         "Skip datasource cleanup %s, file is located in DATAREGISTRY_MEDIA_ROOT",
         url_obj.id)
Ejemplo n.º 5
0
 def test_unregistered_model(self, upload_obj, mocker):
     shutil = mocker.patch("core.tasks.shutil")
     cleanup_upload(upload_obj.id, model="SomeNew")
     assert shutil.rmtree.call_count == 0