def test_survey(self, mock_send_task):
        """A Simple test of the ArrayExpress surveyor."""
        survey_job = self.create_job_for_accession("E-MTAB-3050")
        ae_surveyor = ArrayExpressSurveyor(survey_job)
        ae_surveyor.survey()

        samples = Sample.objects.all()
        downloader_jobs = DownloaderJob.objects.all()

        # We are expecting this to discover 5 samples.
        self.assertEqual(samples.count(), 5)

        # And for one DownloaderJob to be created for all of them.
        self.assertEqual(downloader_jobs.count(), 1)

        sample = Sample.objects.first()
        self.assertTrue(' (hgu95av2)' in sample.pretty_platform)
        # Confirm the sample's protocol_info
        self.assertEqual(len(sample.protocol_info), 9)
        self.assertEqual(sample.protocol_info[0]['Accession'], "P-MTAB-41854")
        self.assertEqual(sample.protocol_info[0]['Text'], "Aliquoting of biomaterials.")
        self.assertEqual(sample.protocol_info[0]['Type'], "split")

        survey_job2 = self.create_job_for_accession("E-GEOD-44719")
        ae_surveyor = ArrayExpressSurveyor(survey_job2)
        ae_surveyor.survey()

        # We are expecting this to discover 77 samples.
        self.assertEqual(samples.count(), 77+5)

        # And for one DownloaderJob to be created for all of them.
        self.assertEqual(downloader_jobs.count(), 2)
    def test_survey_with_protocol_list(self):
        """Tests an edge case that came up after months:
        https://github.com/AlexsLemonade/refinebio/issues/761
        """
        survey_job = self.create_job_for_accession("E-MEXP-2381")
        ae_surveyor = ArrayExpressSurveyor(survey_job)
        ae_surveyor.survey()

        samples = Sample.objects.all()
        downloader_jobs = DownloaderJob.objects.all()

        # We are expecting this to discover 2 samples.
        self.assertEqual(samples.count(), 2)

        # And for one DownloaderJob to be created for all of them.
        self.assertEqual(downloader_jobs.count(), 1)
Beispiel #3
0
    def test_survey(self, mock_send_task, mock_get):
        """The 'survey' function generates one Batch per sample.

        This test also tests the handle_batches method of ExternalSourceSurveyor
        which isn't tested on its own because it is an abstract class.
        """
        mock_send_task.return_value = Mock(ok=True)
        mock_get.side_effect = mocked_requests_get

        ae_surveyor = ArrayExpressSurveyor(self.survey_job)
        ae_surveyor.survey()

        downloader_jobs = DownloaderJob.objects.all()
        mock_send_task.assert_has_calls(
            [call(Downloaders.ARRAY_EXPRESS, downloader_jobs[0].id)])
        batches = Batch.objects.all()
        self.assertEqual(2, len(batches))
        self.assertEqual(1, len(downloader_jobs))

        batch = batches[0]
        self.assertEqual(batch.survey_job.id, self.survey_job.id)
        self.assertEqual(batch.source_type, "ARRAY_EXPRESS")
        self.assertEqual(batch.pipeline_required, "AFFY_TO_PCL")
        self.assertEqual(batch.platform_accession_code, "A-AFFY-1")
        self.assertEqual(batch.experiment_accession_code, "E-MTAB-3050")
        self.assertEqual(batch.experiment_title,
                         "Microarray analysis of in vitro differentiation")
        self.assertEqual(batch.status, "NEW")
        self.assertEqual(batch.release_date, datetime.date(2014, 10, 31))
        self.assertEqual(batch.last_uploaded_date, datetime.date(2014, 10, 30))
        self.assertEqual(batch.organism_id, 9606)
        self.assertEqual(batch.organism_name, "H**O SAPIENS")

        file = batch.files[0]
        self.assertEqual(file.size_in_bytes, -1)
        self.assertEqual(
            file.download_url,
            "ftp://ftp.ebi.ac.uk/pub/databases/microarray/data/experiment/MTAB/E-MTAB-3050/E-MTAB-3050.raw.1.zip"
        )  # noqa
        self.assertEqual(file.raw_format, "CEL")
        self.assertEqual(file.processed_format, "PCL")
        self.assertEqual(file.name, "C30057.CEL")
        self.assertEqual(file.internal_location, "A-AFFY-1/AFFY_TO_PCL")
    def test_survey(self, mock_send_task):
        """A Simple test of the ArrayExpress surveyor."""
        survey_job = self.create_job_for_accession("E-MTAB-3050")
        ae_surveyor = ArrayExpressSurveyor(survey_job)
        ae_surveyor.survey()

        samples = Sample.objects.all()
        downloader_jobs = DownloaderJob.objects.all()

        # We are expecting this to discover 5 samples.
        self.assertEqual(samples.count(), 5)

        # And for one DownloaderJob to be created for all of them.
        self.assertEqual(downloader_jobs.count(), 1)

        experiment = Experiment.objects.first()
        self.assertEqual(experiment.accession_code, "E-MTAB-3050")
        self.assertEqual(experiment.source_first_published,
                         datetime.datetime(2014, 10, 31, tzinfo=timezone.utc))
        self.assertEqual(experiment.source_last_modified,
                         datetime.datetime(2014, 10, 30, tzinfo=timezone.utc))

        sample = Sample.objects.first()
        self.assertTrue(" (hgu95av2)" in sample.pretty_platform)
        # Confirm the sample's protocol_info
        self.assertEqual(len(sample.protocol_info), 9)
        self.assertEqual(sample.protocol_info[0]["Accession"], "P-MTAB-41854")
        self.assertEqual(sample.protocol_info[0]["Text"],
                         "Aliquoting of biomaterials.")
        self.assertEqual(sample.protocol_info[0]["Type"], "split")

        survey_job2 = self.create_job_for_accession("E-GEOD-44719")
        ae_surveyor = ArrayExpressSurveyor(survey_job2)
        ae_surveyor.survey()

        # We are expecting this to discover 77 samples.
        self.assertEqual(samples.count(), 77 + 5)

        # And for one DownloaderJob to be created for all of them.
        self.assertEqual(downloader_jobs.count(), 2)