Example #1
0
class TestSettingTargetValue(unittest.TestCase):
    def setUp(self):
        self.info = LicenseInfo("3PPLICENSE", OpenSourceNoticeConfigMock())

    def test_valid_value_with_single_target(self):
        self.info.set_value("TARGET", "kit")
        self.assertEqual(set(["kit"]), self.info.get_target_set())

    def test_valid_value_with_multiple_targets(self):
        self.info.set_value("TARGET", "kit bi:bcm45")
        self.assertEqual(set(["kit", "bi:bcm45"]), self.info.get_target_set())

    def test_no_value(self):
        self.assertEqual(None, self.info.get_target_set())

    def test_invalid_value_raises_error(self):
        self.assertRaisesRegexp(
            ParserError, "invalid TARGET value",
            self.info.set_value, "TARGET", "kit2")

    def test_setting_second_time_raises_error(self):
        self.info.set_value("TARGET", "kit")
        self.assertRaisesRegexp(
            ParserError, "cannot be added a second time",
            self.info.set_value, "TARGET", "kit")

    def test_setting_with_index_raises_error(self):
        self.assertRaisesRegexp(
            ParserError, "invalid indexed attribute",
            self.info.set_indexed_value, "TARGET", "1", "kit")
Example #2
0
class TestSettingOriginValue(unittest.TestCase):
    def setUp(self):
        self.info = LicenseInfo("3PPLICENSE", OpenSourceNoticeConfigMock())

    def test_valid_non_url_value(self):
        self.info.set_value("ORIGIN", "FromSupplier")
        self.assertEqual("FromSupplier", self.info.get_origin())

    def test_valid_url_value(self):
        self.info.set_value("ORIGIN", "http://comp.com/download")
        self.assertEqual("http://comp.com/download", self.info.get_origin())

    def test_invalid_value(self):
        self.assertRaisesRegexp(
            ParserError, "invalid ORIGIN value",
            self.info.set_value, "ORIGIN", "origin-invalid")

    def test_no_value(self):
        self.assertEqual(None, self.info.get_origin())

    def test_setting_second_time_raises_error(self):
        self.info.set_value("ORIGIN", "http://comp.com/download")
        self.assertRaisesRegexp(
            ParserError, "cannot be added a second time",
            self.info.set_value, "ORIGIN", "http://comp.com/download2")

    def test_setting_with_index_raises_error(self):
        self.assertRaisesRegexp(
            ParserError, "invalid indexed attribute",
            self.info.set_indexed_value, "ORIGIN", "1", "FromSupplier")
Example #3
0
class TestSettingLicenseValue(unittest.TestCase):
    def setUp(self):
        self.info = LicenseInfo("3PPLICENSE", OpenSourceNoticeConfigMock())

    def test_valid_value(self):
        self.info.set_value("LICENSE", "BSDish")
        self.assertEqual("BSDish", self.info.get_license())

    def test_invalid_value(self):
        self.assertRaisesRegexp(
            ParserError, "invalid LICENSE value",
            self.info.set_value, "LICENSE", "foolicense")

    def test_no_value(self):
        self.assertEqual(None, self.info.get_license())

    def test_setting_second_time_raises_error(self):
        self.info.set_value("LICENSE", "BSDish")
        self.assertRaisesRegexp(
            ParserError, "cannot be added a second time",
            self.info.set_value, "LICENSE", "Custom")

    def test_setting_with_index_raises_error(self):
        self.assertRaisesRegexp(
            ParserError, "invalid indexed attribute",
            self.info.set_indexed_value, "LICENSE", "1", "BSDish")
Example #4
0
class TestSettingUsageValue(unittest.TestCase):
    def setUp(self):
        self.info = LicenseInfo("3PPLICENSE", OpenSourceNoticeConfigMock())

    def test_valid_value(self):
        self.info.set_value("USAGE", "InternalUseOnly")
        self.assertEqual("InternalUseOnly", self.info.get_usage())

    def test_invalid_value(self):
        self.assertRaisesRegexp(
            ParserError, "invalid USAGE value",
            self.info.set_value, "USAGE", "usage-foobar")

    def test_no_value(self):
        self.assertEqual("", self.info.get_usage())

    def test_setting_second_time_raises_error(self):
        self.info.set_value("USAGE", "Restricted")
        self.assertRaisesRegexp(
            ParserError, "cannot be added a second time",
            self.info.set_value, "USAGE", "InternalUseOnly")

    def test_setting_with_index_raises_error(self):
        self.assertRaisesRegexp(
            ParserError, "invalid indexed attribute",
            self.info.set_indexed_value, "USAGE", "1", "InternalUseOnly")
