def test_competing_revisions(self): zf = zipfile.ZipFile(self.filename, "a") zf.writestr("revision", "999") data = yaml.load(zf.read("metadata.yaml")) data["revision"] = 303 zf.writestr("metadata.yaml", yaml.dump(data)) zf.close() charm = CharmBundle(self.filename) self.assertEquals(charm.get_revision(), 999)
def test_charm_download(self): """Downloading a charm should store the charm locally.""" yield self.unit_manager.download_charm(self.charm_state) checksum = self.charm.get_sha256() charm_id = local_charm_id(self.charm) charm_key = under.quote("%s:%s" % (charm_id, checksum)) charm_path = os.path.join(self.unit_manager.charms_directory, charm_key) self.assertTrue(os.path.exists(charm_path)) bundle = CharmBundle(charm_path) self.assertEquals( bundle.get_revision(), self.charm.get_revision()) self.assertEquals(bundle.get_sha256(), checksum) self.assertIn( "Downloading charm %s" % charm_id, self.output.getvalue())
def test_revision_in_metadata(self): filename = self.makeFile() zf_dst = zipfile.ZipFile(filename, "w") zf_src = zipfile.ZipFile(self.filename, "r") for name in zf_src.namelist(): if name == "revision": continue content = zf_src.read(name) if name == "metadata.yaml": data = yaml.load(content) data["revision"] = 303 content = yaml.dump(data) zf_dst.writestr(name, content) zf_src.close() zf_dst.close() charm = CharmBundle(filename) self.assertEquals(charm.get_revision(), 303)
def test_charm_download(self): """ Downloading a charm should store the charm locally. """ yield self.agent.startService() yield self.agent.download_charm(self.charm_state) checksum = self.charm.get_sha256() charm_id = local_charm_id(self.charm) charm_key = under.quote("%s:%s" % (charm_id, checksum)) charm_path = os.path.join(self.agent.charms_directory, charm_key) self.assertTrue(os.path.exists(charm_path)) bundle = CharmBundle(charm_path) self.assertEquals(bundle.get_revision(), self.charm.get_revision()) self.assertEquals(bundle.get_sha256(), checksum) self.assertIn("Downloading charm %s" % charm_id, self.output.getvalue())
def test_charm_download_file(self): """Downloading a charm should store the charm locally. """ charm, charm_state = yield self.publish_charm() charm_directory = self.makeDir() # Download the charm yield download_charm(self.client, charm_state.id, charm_directory) # Verify the downloaded copy checksum = charm.get_sha256() charm_id = local_charm_id(charm) charm_key = under.quote("%s:%s" % (charm_id, checksum)) charm_path = os.path.join(charm_directory, charm_key) self.assertTrue(os.path.exists(charm_path)) bundle = CharmBundle(charm_path) self.assertEquals(bundle.get_revision(), charm.get_revision()) self.assertEqual(checksum, bundle.get_sha256())
def test_charm_download_file(self): """Downloading a charm should store the charm locally. """ charm, charm_state = yield self.publish_charm() charm_directory = self.makeDir() # Download the charm yield download_charm( self.client, charm_state.id, charm_directory) # Verify the downloaded copy checksum = charm.get_sha256() charm_id = local_charm_id(charm) charm_key = under.quote("%s:%s" % (charm_id, checksum)) charm_path = os.path.join(charm_directory, charm_key) self.assertTrue(os.path.exists(charm_path)) bundle = CharmBundle(charm_path) self.assertEquals(bundle.get_revision(), charm.get_revision()) self.assertEqual(checksum, bundle.get_sha256())