def test_standard(self): """ Test standard use-case """ global TO test_url = TO["dl_url"] target_file = TO["temp_file"] # Make sure invalid URL's fail self.assertRaises(ValueError, nrcSpreadsheetScraper.download, *["asdf", target_file], **{"overwrite": False}) # Standard test self.assertEqual(target_file, nrcSpreadsheetScraper.download(test_url, target_file))
def test_overwrite(self): """ Test overwriting an existing file """ global TO # Create an empty test file to see if an exception is raised when the target file exists and overwrite=False with open(TO["temp_file"], "w") as f: f.write(str("")) self.assertRaises( ValueError, nrcSpreadsheetScraper.download, *[TO["dl_url"], TO["temp_file"]], **{"overwrite": False} ) # Make sure file is still empty and nothing was downloaded self.assertTrue(os.path.getsize(TO["temp_file"]) == 0) # Download file self.assertEqual(TO["temp_file"], nrcSpreadsheetScraper.download(TO["dl_url"], TO["temp_file"], overwrite=True))