Repository: vmware/tern
Pull request #233 (2019-04-16 22:36:13)

Renaming license to pkg_license in all classes and tests
This PR adds renaming of license to pkg_license in package class properties and corresponding tests. After renaming, I have verified that all tests in tests.test_class_package.py passed.

Resolves issue #213

Signed-off-by: Manisha Tripathy <tripathym@vmware.com>

nishakm: Also, in your commit message body, if you can add something from the actual issue to indicate what the fix does, that would be great.
nishakm: Haha! I didn't have a test for that particular feature in the Image class yet, that's why the tests were passing. So many thanks for catching it!
nishakm: @ManishaTripathy can you combine your 3 commits into one? Also, can you add all of my suggested edits to your commit message?

A note: if you are having a tough time updating or refactoring your commits, I would highly suggest following the git workflow here: https://github.com/nishakm/puns. Feel free to practice on it before you update your PR. You can always ask me questions on specific git operations. Thanks!
ManishaTripathy: Thanks @nishakm for the git workflow link, i have updated the PR with the suggested changes, please review!
nishakm: @ManishaTripathy Thank you!! One small nit: Your commit message has two signed-off-by's can you remove the first one?
ManishaTripathy: @nishakm please review the updated PR 
nishakm: PR looks good all around! Much appreciate you sticking with this. I hope you can submit another!

Patch:
diff --git a/tern/classes/package.py b/tern/classes/package.py
index f59a024..64b2728 100644
--- a/tern/classes/package.py
+++ b/tern/classes/package.py
@@ -12,7 +12,7 @@ class Package:
     attributes:
         name: package name
         version: package version
-        license: package license
+        pkg_license: package license
         src_url: package source url
         origins: a list of NoticeOrigin objects
 
@@ -23,7 +23,7 @@ class Package:
     def __init__(self, name):
         self.__name = name
         self.__version = ''
-        self.__license = ''
+        self.__pkg_license = ''
         self.__src_url = ''
         self.__origins = Origins()
 
@@ -40,12 +40,12 @@ class Package:
         self.__version = version
 
     @property
-    def license(self):
-        return self.__license
+    def pkg_license(self):
+        return self.__pkg_license
 
-    @license.setter
-    def license(self, license):  # pylint: disable=redefined-builtin
-        self.__license = license
+    @pkg_license.setter
+    def pkg_license(self, pkg_license):  
+        self.__pkg_license =pkg_license
 
     @property
     def src_url(self):
