示例#1
0
    def test_invalid_file_name(self, resolwe_mock, os_mock):
        os_mock.configure_mock(**{'path.isfile.return_value': False})

        message = r"File .* not found."
        with six.assertRaisesRegex(self, ValueError, message):
            Resolwe._process_file_field(resolwe_mock, "/bad/path/to/file")
        self.assertEqual(resolwe_mock._upload_file.call_count, 0)
示例#2
0
    def test_invalid_file_name(self, resolwe_mock, os_mock):
        os_mock.configure_mock(**{'path.isfile.return_value': False})

        message = r"File .* not found."
        with six.assertRaisesRegex(self, ValueError, message):
            Resolwe._process_file_field(resolwe_mock, "/bad/path/to/file")
        self.assertEqual(resolwe_mock._upload_file.call_count, 0)
示例#3
0
    def test_if_upload_fails(self, resolwe_mock, os_mock):
        # Good file, upload fails
        os_mock.configure_mock(**{'path.isfile.return_value': True})
        resolwe_mock._upload_file = MagicMock(return_value=None)

        message = r'Upload failed for .*'
        with six.assertRaisesRegex(self, Exception, message):
            Resolwe._process_file_field(resolwe_mock, "/good/path/to/file")
        self.assertEqual(resolwe_mock._upload_file.call_count, 1)
示例#4
0
    def test_if_upload_fails(self, resolwe_mock, os_mock):
        # Good file, upload fails
        os_mock.configure_mock(**{'path.isfile.return_value': True})
        resolwe_mock._upload_file = MagicMock(return_value=None)

        message = r'Upload failed for .*'
        with six.assertRaisesRegex(self, Exception, message):
            Resolwe._process_file_field(resolwe_mock, "/good/path/to/file")
        self.assertEqual(resolwe_mock._upload_file.call_count, 1)
示例#5
0
 def test_url(self, resolwe_mock):
     output = Resolwe._process_file_field(
         resolwe_mock, "http://www.example.com/reads.fq.gz")
     self.assertEqual(
         output, {
             'file': "reads.fq.gz",
             'file_temp': "http://www.example.com/reads.fq.gz"
         })
示例#6
0
    def test_if_upload_ok(self, resolwe_mock, os_mock, ntpath_mock):
        # Good file, upload fails
        os_mock.configure_mock(**{'path.isfile.return_value': True})
        resolwe_mock._upload_file = MagicMock(return_value="temporary_file")
        ntpath_mock.basename.return_value = "Basename returned!"

        output = Resolwe._process_file_field(resolwe_mock, "/good/path/to/file.txt")
        self.assertEqual(output, {'file': "Basename returned!", 'file_temp': "temporary_file"})

        resolwe_mock._upload_file.assert_called_once_with("/good/path/to/file.txt")
示例#7
0
    def test_if_upload_ok(self, resolwe_mock, os_mock, ntpath_mock):
        # Good file, upload fails
        os_mock.configure_mock(**{'path.isfile.return_value': True})
        resolwe_mock._upload_file = MagicMock(return_value="temporary_file")
        ntpath_mock.basename.return_value = "Basename returned!"

        output = Resolwe._process_file_field(resolwe_mock, "/good/path/to/file.txt")
        self.assertEqual(output, {'file': "Basename returned!", 'file_temp': "temporary_file"})

        resolwe_mock._upload_file.assert_called_once_with("/good/path/to/file.txt")
示例#8
0
 def test_url(self, resolwe_mock):
     output = Resolwe._process_file_field(resolwe_mock, "http://www.example.com/reads.fq.gz")
     self.assertEqual(
         output, {'file': "reads.fq.gz", 'file_temp': "http://www.example.com/reads.fq.gz"})