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")
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")
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")
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.....")
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")
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")
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")
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")