Example #5
0
 def test_invalid_license_file_name_raises_error(self):
     file_name_tests = {"3PPLICENSE": False,
                        "3PPLICENSE.foo": False,
                        "KTVLICENSE": False,
                        "KTVLICENSE.foo": False,
                        "OTHERNAME": True}
     for name in file_name_tests:
         try:
             LicenseInfo(name, OpenSourceNoticeConfigMock())
             self.assertFalse(file_name_tests[name])
         except ParserError as ex:
             self.assertRegexpMatches(
                 ex.__str__(), "invalid license file name")
             self.assertTrue(file_name_tests[name])
Example #6
0
class TestSettingEmbeddedNameValue(unittest.TestCase):
    def setUp(self):
        self.info = LicenseInfo("3PPLICENSE", OpenSourceNoticeConfigMock())

    def test_valid_value(self):
        self.info.set_value("EMBEDDED_NAME", "foobar")
        self.assertIn("foobar", self.info.get_embedded_names().values())

    def test_no_value(self):
        self.assertEqual([], self.info.get_embedded_names().values())

    def test_setting_index_second_time_raises_error(self):
        self.info.set_indexed_value("EMBEDDED_NAME", "1", "foobar")
        self.assertRaisesRegexp(
            ParserError, "cannot be added a second time",
            self.info.set_indexed_value, "EMBEDDED_NAME", "1", "foobar")
Example #7
0
class TestSettingVersionValue(unittest.TestCase):
    def setUp(self):
        self.info = LicenseInfo("3PPLICENSE", OpenSourceNoticeConfigMock())

    def test_valid_value(self):
        self.info.set_value("VERSION", "1.2")
        self.assertEqual("1.2", self.info.get_version())

    def test_no_value(self):
        self.assertEqual("", self.info.get_version())

    def test_setting_second_time_raises_error(self):
        self.info.set_value("VERSION", "1.2")
        self.assertRaisesRegexp(
            ParserError, "cannot be added a second time",
            self.info.set_value, "VERSION", "1.3")

    def test_setting_with_index_raises_error(self):
        self.assertRaisesRegexp(
            ParserError, "invalid indexed attribute",
            self.info.set_indexed_value, "VERSION", "1", "1.2")
Example #8
0
 def setUp(self):
     self.info = LicenseInfo("3PPLICENSE", OpenSourceNoticeConfigMock())
Example #9
0
class TestSettingFileNameValue(unittest.TestCase):
    def setUp(self):
        self.info = LicenseInfo("3PPLICENSE", OpenSourceNoticeConfigMock())

    def test_single_filename(self):
        self.info.set_value("FILENAME", "foo.tgz")
        self.assertEqual({"": "foo.tgz"}, self.info.get_file_names())

    def test_indexed_filenames(self):
        self.info.set_indexed_value("FILENAME", "1", "foo.tgz")
        self.info.set_indexed_value("FILENAME", "2", "bar.tgz")
        self.assertEqual({"1": "foo.tgz", "2": "bar.tgz"},
                         self.info.get_file_names())

    def test_no_value(self):
        self.assertEqual({}, self.info.get_file_names())

    def test_setting_second_time_raises_error(self):
        self.info.set_value("FILENAME", "foo.tgz")
        self.assertRaisesRegexp(
            ParserError, "cannot be added a second time",
            self.info.set_value, "FILENAME", "foo.tgz")

    def test_setting_index_second_time_raises_error(self):
        self.info.set_indexed_value(
            "FILENAME", "1", "http://comp.com/download")
        self.assertRaisesRegexp(
            ParserError, "cannot be added a second time",
            self.info.set_indexed_value,
            "FILENAME", "1", "http://comp.com/download2")
Example #10
0
class TestSettingSha1Value(unittest.TestCase):
    def setUp(self):
        self.info = LicenseInfo("3PPLICENSE", OpenSourceNoticeConfigMock())

    def test_single_sha1(self):
        self.info.set_value("SHA1", "ea45fc00.....")
        self.assertEqual({"": "ea45fc00....."}, self.info.get_sha1_checksums())

    def test_indexed_sha1s(self):
        self.info.set_indexed_value("SHA1", "1", "ea45fc00.....")
        self.info.set_indexed_value("SHA1", "2", "ea45fc00.....")
        self.assertEqual({"1": "ea45fc00.....", "2": "ea45fc00....."},
                         self.info.get_sha1_checksums())

    def test_no_value(self):
        self.assertEqual({}, self.info.get_sha1_checksums())

    def test_setting_second_time_raises_error(self):
        self.info.set_value("SHA1", "ea45fc00.....")
        self.assertRaisesRegexp(
            ParserError, "cannot be added a second time",
            self.info.set_value, "SHA1", "ea45fc00.....")

    def test_setting_index_second_time_raises_error(self):
        self.info.set_indexed_value("SHA1", "1", "ea45fc00.....")
        self.assertRaisesRegexp(
            ParserError, "cannot be added a second time",
            self.info.set_indexed_value, "SHA1", "1", "ea45fc00.....")