|
51 | 51 | SONAR_SCANNER_ARCH, |
52 | 52 | SONAR_SCANNER_OS, |
53 | 53 | ) |
54 | | -from pysonar_scanner.exceptions import MissingKeyException |
55 | 54 | from pysonar_scanner.utils import Arch, Os |
| 55 | +from pysonar_scanner.configuration.configuration_loader import ConfigurationLoader, SONAR_PROJECT_BASE_DIR |
| 56 | +from pysonar_scanner.exceptions import MissingPropertyException |
56 | 57 |
|
57 | 58 |
|
58 | 59 | # Mock utils.get_os and utils.get_arch at the module level |
@@ -116,7 +117,7 @@ def test_get_token(self, mock_get_os, mock_get_arch): |
116 | 117 | with self.subTest("Token is present"): |
117 | 118 | self.assertEqual(configuration_loader.get_token({SONAR_TOKEN: "myToken"}), "myToken") |
118 | 119 |
|
119 | | - with self.subTest("Token is absent"), self.assertRaises(MissingKeyException): |
| 120 | + with self.subTest("Token is absent"), self.assertRaises(MissingPropertyException): |
120 | 121 | configuration_loader.get_token({}) |
121 | 122 |
|
122 | 123 | @patch("sys.argv", ["myscript.py", "--token", "myToken", "--sonar-project-key", "myProjectKey"]) |
@@ -428,3 +429,21 @@ def test_unknown_args_with_D_prefix(self, mock_get_os, mock_get_arch): |
428 | 429 | self.assertEqual(configuration["another.unknown.property"], "anotherValue") |
429 | 430 | self.assertEqual(configuration[SONAR_TOKEN], "myToken") |
430 | 431 | self.assertEqual(configuration[SONAR_PROJECT_KEY], "myProjectKey") |
| 432 | + |
| 433 | + def test_check_configuration(self, mock_get_os, mock_get_arch): |
| 434 | + with self.subTest("Both values present"): |
| 435 | + ConfigurationLoader.check_configuration({SONAR_TOKEN: "", SONAR_PROJECT_KEY: ""}) |
| 436 | + |
| 437 | + with self.subTest("missing keys"): |
| 438 | + with self.assertRaises(MissingPropertyException) as cm: |
| 439 | + ConfigurationLoader.check_configuration({SONAR_PROJECT_KEY: "myKey"}) |
| 440 | + self.assertIn(SONAR_TOKEN, str(cm.exception)) |
| 441 | + |
| 442 | + with self.assertRaises(MissingPropertyException) as cm: |
| 443 | + ConfigurationLoader.check_configuration({SONAR_TOKEN: "myToken"}) |
| 444 | + self.assertIn(SONAR_PROJECT_KEY, str(cm.exception)) |
| 445 | + |
| 446 | + with self.assertRaises(MissingPropertyException) as cm: |
| 447 | + ConfigurationLoader.check_configuration({}) |
| 448 | + self.assertIn(SONAR_PROJECT_KEY, str(cm.exception)) |
| 449 | + self.assertIn(SONAR_TOKEN, str(cm.exception)) |
0 commit comments