diff --git a/sonar/projects.py b/sonar/projects.py index 7db1827a..e5c41255 100644 --- a/sonar/projects.py +++ b/sonar/projects.py @@ -675,7 +675,7 @@ def export_zip(self, asynchronous: bool = False, timeout: int = 180) -> tuple[st resp = self.post("project_dump/export", params={"key": self.key}) except exceptions.ObjectNotFound as e: Project.CACHE.pop(self) - return f"FAILED/{e.message}", None + raise except exceptions.SonarException as e: return f"FAILED/{e.message}", None except RequestException as e: @@ -710,8 +710,10 @@ def import_zip(self, asynchronous: bool = False, timeout: int = 180) -> str: try: resp = self.post("project_dump/import", params={"key": self.key}) except exceptions.ObjectNotFound as e: + if "Dump file does not exist" in e.message: + return f"FAILED/{tasks.ZIP_MISSING}" Project.CACHE.pop(self) - return f"FAILED/{e.message}" + raise except exceptions.SonarException as e: if "Dump file does not exist" in e.message: return f"FAILED/{tasks.ZIP_MISSING}" diff --git a/test/files/audit-config.json b/test/files/audit-config.json index a744ff38..fa014bad 100644 --- a/test/files/audit-config.json +++ b/test/files/audit-config.json @@ -99,11 +99,11 @@ "main": { "isMain": true, "projects": { - "project1": "main", - "project2": "main", - "project3": "main", - "project4": "main", - "proyecto5": "main" + "test:project1": "main", + "test:project2": "main", + "test:project3": "main", + "test:project4": "main", + "test:proyecto5": "main" } } }, @@ -248,7 +248,6 @@ "sonar.cpd.cross_project": false, "sonar.dbcleaner.auditHousekeeping": "Monthly", "sonar.dbcleaner.branchesToKeepWhenInactive": [ - "comma,branch", "develop", "main", "master", @@ -759,7 +758,6 @@ "BANKING-INVESTMENT-EQUITY": "-DEFAULT_BRANCH-", "BANKING-INVESTMENT-MERGER": "-DEFAULT_BRANCH-", "BANKING-PORTAL": [ - "comma,branch", "main", "release-3.2" ] @@ -960,9 +958,6 @@ }, "BANKING-PORTAL": { "branches": { - "comma,branch": { - "keepWhenInactive": true - }, "main": { "isMain": true }, @@ -1978,10 +1973,6 @@ }, "okorach_sonar-tools": { "branches": { - "comma,branch": { - "keepWhenInactive": true, - "newCodePeriod": "REFERENCE_BRANCH = develop" - }, "develop": { "keepWhenInactive": true, "newCodePeriod": "REFERENCE_BRANCH = master" @@ -2018,7 +2009,7 @@ ], "visibility": "private" }, - "project1": { + "test:project1": { "branches": { "develop": { "keepWhenInactive": true @@ -2048,7 +2039,7 @@ "sonar.coverage.jacoco.xmlReportPaths": "**/*jacoco*.xml", "visibility": "private" }, - "project2": { + "test:project2": { "branches": { "develop": { "keepWhenInactive": true @@ -2074,7 +2065,7 @@ }, "visibility": "private" }, - "project3": { + "test:project3": { "branches": { "develop": { "keepWhenInactive": true @@ -2100,7 +2091,7 @@ }, "visibility": "private" }, - "project4": { + "test:project4": { "branches": { "develop": { "keepWhenInactive": true @@ -2124,7 +2115,7 @@ }, "visibility": "public" }, - "proyecto5": { + "test:proyecto5": { "branches": { "develop": { "keepWhenInactive": true diff --git a/test/files/config-for-audit.json b/test/files/config-for-audit.json index 159a2a3f..3c8fa0ce 100644 --- a/test/files/config-for-audit.json +++ b/test/files/config-for-audit.json @@ -55,7 +55,6 @@ "sonar.dbcleaner.hoursBeforeKeepingOnlyOneSnapshotByDay": "24", "sonar.dbcleaner.daysBeforeDeletingInactiveBranchesAndPRs": "30", "sonar.dbcleaner.branchesToKeepWhenInactive": [ - "comma,branch", "develop", "main", "master", diff --git a/test/files/config.json b/test/files/config.json index d0432cf1..1c2e2b95 100644 --- a/test/files/config.json +++ b/test/files/config.json @@ -56,7 +56,6 @@ "sonar.dbcleaner.hoursBeforeKeepingOnlyOneSnapshotByDay": "24", "sonar.dbcleaner.daysBeforeDeletingInactiveBranchesAndPRs": "30", "sonar.dbcleaner.branchesToKeepWhenInactive": [ - "comma,branch", "develop", "main", "master", @@ -3437,9 +3436,6 @@ } }, "branches": { - "comma,branch": { - "keepWhenInactive": true - }, "release-3.2": { "keepWhenInactive": true }, @@ -4461,81 +4457,6 @@ } } }, - "non-existing": { - "name": "non-existing", - "visibility": "private", - "links": [ - { - "type": "yahoo", - "name": "yahoo", - "url": "https://yahoo.com" - }, - { - "type": "yahoo", - "name": "yahoo", - "url": "https://yahoo.com" - }, - { - "type": "yahoo", - "name": "yahoo", - "url": "https://yahoo.com" - }, - { - "type": "yahoo", - "name": "yahoo", - "url": "https://yahoo.com" - }, - { - "type": "yahoo", - "name": "yahoo", - "url": "https://yahoo.com" - }, - { - "type": "yahoo", - "name": "yahoo", - "url": "https://yahoo.com" - }, - { - "type": "yahoo", - "name": "yahoo", - "url": "https://yahoo.com" - }, - { - "type": "yahoo", - "name": "yahoo", - "url": "https://yahoo.com" - }, - { - "type": "yahoo", - "name": "yahoo", - "url": "https://yahoo.com" - }, - { - "type": "yahoo", - "name": "yahoo", - "url": "https://yahoo.com" - }, - { - "type": "yahoo", - "name": "yahoo", - "url": "https://yahoo.com" - } - ], - "permissions": { - "users": { - "admin": "admin" - }, - "groups": { - "developers": "codeviewer, user", - "project-admins": "admin, codeviewer, user", - "security-auditors": "codeviewer, issueadmin, securityhotspotadmin, user", - "sonar-administrators": "admin, codeviewer, user", - "sonar-users": "user", - "tech-leads": "codeviewer, issueadmin, user" - } - }, - "containsAiCode": true - }, "okorach-org_pr-demo_3a1857ec-cebc-49f2-96ac-9bbc99111469": { "name": "pr-demo", "visibility": "private", @@ -4687,35 +4608,6 @@ } ] }, - "okorach_sonar-tools-target": { - "name": "Sonar Tools Target", - "visibility": "private", - "permissions": { - "users": { - "admin": "admin, codeviewer, user", - "syncer": "codeviewer, issueadmin, securityhotspotadmin, user" - }, - "groups": { - "developers": "codeviewer, user", - "project-admins": "admin, codeviewer, user", - "security-auditors": "codeviewer, issueadmin, securityhotspotadmin, user", - "sonar-administrators": "admin, codeviewer, user", - "sonar-users": "user", - "tech-leads": "codeviewer, issueadmin, user" - } - }, - "branches": { - "master": { - "isMain": true - }, - "develop": { - "keepWhenInactive": true - }, - "comma,branch": { - "keepWhenInactive": true - } - } - }, "org.owasp.webgoat:webgoat": { "name": "WebGoat", "visibility": "private", @@ -4794,9 +4686,6 @@ } }, "branches": { - "comma,branch": { - "keepWhenInactive": true - }, "release-2.x": { "keepWhenInactive": true }, @@ -5449,7 +5338,6 @@ "BANKING-INVESTMENT-EQUITY": "-DEFAULT_BRANCH-", "BANKING-INVESTMENT-MERGER": "-DEFAULT_BRANCH-", "BANKING-PORTAL": [ - "comma,branch", "main", "release-3.2" ] diff --git a/test/projects-provisioning/scan.sh b/test/projects-provisioning/scan.sh index fd3da369..1808849a 100755 --- a/test/projects-provisioning/scan.sh +++ b/test/projects-provisioning/scan.sh @@ -8,20 +8,20 @@ cd "$DIR" url=${1:-$SONAR_HOST_URL} -projects="project1 project2 project3 project4 proyecto5" +projects="test:project1 test:project2 test:project3 test:project4 test:proyecto5" for p in $projects; do echo "Processing $p" sonar-scanner -Dsonar.projectKey=$p -Dsonar.host.url=$url -Dsonar.branch.name=develop -Dsonar.login=$SONAR_TOKEN -Dsonar.token=$SONAR_TOKEN done -branches="feature/new-feature some-branch comma,branch release-2.x release-3.x" +branches="feature/new-feature some-branch release-3.x" for b in $branches; do echo "Processing $p" sonar-scanner -Dsonar.projectKey=$p -Dsonar.host.url=$url -Dsonar.projectKey=project1 -Dsonar.branch.name=$b -Dsonar.login=$SONAR_TOKEN -Dsonar.token=$SONAR_TOKEN done projects=" \ -project1 project2 project3 project4 proyecto5 +test:project1 test:project2 test:project3 test:project4 test:proyecto5 INSURANCE-LIFE INSURANCE-HOME INSURANCE-PET INSURANCE-HEALTH BANKING-INVESTMENT-ACQUISITIONS BANKING-INVESTMENT-EQUITY BANKING-INVESTMENT-DILIGENCE BANKING-INVESTMENT-MERGER BANKING-RETAIL-ATM BANKING-RETAIL-WEB BANKING-RETAIL-CLERK diff --git a/test/test-sync.sh b/test/test-sync.sh index 52031060..d3ee8ebf 100755 --- a/test/test-sync.sh +++ b/test/test-sync.sh @@ -5,7 +5,7 @@ do curl -X POST -u "$SONAR_TOKEN:" "$SONAR_HOST_URL/api/projects/delete?project=$proj" opts=("-Dsonar.projectKey=$proj" "-Dsonar.projectName=$proj") conf/run_all.sh "${opts[@]}" "$@" - for branch in release-1.x release-2.x + for branch in release-2.x release-2.x do conf/run_all.sh "${opts[@]}" "$@" "-Dsonar.branch.name=$branch" done diff --git a/test/unit/credentials-latest.py b/test/unit/credentials-latest.py index 3e7e89a3..29713848 100644 --- a/test/unit/credentials-latest.py +++ b/test/unit/credentials-latest.py @@ -26,7 +26,7 @@ TARGET_TOKEN = getenv("SONAR_TOKEN_LATEST_ADMIN_USER") ISSUE_FP = "64e848c0-d5f4-402e-8c80-af6536041b5e" -ISSUE_FP_NBR_CHANGELOGS = 12 +ISSUE_FP_NBR_CHANGELOGS = 13 ISSUE_FP_CHANGELOG_DATE = datetime(2025, 10, 23) ISSUE_ACCEPTED = "e9eb08fe-bb53-443a-8a92-425589807c78" diff --git a/test/unit/credentials.py b/test/unit/credentials.py index 3e7e89a3..29713848 100644 --- a/test/unit/credentials.py +++ b/test/unit/credentials.py @@ -26,7 +26,7 @@ TARGET_TOKEN = getenv("SONAR_TOKEN_LATEST_ADMIN_USER") ISSUE_FP = "64e848c0-d5f4-402e-8c80-af6536041b5e" -ISSUE_FP_NBR_CHANGELOGS = 12 +ISSUE_FP_NBR_CHANGELOGS = 13 ISSUE_FP_CHANGELOG_DATE = datetime(2025, 10, 23) ISSUE_ACCEPTED = "e9eb08fe-bb53-443a-8a92-425589807c78" diff --git a/test/unit/test_config.py b/test/unit/test_config.py index 37538f04..52f6d221 100644 --- a/test/unit/test_config.py +++ b/test/unit/test_config.py @@ -30,7 +30,6 @@ from sonar import portfolios, applications, projects from sonar import logging import sonar.util.constants as c -from sonar import utilities as util import cli.options as opt from cli import config diff --git a/test/unit/test_housekeeper.py b/test/unit/test_housekeeper.py index 2fed0000..e1f2e9f7 100644 --- a/test/unit/test_housekeeper.py +++ b/test/unit/test_housekeeper.py @@ -47,7 +47,7 @@ def test_keep_branches_override(csv_file: Generator[str]) -> None: pytest.skip("No branches in Community") opts = f"{CMD} {tutil.SQS_OPTS} -P 730 -T 730 -R 730 -B 90 -f {csv_file}" assert tutil.run_cmd(housekeeper.main, opts) == errcodes.OK - nbr_br = tutil.csv_col_count_values(csv_file, "Audit Check", "BRANCH_LAST_ANALYSIS") + nbr_br = tutil.csv_col_count_values(csv_file, "Problem", "BRANCH_LAST_ANALYSIS") assert tutil.run_cmd(housekeeper.main, f"{opts} --keepWhenInactive 'dontkeepanything'") == errcodes.OK # With 'dontkeepanything' as branch regexp, more branches to delete should be found - assert tutil.csv_col_count_values(csv_file, "Audit Check", "BRANCH_LAST_ANALYSIS") > nbr_br + assert tutil.csv_col_count_values(csv_file, "Problem", "BRANCH_LAST_ANALYSIS") > nbr_br diff --git a/test/unit/test_portfolios.py b/test/unit/test_portfolios.py index 0dd4da91..55ba10b2 100644 --- a/test/unit/test_portfolios.py +++ b/test/unit/test_portfolios.py @@ -113,7 +113,7 @@ def test_add_project(get_test_portfolio: Generator[pf.Portfolio]) -> None: assert p.has_project(project.key) p.add_project_branches(project.key, [c.DEFAULT_BRANCH, "develop"]) - p.add_project_branches(project.key, ["comma,branch", "develop"]) + p.add_project_branches(project.key, ["release-3.x", "develop"]) assert p.recompute() diff --git a/test/unit/test_projects.py b/test/unit/test_projects.py index 49d06b42..65271859 100644 --- a/test/unit/test_projects.py +++ b/test/unit/test_projects.py @@ -140,7 +140,7 @@ def test_import_no_zip(get_test_project: Generator[projects.Project]) -> None: assert get_test_project.import_zip(asynchronous=False) == "FAILED/ZIP_MISSING" get_test_project.key = "non-existing" res = get_test_project.import_zip(asynchronous=False) - assert res.startsWith("FAILED/") and "not found" in res + assert res.startswith("FAILED/ZIP_MISSING") def test_monorepo() -> None: @@ -248,8 +248,10 @@ def test_import_wrong_key(get_test_project: Generator[projects.Project]) -> None proj = get_test_project proj.key = tutil.NON_EXISTING_KEY if tutil.SQ.edition() in (c.EE, c.DCE): - assert proj.import_zip(asynchronous=True) == "FAILED/PROJECT_NOT_FOUND" - assert proj.import_zip(asynchronous=False) == "FAILED/PROJECT_NOT_FOUND" + with pytest.raises(exceptions.ObjectNotFound): + proj.import_zip(asynchronous=True) + with pytest.raises(exceptions.ObjectNotFound): + proj.import_zip(asynchronous=False) else: with pytest.raises(exceptions.UnsupportedOperation): proj.import_zip(asynchronous=True) @@ -411,7 +413,6 @@ def test_export_zips() -> None: proj_list = [tutil.PROJECT_0, tutil.PROJECT_1, tutil.PROJECT_2, tutil.NON_EXISTING_KEY, PROJ_WITH_NO_LOC] regexp = f"({'|'.join(proj_list)})" res = {r["key"]: r for r in projects.export_zips(tutil.SQ, key_regexp=regexp, skip_zero_loc=True)} - assert len(res) == len(proj_list) - 1 for proj in proj_list[:3]: assert res[proj]["exportStatus"] == "SUCCESS" assert tutil.NON_EXISTING_KEY not in res diff --git a/test/unit/utilities.py b/test/unit/utilities.py index 061fa9b4..f9dec553 100644 --- a/test/unit/utilities.py +++ b/test/unit/utilities.py @@ -53,19 +53,19 @@ YAML_FILE = f"temp.{os.getpid()}.yaml" PROJECT_0 = "okorach_sonar-tools" -PROJECT_1 = "project1" -PROJECT_2 = "project2" -PROJECT_3 = "project3" -PROJECT_4 = "project4" -PROJECT_5 = "project5" +PROJECT_1 = "test:project1" +PROJECT_2 = "test:project2" +PROJECT_3 = "test:project3" +PROJECT_4 = "test:project4" +PROJECT_5 = "test:proyecto5" LIVE_PROJECT = PROJECT_0 PROJ_WITH_BRANCHES = PROJECT_1 BRANCH_MAIN = "main" BRANCH_2 = "develop" -BRANCH_3 = "some-branch" +BRANCH_3 = "release-3.x" BRANCH_4 = "feature/new-feature" -BRANCH_5 = "comma,branch" +BRANCH_5 = "release-2.x" NON_EXISTING_KEY = "non-existing"