Ejemplo n.º 1
0
    def test_get_by_token_all_uploaded_files(self):
        # Tests that get_by_token does not remove old BilbyJob instances that do have all their
        # uploaded supporting files.

        # Check that if all supporting files are uploaded, the job is not deleted
        tokens = [t['token'] for t in SupportingFile.save_from_parsed(self.job, self.parsed)]

        self.assertEqual(SupportingFile.objects.count(), 3)

        for sf in SupportingFile.objects.all():
            sf.upload_token = None
            sf.save()

        for t in tokens:
            self.assertIsNone(SupportingFile.get_by_upload_token(t))

        self.assertTrue(BilbyJob.objects.filter(id=self.job.id).exists())

        # Check objects just inside the deletion time are not deleted
        self.job.creation_time = self.after - timezone.timedelta(seconds=settings.UPLOAD_SUPPORTING_FILE_EXPIRY - 1)
        self.job.save()

        for t in tokens:
            self.assertIsNone(SupportingFile.get_by_upload_token(t))

        self.assertTrue(BilbyJob.objects.filter(id=self.job.id).exists())

        # Check objects just outside the deletion time are not deleted if all supporting files are uploaded
        self.job.creation_time = self.after - timezone.timedelta(seconds=settings.UPLOAD_SUPPORTING_FILE_EXPIRY + 1)
        self.job.save()

        for t in tokens:
            self.assertIsNone(SupportingFile.get_by_upload_token(t))

        self.assertTrue(BilbyJob.objects.filter(id=self.job.id).exists())
Ejemplo n.º 2
0
    def test_get_by_token_non_uploaded_files(self):
        # Tests that get_by_token correctly removes old BilbyJob instances that do not have all their
        # uploaded supporting files.

        # Test that objects created now are not removed
        tokens = [t['token'] for t in SupportingFile.save_from_parsed(self.job, self.parsed)]

        for t in tokens:
            self.assertIsNotNone(SupportingFile.get_by_upload_token(t))

        # Check objects just inside the deletion time are not deleted
        self.job.creation_time = self.after - timezone.timedelta(seconds=settings.UPLOAD_SUPPORTING_FILE_EXPIRY - 1)
        self.job.save()

        for t in tokens:
            self.assertIsNotNone(SupportingFile.get_by_upload_token(t))

        # Check objects just outside the deletion time are deleted
        self.job.creation_time = self.after - timezone.timedelta(seconds=settings.UPLOAD_SUPPORTING_FILE_EXPIRY + 1)
        self.job.save()

        for t in tokens:
            self.assertIsNone(SupportingFile.get_by_upload_token(t))

        self.assertFalse(BilbyJob.objects.filter(id=self.job.id).exists())
Ejemplo n.º 3
0
    def test_pruning_jobs_with_all_uploaded_supporting_files(self):
        # Test that BilbyJob's objects older than settings.UPLOAD_SUPPORTING_FILE_EXPIRY are not removed
        # from the database if all SupportingFile's are uploaded

        # Check that if all supporting files are uploaded, the job is not deleted
        SupportingFile.save_from_parsed(self.job, self.parsed)

        self.assertEqual(SupportingFile.objects.count(), 3)

        for sf in SupportingFile.objects.all():
            sf.upload_token = None
            sf.save()

        BilbyJob.prune_supporting_files_jobs()

        self.assertEqual(BilbyJob.objects.all().count(), 1)

        # Check objects just inside the deletion time are not deleted
        self.job.creation_time = self.after - timezone.timedelta(seconds=settings.UPLOAD_SUPPORTING_FILE_EXPIRY - 1)
        self.job.save()

        BilbyJob.prune_supporting_files_jobs()

        self.assertEqual(BilbyJob.objects.all().count(), 1)

        # Check objects just outside the deletion time are not deleted if all supporting files are uploaded
        self.job.creation_time = self.after - timezone.timedelta(seconds=settings.UPLOAD_SUPPORTING_FILE_EXPIRY + 1)
        self.job.save()

        BilbyJob.prune_supporting_files_jobs()

        self.assertEqual(BilbyJob.objects.all().count(), 1)
Ejemplo n.º 4
0
    def test_pruning_jobs_with_non_uploaded_supporting_files(self):
        # Test that BilbyJob's objects older than settings.UPLOAD_SUPPORTING_FILE_EXPIRY are correctly removed
        # from the database if there are any SupportingFile's that are not uploaded

        # Test that objects created now are not removed
        SupportingFile.save_from_parsed(self.job, self.parsed)

        BilbyJob.prune_supporting_files_jobs()

        self.assertEqual(BilbyJob.objects.all().count(), 1)

        # Check objects just inside the deletion time are not deleted
        self.job.creation_time = self.after - timezone.timedelta(seconds=settings.UPLOAD_SUPPORTING_FILE_EXPIRY - 1)
        self.job.save()

        BilbyJob.prune_supporting_files_jobs()

        self.assertEqual(BilbyJob.objects.all().count(), 1)

        # Check objects just outside the deletion time are deleted
        self.job.creation_time = self.after - timezone.timedelta(seconds=settings.UPLOAD_SUPPORTING_FILE_EXPIRY + 1)
        self.job.save()

        BilbyJob.prune_supporting_files_jobs()

        self.assertEqual(BilbyJob.objects.all().count(), 0)
Ejemplo n.º 5
0
    def test_get_by_download_token(self):
        # Test that it's possible to get a SupportingFile object by the download token.
        SupportingFile.save_from_parsed(self.job, self.parsed)

        # Get the last inserted SupportingFile
        sf = SupportingFile.objects.last()

        # This file is not uploaded so get_by_download_token should return None
        self.assertIsNone(SupportingFile.get_by_download_token(sf.download_token))

        # Mark the supporting file as uploaded
        sf.upload_token = None
        sf.save()

        # Now the supporting file should be returned by get_by_download_token
        self.assertEquals(SupportingFile.get_by_download_token(sf.download_token).id, sf.id)
Ejemplo n.º 6
0
    def test_save_from_parsed(self):
        # Test that parsed supporting files are correctly entered in to the database
        supporting_file_tokens = SupportingFile.save_from_parsed(self.job, self.parsed)

        self.assertEqual(SupportingFile.objects.count(), 3)

        for token in supporting_file_tokens:
            self.assertTrue(
                SupportingFile.objects.filter(
                    upload_token=token['token'],
                    file_name=Path(token['file_path']).name
                ).exists()
            )
Ejemplo n.º 7
0
 def test_get_by_download_token_invalid(self):
     # Test that a supporting file can't be fetched by an invalid token
     SupportingFile.save_from_parsed(self.job, self.parsed)
     self.assertIsNone(SupportingFile.get_by_download_token(str(uuid.uuid4())))