Пример #1
0
 def test_invalid_url(self):
     url = "xyz"
     with self.assertRaises(ValueError) as ctx:
         retrieve_filename(url)
     ex = str(ctx.exception)
     msg = f"Cannot connect to URL: {url}"
     self.assertTrue(msg in ex)
Пример #2
0
 def test_no_path_no_header(self):
     """Test the case where there is no filepath and no filename header."""
     url = "https://www.google.com"
     fn = retrieve_filename(url)
     # Assert that filename is a non-empty string
     self.assertTrue(isinstance(fn, str))
     self.assertTrue(len(fn) > 0)
Пример #3
0
 def test_use_url_filepath_no_header(self):
     """
     Test the case where we are able fetch from the URL, but we get no content header
     """
     expected_fn = "SP1.fq"
     url = f"http://molb7621.github.io/workshop/_downloads/{expected_fn}"
     fn = retrieve_filename(url)
     self.assertEqual(fn, expected_fn)
Пример #4
0
 def test_use_resp_header(self):
     """
     Test the case where we get the filename from the response header.
     """
     expected_fn = 'file1.txt'
     url = f"https://anl.box.com/shared/static/4ero6ld3322gnfcbssegglbdbpdvpzae.txt"
     fn = retrieve_filename(url)
     self.assertEqual(fn, expected_fn)
Пример #5
0
 def test_filename_truncation_no_ext(self):
     """
     Test the case where the retrieved filename (without extension) is too
     long, so we truncate to 255 chars.
     """
     given_fn = str(uuid4()) * 20
     url = f"https://www.example.com/{given_fn}"
     expected_fn = given_fn[0:255]
     fn = retrieve_filename(url)
     self.assertEqual(fn, expected_fn)