Exemplo n.º 1
0
    def test_dir_files(self, requests_mock):
        data = Data(id=123, resolwe=MagicMock(url='http://resolwe.url'))
        requests_mock.get = MagicMock(side_effect=[
            MagicMock(content=b'[{"type": "file", "name": "file1.txt"}, '
                              b'{"type": "directory", "name": "subdir"}]'),
            MagicMock(content=b'[{"type": "file", "name": "file2.txt"}]'),
        ])

        files = data._get_dir_files('test_dir')

        self.assertEqual(files, ['test_dir/file1.txt', 'test_dir/subdir/file2.txt'])
Exemplo n.º 2
0
    def test_dir_files(self, requests_mock):
        data = Data(id=123, resolwe=MagicMock(url='http://resolwe.url'))
        requests_mock.get = MagicMock(side_effect=[
            MagicMock(content=b'[{"type": "file", "name": "file1.txt"}, '
                              b'{"type": "directory", "name": "subdir"}]'),
            MagicMock(content=b'[{"type": "file", "name": "file2.txt"}]'),
        ])

        files = data._get_dir_files('test_dir')

        self.assertEqual(files, ['test_dir/file1.txt', 'test_dir/subdir/file2.txt'])
Exemplo n.º 3
0
 def test_dir_files(self, resolwe_mock):
     resolwe_mock.url = "http://resolwe.url"
     resolwe_mock.session.get.side_effect = [
         MagicMock(content=b'[{"type": "file", "name": "file1.txt"}, '
                   b'{"type": "directory", "name": "subdir"}]'),
         MagicMock(content=b'[{"type": "file", "name": "file2.txt"}]'),
     ]
     data = Data(id=123, resolwe=resolwe_mock)
     files = data._get_dir_files("test_dir")
     self.assertEqual(files,
                      ["test_dir/file1.txt", "test_dir/subdir/file2.txt"])
Exemplo n.º 4
0
    def test_files(self):
        resolwe = MagicMock()
        data = Data(id=123, resolwe=resolwe)
        data._get_dir_files = MagicMock(
            side_effect=[['first_dir/file1.txt'], ['fastq_dir/file2.txt']])

        data.output = {
            'list': [{'file': "element.gz"}],
            'dir_list': [{'dir': "first_dir"}],
            'fastq': {'file': "file.fastq.gz"},
            'fastq_archive': {'file': "archive.gz"},
            'fastq_dir': {'dir': "fastq_dir"},
        }
        data.process = Process(resolwe=resolwe, output_schema=[
            {'name': 'list', 'label': 'List', 'type': 'list:basic:file:'},
            {'name': 'dir_list', 'label': 'Dir_list', 'type': 'list:basic:dir:'},
            {'name': 'fastq', 'label': 'Fastq', 'type': 'basic:file:fastq:'},
            {'name': 'fastq_archive', 'label': 'Fastq_archive', 'type': 'basic:file:'},
            {'name': 'fastq_dir', 'label': 'Fastq_dir', 'type': 'basic:dir:'},
        ])

        file_list = data.files()
        self.assertCountEqual(file_list, [
            'element.gz',
            'archive.gz',
            'file.fastq.gz',
            'first_dir/file1.txt',
            'fastq_dir/file2.txt'
        ])
        file_list = data.files(file_name='element.gz')
        self.assertEqual(file_list, ['element.gz'])
        file_list = data.files(field_name='output.fastq')
        self.assertEqual(file_list, ['file.fastq.gz'])

        data.output = {
            'list': [{'no_file_field_here': "element.gz"}],
        }
        data.process.output_schema = [
            {'name': 'list', 'label': 'List', 'type': 'list:basic:file:'},
        ]
        with self.assertRaisesRegex(KeyError, "does not contain 'file' key."):
            data.files()

        data = Data(resolwe=MagicMock(), id=None)
        with self.assertRaisesRegex(ValueError, "must be saved before"):
            data.files()
