def testEmptyFilename(self):
     #1
     url=''
     filename=''
     result=download_if_needed(url,filename)
     expected_explanation='Please input a correct filename.'
     self.assertEqual(result, expected_explanation)
     #2
     url='https://google.com'
     filename=''
     result=download_if_needed(url,filename)
     expected_explanation='Please input a correct filename.'
     self.assertEqual(result, expected_explanation)
 def testIncorrectURLs(self):
     #1
     url='https://geegle.com'
     filename='testFilename.txt'
     result=download_if_needed(url,filename)
     expected_explanation='Could not connect to server. Please check to make sure the URL is valid and try again.'
     self.assertEqual(result, expected_explanation)
     #2
     url='https://s3.amazws.com/pronto-data/open_data_year_one.zip'
     filename='data_year_one.zip'
     result=download_if_needed(url,filename)
     expected_explanation='Could not connect to server. Please check to make sure the URL is valid and try again.'
     self.assertEqual(result, expected_explanation)
 def testEmptyURL(self):
     #1
     url=''
     filename='testFilename.txt'
     result=download_if_needed(url,filename)
     expected_explanation='No host specified.'
     self.assertEqual(result, expected_explanation)
 def test_file_present(self):
     remove_data("open_data_year_one.zip")
     get_pronto_data()
     result = download_if_needed(
         "https://s3.amazonaws.com/pronto-data/open_data_year_one.zip", "open_data_year_one.zip"
     )
     self.assertEqual("open_data_year_one.zip already exists", result)
 def testFileExists(self):
     #1
     url='https://s3.amazonaws.com/pronto-data/open_data_year_one.zip'
     filename='open_data_year_one.zip'
     result=download_if_needed(url,filename)
     expected_explanation=(filename, 'already exists')
     self.assertEqual(result, expected_explanation)
 def testCorrectURLs(self):
     #1
     if os.path.isfile('Fig3-1.xls'):
         os.remove('Fig3-1.xls')
     url='http://www.econ.yale.edu/~shiller/data/Fig3-1.xls'
     filename='Fig3-1.xls'
     result=download_if_needed(url,filename)
     expected_explanation=('Downloading', filename)
     self.assertEqual(result, expected_explanation)
     #2
     if os.path.isfile('dataYale.xls'):
         os.remove('dataYale.xls')
     url='http://www.econ.yale.edu/~shiller/data/ie_data.xls'
     filename='dataYale.xls'
     result=download_if_needed(url,filename)
     expected_explanation=('Downloading', filename)
     self.assertEqual(result, expected_explanation)
 def test_download_unneeded(self):
     """
     Ensures download if needed function won't double download_if_needed
     """
     # We just downloaded the test.zip so let's make sure it doesn't
     # download again if it's queried
     result = download_if_needed(
         'https://github.com/UWSEDS/Cogert/blob/master/analysis/test.zip',
         'test.zip')
     self.assertTrue(result[0])
Ejemplo n.º 8
0
        def testDownloadIfNeeded(self):
            """
            Test the data download function in the case of both an invalid
            and valid URL. In the former case, we check to see that the data
            file does not exist (since the link was invalid); in the latter,
            we check that the data file does exist.
            """

            validURL = 'https://s3.amazonaws.com/pronto-data/open_data_year_one.zip'
            invalidURL = 'ttps://s3.amazonaws.com/pronto-data/open_data_year_one.zip'
            fileName = 'open_data_year_one.zip'
            path = os.getcwd() + '\open_data_year_one.zip'

            # invalid url
            download_if_needed(invalidURL,fileName)
            self.assertFalse(os.path.exists(path))

            # valid url
            download_if_needed(validURL,fileName)
            self.assertTrue(os.path.exists(path))
 def test_download_needed(self):
     """
     Tests the download if needed function downloads new files
     """
     # Remove data works, so let's make sure test.zip isn't
     # around so we can download it for the test and verify that
     # it will download
     remove_file('test.zip')
     result = download_if_needed(
         'https://github.com/UWSEDS/Cogert/blob/master/analysis/test.zip',
         'test.zip')
     self.assertFalse(result[0])
 def test_file_removal(self):
     download_if_needed("https://s3.amazonaws.com/pronto-data/open_data_year_one.zip", "open_data_year_one.zip")
     result = remove_data("open_data_year_one.zip")
     self.assertEqual(result, "Data file removed")
 def test_url_nonexistent(self):
     remove_data("open_data_year_one.zip")
     result = download_if_needed(
         "https://s3.amazonaws.com/pronto-data/open_data_year_ne.zip", "open_data_year_one.zip"
     )
     self.assertEqual("Url does not exist", result)