Example #1
0
    def test_file_not_available(self):
        """
        If a requested file is not available in the repository, a 404 error is
        raised.
        """
        with self.assertRaises(HTTPError) as exception:
            get_checksum(url='file://' + FilePath(self.mktemp()).path)

        self.assertEqual(404, exception.exception.response.status_code)
Example #2
0
 def test_checksum(self):
     """
     The sha1 hash of a file at a given URI is returned.
     """
     source_repo = FilePath(self.mktemp())
     source_repo.makedirs()
     example_file = source_repo.child("example_file")
     example_file.setContent("Some content")
     uri = "file://" + example_file.path
     self.assertEqual("9f1a6ecf74e9f9b1ae52e8eb581d420e63e8453a", get_checksum(url=uri))
Example #3
0
 def test_checksum(self):
     """
     The sha1 hash of a file at a given URI is returned.
     """
     source_repo = FilePath(self.mktemp())
     source_repo.makedirs()
     example_file = source_repo.child('example_file')
     example_file.setContent("Some content")
     uri = 'file://' + example_file.path
     self.assertEqual('9f1a6ecf74e9f9b1ae52e8eb581d420e63e8453a',
                      get_checksum(url=uri))
Example #4
0
    def test_gzip(self):
        """
        The sha1 hash of a gzip and not its unzipped content is returned.
        """
        source_repo = FilePath(self.mktemp())
        source_repo.makedirs()
        example_file = source_repo.child("example_gzip.tar.gz")
        # Set mtime else a timestamp of the current time will be used,
        # making the assertion value change.
        gzip_file = gzip.GzipFile(filename=example_file.path, mode="wb", mtime=0)
        self.addCleanup(gzip_file.close)
        gzip_file.write("Some content")
        uri = "file://" + example_file.path

        self.assertEqual("da39a3ee5e6b4b0d3255bfef95601890afd80709", get_checksum(url=uri))
Example #5
0
    def test_gzip(self):
        """
        The sha1 hash of a gzip and not its unzipped content is returned.
        """
        source_repo = FilePath(self.mktemp())
        source_repo.makedirs()
        example_file = source_repo.child('example_gzip.tar.gz')
        # Set mtime else a timestamp of the current time will be used,
        # making the assertion value change.
        gzip_file = gzip.GzipFile(
            filename=example_file.path, mode="wb", mtime=0)
        self.addCleanup(gzip_file.close)
        gzip_file.write("Some content")
        uri = 'file://' + example_file.path

        self.assertEqual(
            'da39a3ee5e6b4b0d3255bfef95601890afd80709',
            get_checksum(url=uri))