def test_empty_mtx_file(self):
        """Ingest Pipeline should fail gracefully when an empty file is given
        """

        args = [
            "--study-id",
            "5d276a50421aa9117c982845",
            "--study-file-id",
            "5dd5ae25421aa910a723a337",
            "ingest_expression",
            "--taxon-name",
            "H**o sapiens",
            "--taxon-common-name",
            "human",
            "--ncbi-taxid",
            "9606",
            "--genome-assembly-accession",
            "GCA_000001405.15",
            "--genome-annotation",
            "Ensembl 94",
            "--matrix-file",
            "../tests/data/mtx/AB_toy_data_toy.matrix.mtx",
            "--matrix-file-type",
            "mtx",
            "--gene-file",
            "../tests/data/empty_file.txt",
            "--barcode-file",
            "../tests/data/mtx/AB_toy_data_toy.barcodes.tsv",
        ]
        ingest, arguments, status, status_cell_metadata = self.execute_ingest(
            args)

        with self.assertRaises(SystemExit) as cm:
            exit_pipeline(ingest, status, status_cell_metadata, arguments)
        self.assertEqual(cm.exception.code, 1)
    def test_bad_cluster_missing_coordinate_file(self):
        """Ingest Pipeline should fail for missing coordinate in cluster file
        """
        args = [
            "--study-id",
            "5d276a50421aa9117c982845",
            "--study-file-id",
            "5dd5ae25421aa910a723a337",
            "ingest_cluster",
            "--cluster-file",
            "../tests/data/cluster_bad_missing_coordinate.txt",
            "--ingest-cluster",
            "--name",
            "cluster1",
        ]
        ingest, arguments, status, status_cell_metadata = self.execute_ingest(
            args)

        with self.assertRaises(SystemExit) as cm:
            exit_pipeline(ingest, status, status_cell_metadata, arguments)
        self.assertEqual(cm.exception.code, 1)
    def test_bad_metadata_file(self):
        """Ingest Pipeline should not succeed for misformatted metadata file
        """
        args = [
            "--study-id",
            "5d276a50421aa9117c982845",
            "--study-file-id",
            "5dd5ae25421aa910a723a337",
            "ingest_cell_metadata",
            "--cell-metadata-file",
            "../tests/data/metadata_bad.txt",
            "--study-accession",
            "SCP123",
            "--ingest-cell-metadata",
        ]
        ingest, arguments, status, status_cell_metadata = self.execute_ingest(
            args)

        with self.assertRaises(SystemExit) as cm:
            exit_pipeline(ingest, status, status_cell_metadata, arguments)
        self.assertEqual(cm.exception.code, 1)
 def test_subsample_no_cell_intersection(self, mock_load_subsample):
     """When cell values in cluster are not present in cell metadata file ingest should fail.
     """
     args = [
         "--study-id",
         "5d276a50421aa9117c982845",
         "--study-file-id",
         "5dd5ae25421aa910a723a337",
         "ingest_subsample",
         "--cluster-file",
         "../tests/data/good_subsample_cluster.csv",
         "--name",
         "custer1",
         "--cell-metadata-file",
         "../tests/data/test_cell_metadata.csv",
         "--subsample",
     ]
     ingest, arguments, status, status_cell_metadata = self.execute_ingest(
         args)
     with self.assertRaises(SystemExit) as cm, self.assertRaises(
             ValueError):
         exit_pipeline(ingest, status, status_cell_metadata, arguments)
     self.assertEqual(cm.exception.code, 1)
    def test_exponential_back_off_expression_file(self,
                                                  mock_check_unique_cells,
                                                  mock_load):
        """Ingest Pipeline should not succeed if mongo cannot connect after 5
            reconnection tries.
        """
        args = [
            "--study-id",
            "5d276a50421aa9117c982845",
            "--study-file-id",
            "5dd5ae25421aa910a723a337",
            "ingest_expression",
            "--taxon-name",
            "H**o sapiens",
            "--taxon-common-name",
            "human",
            "--ncbi-taxid",
            "9606",
            "--genome-assembly-accession",
            "GCA_000001405.15",
            "--genome-annotation",
            "Ensembl 94",
            "--matrix-file",
            "gs://fake-bucket/tests/data/AB_toy_data_toy.matrix.mtx",
            "--matrix-file-type",
            "mtx",
            "--gene-file",
            "gs://fake-bucket/tests/data/AB_toy_data_toy.genes.tsv",
            "--barcode-file",
            "gs://fake-bucket/tests/data/AB_toy_data_toy.barcodes.tsv",
        ]
        ingest, arguments, status, status_cell_metadata = self.execute_ingest(
            args)

        with self.assertRaises(SystemExit) as cm:
            exit_pipeline(ingest, status, status_cell_metadata, arguments)
        self.assertEqual(cm.exception.code, 1)