Exemplo n.º 5
0
    def test_files(self):
        data = Data(id=123, resolwe=MagicMock())
        data._get_dir_files = MagicMock(
            side_effect=[['first_dir/file1.txt'], ['fastq_dir/file2.txt']])

        data.output = {
            'list': [{'file': "element.gz"}],
            'dir_list': [{'dir': "first_dir"}],
            'fastq': {'file': "file.fastq.gz"},
            'fastq_archive': {'file': "archive.gz"},
            'fastq_dir': {'dir': "fastq_dir"},
        }
        data.process_output_schema = [
            {'name': 'list', 'label': 'List', 'type': 'list:basic:file:'},
            {'name': 'dir_list', 'label': 'Dir_list', 'type': 'list:basic:dir:'},
            {'name': 'fastq', 'label': 'Fastq', 'type': 'basic:file:fastq:'},
            {'name': 'fastq_archive', 'label': 'Fastq_archive', 'type': 'basic:file:'},
            {'name': 'fastq_dir', 'label': 'Fastq_dir', 'type': 'basic:dir:'},
        ]

        file_list = data.files()
        self.assertCountEqual(file_list, [
            'element.gz',
            'archive.gz',
            'file.fastq.gz',
            'first_dir/file1.txt',
            'fastq_dir/file2.txt'
        ])
        file_list = data.files(file_name='element.gz')
        self.assertEqual(file_list, ['element.gz'])
        file_list = data.files(field_name='output.fastq')
        self.assertEqual(file_list, ['file.fastq.gz'])

        data.output = {
            'list': [{'no_file_field_here': "element.gz"}],
        }
        data.process_output_schema = [
            {'name': 'list', 'label': 'List', 'type': 'list:basic:file:'},
        ]
        with self.assertRaisesRegex(KeyError, "does not contain 'file' key."):
            data.files()

        data = Data(resolwe=MagicMock(), id=None)
        with self.assertRaisesRegex(ValueError, "must be saved before"):
            data.files()
Exemplo n.º 6
0
    def test_files(self):
        data = Data(id=123, resolwe=MagicMock())
        data._get_dir_files = MagicMock(
            side_effect=[['first_dir/file1.txt'], ['fastq_dir/file2.txt']])

        data.annotation = {
            'output.list': {'value': [{'file': "element.gz"}], 'type': 'list:basic:file:'},
            'output.dir_list': {'value': [{'dir': "first_dir"}], 'type': 'list:basic:dir:'},
            'output.fastq': {'value': {'file': "file.fastq.gz"}, 'type': 'basic:file:fastq'},
            'output.fastq_archive': {'value': {'file': "archive.gz"}, 'type': 'basic:file:'},
            'output.fastq_dir': {'value': {'dir': "fastq_dir"}, 'type': 'basic:dir:'},
            'input.fastq_url': {'value': {'file': "blah"}, 'type': 'basic:url:'},
            'input.blah': {'value': "blah.gz", 'type': 'basic:file:'}
        }

        file_list = data.files()
        six.assertCountEqual(self, file_list, [
            'element.gz',
            'archive.gz',
            'file.fastq.gz',
            'first_dir/file1.txt',
            'fastq_dir/file2.txt'
        ])
        file_list = data.files(file_name='element.gz')
        self.assertEqual(file_list, ['element.gz'])
        file_list = data.files(field_name='output.fastq')
        self.assertEqual(file_list, ['file.fastq.gz'])

        data.annotation = {
            'output.list': {'value': [{'no_file_field_here': "element.gz"}],
                            'type': 'list:basic:file:'},
        }
        with six.assertRaisesRegex(self, KeyError, "does not contain 'file' key."):
            data.files()

        data = Data(resolwe=MagicMock(), id=None)
        with six.assertRaisesRegex(self, ValueError, "must be saved before"):
            data.files()
