Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def testIsEqual(self):
p = Package('p2')
p.pkg_license = 'Testpkg_license'
p.version = '1.0'
p.proj_url = 'TestUrl'
p.checksum = 'abcdef'
self.p2.pkg_license = 'Testpkg_license'
self.p2.version = '2.0'
self.p2.proj_url = 'TestUrl'
self.p2.checksum = 'abcdef'
self.assertFalse(self.p2.is_equal(p))
p.version = '2.0'
self.assertTrue(self.p2.is_equal(p))
def testToDict(self):
p1 = Package('x')
self.layer.add_package(p1)
a_dict = self.layer.to_dict()
self.assertEqual(a_dict['diff_id'], '123abc')
self.assertEqual(len(a_dict['packages']), 1)
self.assertEqual(a_dict['packages'][0]['name'], 'x')
self.assertEqual(a_dict['tar_file'], 'path/to/tar')
def testGetPackageNames(self):
p1 = Package('x')
self.layer.add_package(p1)
pkgs = self.layer.get_package_names()
self.assertEqual(pkgs[0], 'x')
def testToDictTemplate(self):
template1 = TestTemplate1()
template2 = TestTemplate2()
p1 = Package('x')
self.layer.add_package(p1)
dict1 = self.layer.to_dict(template1)
dict2 = self.layer.to_dict(template2)
self.assertEqual(len(dict1.keys()), 3)
self.assertEqual(dict1['layer.diff'], '123abc')
self.assertEqual(dict1['layer.tarfile'], 'path/to/tar')
self.assertEqual(len(dict1['layer.packages']), 1)
self.assertEqual(len(dict2.keys()), 4)
self.assertFalse(dict2['notes'])
self.assertFalse(dict2['layer.packages'][0]['notes'])
def load_image(self):
l1 = ImageLayer('123abc', 'path/to/tar')
self.name = 'testimage'
self.tag = 'testtag'
l1.add_package(Package('p1'))
l1.add_package(Package('p2'))
self._layers.append(l1)
def testFill(self):
p_dict = {'name': 'p1',
'version': '1.0',
'pkg_license': 'Apache 2.0',
'checksum': 'abcxyz'}
p = Package('p1')
p.fill(p_dict)
self.assertEqual(p.name, 'p1')
self.assertEqual(p.version, '1.0')
self.assertEqual(p.pkg_license, 'Apache 2.0')
self.assertEqual(p.checksum, 'abcxyz')
self.assertFalse(p.copyright)
self.assertFalse(p.proj_url)
self.assertEqual(len(p.origins.origins), 1)
self.assertEqual(p.origins.origins[0].origin_str, 'p1')
self.assertEqual(len(p.origins.origins[0].notices), 3)
self.assertEqual(p.origins.origins[0].notices[0].message,
"No metadata for key: copyright")
self.assertEqual(p.origins.origins[0].notices[0].level, 'warning')
self.assertEqual(p.origins.origins[0].notices[1].message,
"No metadata for key: proj_url")
self.assertEqual(p.origins.origins[0].notices[2].message,
def testAddPackage(self):
err = "Object type String, should be Package"
p1 = Package('x')
self.layer.add_package(p1)
self.assertEqual(len(self.layer.packages), 1)
with self.assertRaises(TypeError, msg=err):
self.layer.add_package("not_a_package")
def testRemovePackage(self):
p1 = Package('x')
p2 = Package('y')
self.layer.add_package(p1)
self.layer.add_package(p2)
self.assertTrue(self.layer.remove_package('y'))
self.assertFalse(self.layer.remove_package('y'))
all_pkgs = []
for pkg_name in pkg_list:
pkg_invoke = command_lib.check_for_unique_package(
pkg_listing, pkg_name)
deps, deps_msg = get_package_dependencies(
pkg_invoke, pkg_name, shell)
if deps_msg:
logger.warning(deps_msg)
image_layer.origins.add_notice_to_origins(
origin_layer, Notice(deps_msg, 'error'))
all_pkgs.append(pkg_name)
all_pkgs.extend(deps)
unique_pkgs = list(set(all_pkgs))
# get package metadata for each package name
for pkg_name in unique_pkgs:
pkg = Package(pkg_name)
fill_package_metadata(pkg, pkg_invoke, shell)
image_layer.add_package(pkg)
def load_from_cache(layer, redo=False):
'''Given a layer object, check against cache to see if that layer id exists
if yes then get the package list and load it in the layer and return true.
If it doesn't exist return false. Default operation is to not redo the
cache. Add notices to the layer's origins matching the origin_str'''
loaded = False
if not layer.packages and not redo:
# there are no packages in this layer and we are not repopulating the
# cache, try to get it from the cache
raw_pkg_list = cache.get_packages(layer.fs_hash)
if raw_pkg_list:
logger.debug('Loaded from cache: layer \"%s\"', layer.fs_hash[:10])
for pkg_dict in raw_pkg_list:
pkg = Package(pkg_dict['name'])
pkg.fill(pkg_dict)
layer.add_package(pkg)
load_notices_from_cache(layer)
loaded = True
return loaded