@@ -86,7 +86,7 @@ class Package:
         '''The package dict looks like this:
             name: <name>
             version: <version>
-            license: <license string>
+            pkg_license: <packagelicense string>
             src_url: <source url>
         the way to use this method is to instantiate the class with the
         name and then give it a package dictionary to fill in the rest
@@ -95,7 +95,7 @@ class Package:
         success = True
         if self.name == package_dict['name']:
             self.version = package_dict['version']
-            self.license = package_dict['license']
+            self.pkg_license = package_dict['pkg_license']
             self.src_url = package_dict['src_url']
         else:
             success = False


Test patch:
diff --git a/tests/test_class_package.py b/tests/test_class_package.py
index 74af563..d7228af 100644
--- a/tests/test_class_package.py
+++ b/tests/test_class_package.py
@@ -15,7 +15,7 @@ class TestClassPackage(unittest.TestCase):
     def setUp(self):
         self.p1 = Package('p1')
         self.p1.version = '1.0'
-        self.p1.license = 'Apache 2.0'
+        self.p1.pkg_license = 'Apache 2.0'
         self.p1.src_url = 'github.com'
 
         self.p2 = Package('p2')
@@ -28,28 +28,28 @@ class TestClassPackage(unittest.TestCase):
         self.assertEqual(self.p2.name, 'p2')
         self.assertFalse(self.p2.version)
         self.assertFalse(self.p2.src_url)
-        self.assertFalse(self.p2.license)
+        self.assertFalse(self.p2.pkg_license)
 
     def testSetters(self):
         self.assertRaises(AttributeError, setattr, self.p2, 'name', 'y')
         self.p2.version = '2.0'
         self.assertEqual(self.p2.version, '2.0')
-        self.p2.license = 'Apache 2.0'
-        self.assertEqual(self.p2.license, 'Apache 2.0')
+        self.p2.pkg_license = 'Apache 2.0'
+        self.assertEqual(self.p2.pkg_license, 'Apache 2.0')
         self.p2.src_url = 'github.com'
         self.assertEqual(self.p2.src_url, 'github.com')
 
     def testGetters(self):
         self.assertEqual(self.p1.name, 'p1')
         self.assertEqual(self.p1.version, '1.0')
-        self.assertEqual(self.p1.license, 'Apache 2.0')
+        self.assertEqual(self.p1.pkg_license, 'Apache 2.0')
         self.assertEqual(self.p1.src_url, 'github.com')
 
     def testToDict(self):
         a_dict = self.p1.to_dict()
         self.assertEqual(a_dict['name'], 'p1')
         self.assertEqual(a_dict['version'], '1.0')
-        self.assertEqual(a_dict['license'], 'Apache 2.0')
+        self.assertEqual(a_dict['pkg_license'], 'Apache 2.0')
         self.assertEqual(a_dict['src_url'], 'github.com')
         self.assertFalse(a_dict['origins'])
 
@@ -67,10 +67,10 @@ class TestClassPackage(unittest.TestCase):
 
     def testIsEqual(self):
         p = Package('p2')
-        p.license = 'TestLicense'
+        p.pkg_license = 'Testpkg_license'
         p.version = '1.0'
         p.src_url = 'TestUrl'
-        self.p2.license = 'TestLicense'
+        self.p2.pkg_license = 'Testpkg_license'
         self.p2.version = '2.0'
         self.p2.src_url = 'TestUrl'
         self.assertFalse(self.p2.is_equal(p))
diff --git a/tests/test_class_template.py b/tests/test_class_template.py
index 2d23c26..080dba9 100644
--- a/tests/test_class_template.py
+++ b/tests/test_class_template.py
@@ -25,7 +25,7 @@ class TestClassTemplate(unittest.TestCase):
         mapping = self.template1.package()
         self.assertEqual(mapping['name'], 'package.name')
         self.assertEqual(mapping['version'], 'package.version')
-        self.assertEqual(mapping['license'], 'package.license')
+        self.assertEqual(mapping['pkg_license'], 'package.pkg_license')
 
     def testImageLayer(self):
         mapping = self.template1.image_layer()
@@ -35,7 +35,7 @@ class TestClassTemplate(unittest.TestCase):
 
     def testImage(self):
         mapping = self.template1.image()
-        self.assertEqual(mapping['id'], 'image.id')
+        self.assertEqual(mapping['image_id'], 'image.id')
         self.assertEqual(mapping['layers'], 'image.layers')
 
     def testNotice(self):
diff --git a/tests/test_fixtures.py b/tests/test_fixtures.py
index e25f54f..2c2627c 100644
--- a/tests/test_fixtures.py
+++ b/tests/test_fixtures.py
@@ -28,7 +28,7 @@ class TestTemplate1(Template):
     def package(self):
         return {'name': 'package.name',
                 'version': 'package.version',
-                'license': 'package.license'}
+                'pkg_license': 'package.license'}
 
     def image_layer(self):
         return {'diff_id': 'layer.diff',
@@ -45,7 +45,7 @@ class TestTemplate2(Template):
     def package(self):
         mapping = {'name': 'package.name',
                    'version': 'package.version',
-                   'license': 'package.license',
+                   'pkg_license': 'package.license',
                    'src_url': 'package.url'}
         # we update the mapping with another defined mapping
         mapping.update(self.origins())