Exemplo n.º 7
0
    def test_files(self):
        data = Data(id=123, resolwe=MagicMock())
        data._get_dir_files = MagicMock(
            side_effect=[['first_dir/file1.txt'], ['fastq_dir/file2.txt']])

        data.annotation = {
            'output.list': {
                'value': [{
                    'file': "element.gz"
                }],
                'type': 'list:basic:file:'
            },
            'output.dir_list': {
                'value': [{
                    'dir': "first_dir"
                }],
                'type': 'list:basic:dir:'
            },
            'output.fastq': {
                'value': {
                    'file': "file.fastq.gz"
                },
                'type': 'basic:file:fastq'
            },
            'output.fastq_archive': {
                'value': {
                    'file': "archive.gz"
                },
                'type': 'basic:file:'
            },
            'output.fastq_dir': {
                'value': {
                    'dir': "fastq_dir"
                },
                'type': 'basic:dir:'
            },
            'input.fastq_url': {
                'value': {
                    'file': "blah"
                },
                'type': 'basic:url:'
            },
            'input.blah': {
                'value': "blah.gz",
                'type': 'basic:file:'
            }
        }

        file_list = data.files()
        six.assertCountEqual(self, file_list, [
            'element.gz', 'archive.gz', 'file.fastq.gz', 'first_dir/file1.txt',
            'fastq_dir/file2.txt'
        ])
        file_list = data.files(file_name='element.gz')
        self.assertEqual(file_list, ['element.gz'])
        file_list = data.files(field_name='output.fastq')
        self.assertEqual(file_list, ['file.fastq.gz'])

        data.annotation = {
            'output.list': {
                'value': [{
                    'no_file_field_here': "element.gz"
                }],
                'type': 'list:basic:file:'
            },
        }
        with six.assertRaisesRegex(self, KeyError,
                                   "does not contain 'file' key."):
            data.files()

        data = Data(resolwe=MagicMock(), id=None)
        with six.assertRaisesRegex(self, ValueError, "must be saved before"):
            data.files()
Exemplo n.º 8
0
    def test_files(self):
        resolwe = MagicMock()
        data = Data(id=123, resolwe=resolwe)
        data._get_dir_files = MagicMock(
            side_effect=[["first_dir/file1.txt"], ["fastq_dir/file2.txt"]])

        data.output = {
            "list": [{
                "file": "element.gz"
            }],
            "dir_list": [{
                "dir": "first_dir"
            }],
            "fastq": {
                "file": "file.fastq.gz"
            },
            "fastq_archive": {
                "file": "archive.gz"
            },
            "fastq_dir": {
                "dir": "fastq_dir"
            },
        }
        data.process = Process(
            resolwe=resolwe,
            output_schema=[
                {
                    "name": "list",
                    "label": "List",
                    "type": "list:basic:file:"
                },
                {
                    "name": "dir_list",
                    "label": "Dir_list",
                    "type": "list:basic:dir:"
                },
                {
                    "name": "fastq",
                    "label": "Fastq",
                    "type": "basic:file:fastq:"
                },
                {
                    "name": "fastq_archive",
                    "label": "Fastq_archive",
                    "type": "basic:file:",
                },
                {
                    "name": "fastq_dir",
                    "label": "Fastq_dir",
                    "type": "basic:dir:"
                },
            ],
        )

        file_list = data.files()
        self.assertCountEqual(
            file_list,
            [
                "element.gz",
                "archive.gz",
                "file.fastq.gz",
                "first_dir/file1.txt",
                "fastq_dir/file2.txt",
            ],
        )
        file_list = data.files(file_name="element.gz")
        self.assertEqual(file_list, ["element.gz"])
        file_list = data.files(field_name="output.fastq")
        self.assertEqual(file_list, ["file.fastq.gz"])

        data.output = {
            "list": [{
                "no_file_field_here": "element.gz"
            }],
        }
        data.process.output_schema = [
            {
                "name": "list",
                "label": "List",
                "type": "list:basic:file:"
            },
        ]
        with self.assertRaisesRegex(KeyError, "does not contain 'file' key."):
            data.files()

        data = Data(resolwe=MagicMock(), id=None)
        with self.assertRaisesRegex(ValueError, "must be saved before"):
            data.files()