|
21 | 21 | ZONE_TITLE,
|
22 | 22 | ZONE_DESC,
|
23 | 23 | )
|
| 24 | +from landingzones.tests.test_views_taskflow import LandingZoneTaskflowMixin |
24 | 25 |
|
25 | 26 | # Samplesheets dependency
|
26 | 27 | from samplesheets.tests.test_io import SampleSheetIOMixin, SHEET_DIR
|
|
67 | 68 | BATCH_OBJ_NAME = 'batch_obj'
|
68 | 69 | BATCH_OBJ2_NAME = 'batch_obj2'
|
69 | 70 |
|
| 71 | +SUFFIX_OBJ_NAME_BAM = 'test.bam' |
| 72 | +SUFFIX_OBJ_NAME_VCF = 'test.vcf.gz' |
| 73 | +SUFFIX_OBJ_NAME_TXT = ' test.txt' |
| 74 | + |
70 | 75 |
|
71 | 76 | class IRODSTaskTestBase(TaskflowViewTestBase):
|
72 | 77 | """Base test class for iRODS tasks"""
|
@@ -1868,6 +1873,180 @@ def test_revert_mixed(self):
|
1868 | 1873 | self.assert_irods_access(DEFAULT_USER_GROUP, self.sub_coll_path2, None)
|
1869 | 1874 |
|
1870 | 1875 |
|
| 1876 | +class TestBatchCheckFileSuffixTask( |
| 1877 | + SampleSheetIOMixin, |
| 1878 | + LandingZoneMixin, |
| 1879 | + LandingZoneTaskflowMixin, |
| 1880 | + IRODSTaskTestBase, |
| 1881 | +): |
| 1882 | + """Tests for BatchCheckFileSuffixTask""" |
| 1883 | + |
| 1884 | + def setUp(self): |
| 1885 | + super().setUp() |
| 1886 | + self.investigation = self.import_isa_from_file(SHEET_PATH, self.project) |
| 1887 | + self.study = self.investigation.studies.first() |
| 1888 | + self.assay = self.study.assays.first() |
| 1889 | + self.zone = self.make_landing_zone( |
| 1890 | + title=ZONE_TITLE, |
| 1891 | + project=self.project, |
| 1892 | + user=self.user, |
| 1893 | + assay=self.assay, |
| 1894 | + description=ZONE_DESC, |
| 1895 | + ) |
| 1896 | + self.make_zone_taskflow(zone=self.zone) |
| 1897 | + self.zone_path = self.irods_backend.get_path(self.zone) |
| 1898 | + self.zone_coll = self.irods.collections.get(self.zone_path) |
| 1899 | + self.obj_bam = self.make_irods_object( |
| 1900 | + self.zone_coll, SUFFIX_OBJ_NAME_BAM |
| 1901 | + ) |
| 1902 | + self.obj_vcf = self.make_irods_object( |
| 1903 | + self.zone_coll, SUFFIX_OBJ_NAME_VCF |
| 1904 | + ) |
| 1905 | + self.obj_txt = self.make_irods_object( |
| 1906 | + self.zone_coll, SUFFIX_OBJ_NAME_TXT |
| 1907 | + ) |
| 1908 | + self.obj_paths = [ |
| 1909 | + self.obj_bam.path, |
| 1910 | + self.obj_vcf.path, |
| 1911 | + self.obj_txt.path, |
| 1912 | + ] |
| 1913 | + self.task_kw = { |
| 1914 | + 'cls': BatchCheckFileSuffixTask, |
| 1915 | + 'name': 'Check file suffixes', |
| 1916 | + 'inject': { |
| 1917 | + 'file_paths': self.obj_paths, |
| 1918 | + 'zone_path': self.zone_path, |
| 1919 | + }, |
| 1920 | + } |
| 1921 | + |
| 1922 | + def test_check_bam(self): |
| 1923 | + """Test batch file suffix check with prohibited BAM type""" |
| 1924 | + self.task_kw['inject']['suffixes'] = ['bam'] |
| 1925 | + self.add_task(**self.task_kw) |
| 1926 | + with self.assertRaises(Exception) as cm: |
| 1927 | + self.run_flow() |
| 1928 | + ex = cm.exception |
| 1929 | + self.assertIn(SUFFIX_OBJ_NAME_BAM, ex) |
| 1930 | + self.assertNotIn(SUFFIX_OBJ_NAME_VCF, ex) |
| 1931 | + self.assertNotIn(SUFFIX_OBJ_NAME_TXT, ex) |
| 1932 | + |
| 1933 | + def test_check_vcf(self): |
| 1934 | + """Test check with prohibited VCF type""" |
| 1935 | + self.task_kw['inject']['suffixes'] = ['vcf.gz'] |
| 1936 | + self.add_task(**self.task_kw) |
| 1937 | + with self.assertRaises(Exception) as cm: |
| 1938 | + self.run_flow() |
| 1939 | + ex = cm.exception |
| 1940 | + self.assertNotIn(SUFFIX_OBJ_NAME_BAM, ex) |
| 1941 | + self.assertIn(SUFFIX_OBJ_NAME_VCF, ex) |
| 1942 | + self.assertNotIn(SUFFIX_OBJ_NAME_TXT, ex) |
| 1943 | + |
| 1944 | + def test_check_multiple(self): |
| 1945 | + """Test check with multiple prohibited types""" |
| 1946 | + self.task_kw['inject']['suffixes'] = ['bam', 'vcf.gz'] |
| 1947 | + self.add_task(**self.task_kw) |
| 1948 | + with self.assertRaises(Exception) as cm: |
| 1949 | + self.run_flow() |
| 1950 | + ex = cm.exception |
| 1951 | + self.assertIn(SUFFIX_OBJ_NAME_BAM, ex) |
| 1952 | + self.assertIn(SUFFIX_OBJ_NAME_VCF, ex) |
| 1953 | + self.assertNotIn(SUFFIX_OBJ_NAME_TXT, ex) |
| 1954 | + |
| 1955 | + def test_check_multiple_not_found(self): |
| 1956 | + """Test check with multiple types not found in files""" |
| 1957 | + self.task_kw['inject']['suffixes'] = ['mp3', 'rar'] |
| 1958 | + self.add_task(**self.task_kw) |
| 1959 | + result = self.run_flow() |
| 1960 | + self.assertEqual(result, True) |
| 1961 | + |
| 1962 | + def test_check_empty_list(self): |
| 1963 | + """Test check with empty prohibition list""" |
| 1964 | + self.task_kw['inject']['suffixes'] = [] |
| 1965 | + self.add_task(**self.task_kw) |
| 1966 | + result = self.run_flow() |
| 1967 | + self.assertEqual(result, True) |
| 1968 | + |
| 1969 | + def test_check_notation_dot(self): |
| 1970 | + """Test check with dot notation in list""" |
| 1971 | + self.task_kw['inject']['suffixes'] = ['.bam'] |
| 1972 | + self.add_task(**self.task_kw) |
| 1973 | + with self.assertRaises(Exception) as cm: |
| 1974 | + self.run_flow() |
| 1975 | + ex = cm.exception |
| 1976 | + self.assertIn(SUFFIX_OBJ_NAME_BAM, ex) |
| 1977 | + self.assertNotIn(SUFFIX_OBJ_NAME_VCF, ex) |
| 1978 | + self.assertNotIn(SUFFIX_OBJ_NAME_TXT, ex) |
| 1979 | + |
| 1980 | + def test_check_notation_asterisk(self): |
| 1981 | + """Test check with asterisk notation in list""" |
| 1982 | + self.task_kw['inject']['suffixes'] = ['*bam'] |
| 1983 | + self.add_task(**self.task_kw) |
| 1984 | + with self.assertRaises(Exception) as cm: |
| 1985 | + self.run_flow() |
| 1986 | + ex = cm.exception |
| 1987 | + self.assertIn(SUFFIX_OBJ_NAME_BAM, ex) |
| 1988 | + self.assertNotIn(SUFFIX_OBJ_NAME_VCF, ex) |
| 1989 | + self.assertNotIn(SUFFIX_OBJ_NAME_TXT, ex) |
| 1990 | + |
| 1991 | + def test_check_notation_combined(self): |
| 1992 | + """Test check with combined notation in list""" |
| 1993 | + self.task_kw['inject']['suffixes'] = ['*.bam'] |
| 1994 | + self.add_task(**self.task_kw) |
| 1995 | + with self.assertRaises(Exception) as cm: |
| 1996 | + self.run_flow() |
| 1997 | + ex = cm.exception |
| 1998 | + self.assertIn(SUFFIX_OBJ_NAME_BAM, ex) |
| 1999 | + self.assertNotIn(SUFFIX_OBJ_NAME_VCF, ex) |
| 2000 | + self.assertNotIn(SUFFIX_OBJ_NAME_TXT, ex) |
| 2001 | + |
| 2002 | + def test_check_extra_spaces(self): |
| 2003 | + """Test check with extra spaces""" |
| 2004 | + self.task_kw['inject']['suffixes'] = [' bam '] |
| 2005 | + self.add_task(**self.task_kw) |
| 2006 | + with self.assertRaises(Exception) as cm: |
| 2007 | + self.run_flow() |
| 2008 | + ex = cm.exception |
| 2009 | + self.assertIn(SUFFIX_OBJ_NAME_BAM, ex) |
| 2010 | + self.assertNotIn(SUFFIX_OBJ_NAME_VCF, ex) |
| 2011 | + self.assertNotIn(SUFFIX_OBJ_NAME_TXT, ex) |
| 2012 | + |
| 2013 | + def test_check_not_end_of_file(self): |
| 2014 | + """Test check with given string not in end of file name""" |
| 2015 | + self.task_kw['inject']['suffixes'] = ['test'] |
| 2016 | + self.add_task(**self.task_kw) |
| 2017 | + result = self.run_flow() |
| 2018 | + self.assertEqual(result, True) |
| 2019 | + |
| 2020 | + def test_check_upper_case(self): |
| 2021 | + """Test check with upper case string""" |
| 2022 | + self.task_kw['inject']['suffixes'] = ['BAM'] |
| 2023 | + self.add_task(**self.task_kw) |
| 2024 | + with self.assertRaises(Exception) as cm: |
| 2025 | + self.run_flow() |
| 2026 | + ex = cm.exception |
| 2027 | + self.assertIn(SUFFIX_OBJ_NAME_BAM, ex) |
| 2028 | + self.assertNotIn(SUFFIX_OBJ_NAME_VCF, ex) |
| 2029 | + self.assertNotIn(SUFFIX_OBJ_NAME_TXT, ex) |
| 2030 | + |
| 2031 | + def test_check_invalid_strings(self): |
| 2032 | + """Test check with invalid strings""" |
| 2033 | + self.task_kw['inject']['suffixes'] = ['', '*', '*.*'] |
| 2034 | + self.add_task(**self.task_kw) |
| 2035 | + result = self.run_flow() |
| 2036 | + self.assertEqual(result, True) |
| 2037 | + |
| 2038 | + def test_check_invalid_valid(self): |
| 2039 | + """Test check with mixed invalid and valid strings""" |
| 2040 | + self.task_kw['inject']['suffixes'] = ['', '*', 'bam'] |
| 2041 | + self.add_task(**self.task_kw) |
| 2042 | + with self.assertRaises(Exception) as cm: |
| 2043 | + self.run_flow() |
| 2044 | + ex = cm.exception |
| 2045 | + self.assertIn(SUFFIX_OBJ_NAME_BAM, ex) |
| 2046 | + self.assertNotIn(SUFFIX_OBJ_NAME_VCF, ex) |
| 2047 | + self.assertNotIn(SUFFIX_OBJ_NAME_TXT, ex) |
| 2048 | + |
| 2049 | + |
1871 | 2050 | class TestBatchCreateCollectionsTask(IRODSTaskTestBase):
|
1872 | 2051 | """Tests for BatchCreateCollectionsTask"""
|
1873 | 2052 |
|
|
0 commit comments