Exemple #1
0
 def test_download_badsha1(self):
   f = tempfile.NamedTemporaryFile(delete=False)
   f.write('asdf')
   f.close()
   assert util.sha1file(f.name) != self.sha1_gtfs
   entity = util.example_feed()
   entity.data['url'] = self.url
   entity.download(f.name, verify=True, sha1=self.sha1_gtfs)
   assert util.sha1file(f.name) == self.sha1_gtfs
Exemple #2
0
 def test_download(self):
   # Download the file, then download again to verify cache.
   f = tempfile.NamedTemporaryFile(delete=False)
   f.close()
   entity = util.example_feed()
   entity.data['url'] = self.url
   entity.download(f.name, cache=False)
   assert util.sha1file(f.name) == self.sha1_gtfs
 def test_download(self):
   # Create a temporary file name, then delete it...
   # Of course, never do this in non-testing code!!
   f = tempfile.NamedTemporaryFile()
   f.close()
   # Make sure it doesn't exist.
   assert not os.path.exists(f.name)
   # Now download, using the deleted temporary file name.
   util.download(self.url, f.name)
   assert util.sha1file(f.name) == self.sha1_gtfs
 def download(self, filename=None, cache=True, verify=True, sha1=None):
     """Download the GTFS feed to a file. Return filename."""
     if cache and self.verify_sha1(filename, sha1):
         return filename
     filename = util.download(self.url(), filename)
     if verify and sha1 and not self.verify_sha1(filename, sha1):
         raise errors.InvalidChecksumError(
             "Incorrect checksum: %s, expected %s" %
             (util.sha1file(filename), sha1))
     return filename
 def download(self, filename=None, cache=True, verify=True, sha1=None):
   """Download the GTFS feed to a file. Return filename."""
   if cache and self.verify_sha1(filename, sha1):
     return filename
   filename = util.download(self.url(), filename)
   if verify and sha1 and not self.verify_sha1(filename, sha1):
     raise errors.InvalidChecksumError("Incorrect checksum: %s, expected %s"%(
       util.sha1file(filename),
       sha1
     ))
   return filename
 def verify_sha1(self, filename, sha1):
   """Check if a file is validly cached."""
   if os.path.exists(filename):
     if sha1 and util.sha1file(filename) == sha1:
       return True
   return False
 def test_sha1file(self):
   data = util.sha1file(util.example_gtfs_feed_path())
   expect = '4e5e6a2668d12cca29c89a969d73e05e625d9596'
   assert data == expect
 def test_download_nofile(self):
   filename = util.download(self.url)
   assert util.sha1file(filename) == self.sha1_gtfs
 def verify_sha1(self, filename, sha1):
     """Check if a file is validly cached."""
     if os.path.exists(filename):
         if sha1 and util.sha1file(filename) == sha1:
             return True
     return False