def test_init_empty(self): res = backend.Resource('name', {}, 'od') self.assertEqual(res.name, 'name') self.assertEqual(res.filename, '') self.assertEqual(res.destination, 'od/') self.assertEqual(res.hash, '') self.assertEqual(res.hash_type, '')
def test_verify_invalid(self): res = backend.Resource('name', { 'file': 'res-defaults.yaml', 'hash': 'deadbeef', 'hash_type': 'md5', }, self.test_data) assert not res.verify()
def test_verify_missing(self): res = backend.Resource( 'name', { 'file': 'nonce', 'hash': '4f08575d804517cea2265a7d43022771', 'hash_type': 'md5', }, self.test_data) assert not res.verify()
def test_verify(self): res = backend.Resource( 'name', { 'file': 'res-defaults.yaml', 'hash': '4f08575d804517cea2265a7d43022771', 'hash_type': 'md5', }, self.test_data) assert res.verify()
def test_install_invalid(self): res = backend.Resource('name', { 'file': 'res-defaults.yaml', 'hash': 'deadbeef', 'hash_type': 'md5', }, self.test_data) tmpdir = mkdtemp() try: assert not res.install(tmpdir) self.assertEqual(os.listdir(tmpdir), []) finally: shutil.rmtree(tmpdir)
def test_init(self): res = backend.Resource('name', { 'file': 'path/fn', 'hash': 'hash', 'hash_type': 'hash_type', }, 'od') self.assertEqual(res.name, 'name') self.assertEqual(res.source, 'path/fn') self.assertEqual(res.filename, 'fn') self.assertEqual(res.destination, 'od/fn') self.assertEqual(res.hash, 'hash') self.assertEqual(res.hash_type, 'hash_type') self.assertEqual(res.output_dir, 'od')
def test_install_file(self): res = backend.Resource( 'name', { 'file': 'res-defaults.yaml', 'hash': '4f08575d804517cea2265a7d43022771', 'hash_type': 'md5', }, self.test_data) tmpdir = mkdtemp() try: assert res.install(tmpdir) self.assertEqual(os.listdir(tmpdir), ['res-defaults.yaml']) finally: shutil.rmtree(tmpdir)
def test_install_zip_skip_top_level(self): res = backend.Resource( 'name', { 'file': 'test.zip', 'hash': '5c7b6a3c4bf38ac9d2f0ab0088fff1a9', 'hash_type': 'md5', }, self.test_data) tmpdir = mkdtemp() try: assert res.install(tmpdir, skip_top_level=True) self.assertItemsEqual(os.listdir(tmpdir), ['foo', 'bar']) self.assertItemsEqual(os.listdir(os.path.join(tmpdir, 'bar')), ['qux']) finally: shutil.rmtree(tmpdir)
def test_install_tgz(self): res = backend.Resource( 'name', { 'file': 'test.tgz', 'hash': '347153cce7f15a6d3e47d34fbccb6afa', 'hash_type': 'md5', }, self.test_data) tmpdir = mkdtemp() try: assert res.install(tmpdir) self.assertItemsEqual(os.listdir(tmpdir), ['toplevel']) self.assertItemsEqual(os.listdir(os.path.join(tmpdir, 'toplevel')), ['foo', 'bar']) finally: shutil.rmtree(tmpdir)
def test_init_explicit_destination(self): res = backend.Resource('name', { 'file': 'fn', 'destination': 'dst' }, 'od') self.assertEqual(res.destination, 'dst')
def test_fetch(self): res = backend.Resource('name', {'file': 'fn'}, 'od') res.fetch() res.fetch('mirror')