def test_charm_base_inheritance(self): """ get_sha256() should be implemented in the base class, and should use compute_sha256 to calculate the digest. """ directory = CharmDirectory(self.sample_dir1) bundle = directory.as_bundle() digest = compute_file_hash(hashlib.sha256, bundle.path) self.assertEquals(digest, directory.get_sha256())
def test_compute_sha256(self): """ Computing the sha256 of a directory will use the bundled charm, since the hash of the file itself is needed. """ directory = CharmDirectory(self.sample_dir1) sha256 = directory.compute_sha256() charm_bundle = directory.as_bundle() self.assertEquals(type(charm_bundle), CharmBundle) self.assertEquals(compute_file_hash(hashlib.sha256, charm_bundle.path), sha256)
def test_compute_file_hash(self): for type in (hashlib.sha256, hashlib.md5): filename = self.makeFile("content") digest = compute_file_hash(type, filename) self.assertEquals(digest, type("content").hexdigest())
def compute_sha256(self): """Return the SHA256 digest for this charm bundle. The digest is extracted out of the final bundle file itself. """ return compute_file_hash(hashlib.sha256, self.path)
def get_charm_sha256(self): return compute_file_hash(hashlib.sha256, self.filename)