Skip to content

Commit 26acf1c

Browse files
authored
Fix-test-3 (#2030)
* Fix test * Remove bad branches * Change test projects * Change test project keys * Fix project tests * Cleanup tests * Remove non-existing project * Fix project-keys * Change changelog size * Fix tests
1 parent fd74fd2 commit 26acf1c

File tree

13 files changed

+35
-155
lines changed

13 files changed

+35
-155
lines changed

sonar/projects.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ def export_zip(self, asynchronous: bool = False, timeout: int = 180) -> tuple[st
675675
resp = self.post("project_dump/export", params={"key": self.key})
676676
except exceptions.ObjectNotFound as e:
677677
Project.CACHE.pop(self)
678-
return f"FAILED/{e.message}", None
678+
raise
679679
except exceptions.SonarException as e:
680680
return f"FAILED/{e.message}", None
681681
except RequestException as e:
@@ -710,8 +710,10 @@ def import_zip(self, asynchronous: bool = False, timeout: int = 180) -> str:
710710
try:
711711
resp = self.post("project_dump/import", params={"key": self.key})
712712
except exceptions.ObjectNotFound as e:
713+
if "Dump file does not exist" in e.message:
714+
return f"FAILED/{tasks.ZIP_MISSING}"
713715
Project.CACHE.pop(self)
714-
return f"FAILED/{e.message}"
716+
raise
715717
except exceptions.SonarException as e:
716718
if "Dump file does not exist" in e.message:
717719
return f"FAILED/{tasks.ZIP_MISSING}"

test/files/audit-config.json

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,11 @@
9999
"main": {
100100
"isMain": true,
101101
"projects": {
102-
"project1": "main",
103-
"project2": "main",
104-
"project3": "main",
105-
"project4": "main",
106-
"proyecto5": "main"
102+
"test:project1": "main",
103+
"test:project2": "main",
104+
"test:project3": "main",
105+
"test:project4": "main",
106+
"test:proyecto5": "main"
107107
}
108108
}
109109
},
@@ -248,7 +248,6 @@
248248
"sonar.cpd.cross_project": false,
249249
"sonar.dbcleaner.auditHousekeeping": "Monthly",
250250
"sonar.dbcleaner.branchesToKeepWhenInactive": [
251-
"comma,branch",
252251
"develop",
253252
"main",
254253
"master",
@@ -759,7 +758,6 @@
759758
"BANKING-INVESTMENT-EQUITY": "-DEFAULT_BRANCH-",
760759
"BANKING-INVESTMENT-MERGER": "-DEFAULT_BRANCH-",
761760
"BANKING-PORTAL": [
762-
"comma,branch",
763761
"main",
764762
"release-3.2"
765763
]
@@ -960,9 +958,6 @@
960958
},
961959
"BANKING-PORTAL": {
962960
"branches": {
963-
"comma,branch": {
964-
"keepWhenInactive": true
965-
},
966961
"main": {
967962
"isMain": true
968963
},
@@ -1978,10 +1973,6 @@
19781973
},
19791974
"okorach_sonar-tools": {
19801975
"branches": {
1981-
"comma,branch": {
1982-
"keepWhenInactive": true,
1983-
"newCodePeriod": "REFERENCE_BRANCH = develop"
1984-
},
19851976
"develop": {
19861977
"keepWhenInactive": true,
19871978
"newCodePeriod": "REFERENCE_BRANCH = master"
@@ -2018,7 +2009,7 @@
20182009
],
20192010
"visibility": "private"
20202011
},
2021-
"project1": {
2012+
"test:project1": {
20222013
"branches": {
20232014
"develop": {
20242015
"keepWhenInactive": true
@@ -2048,7 +2039,7 @@
20482039
"sonar.coverage.jacoco.xmlReportPaths": "**/*jacoco*.xml",
20492040
"visibility": "private"
20502041
},
2051-
"project2": {
2042+
"test:project2": {
20522043
"branches": {
20532044
"develop": {
20542045
"keepWhenInactive": true
@@ -2074,7 +2065,7 @@
20742065
},
20752066
"visibility": "private"
20762067
},
2077-
"project3": {
2068+
"test:project3": {
20782069
"branches": {
20792070
"develop": {
20802071
"keepWhenInactive": true
@@ -2100,7 +2091,7 @@
21002091
},
21012092
"visibility": "private"
21022093
},
2103-
"project4": {
2094+
"test:project4": {
21042095
"branches": {
21052096
"develop": {
21062097
"keepWhenInactive": true
@@ -2124,7 +2115,7 @@
21242115
},
21252116
"visibility": "public"
21262117
},
2127-
"proyecto5": {
2118+
"test:proyecto5": {
21282119
"branches": {
21292120
"develop": {
21302121
"keepWhenInactive": true

test/files/config-for-audit.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
"sonar.dbcleaner.hoursBeforeKeepingOnlyOneSnapshotByDay": "24",
5656
"sonar.dbcleaner.daysBeforeDeletingInactiveBranchesAndPRs": "30",
5757
"sonar.dbcleaner.branchesToKeepWhenInactive": [
58-
"comma,branch",
5958
"develop",
6059
"main",
6160
"master",

test/files/config.json

Lines changed: 0 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
"sonar.dbcleaner.hoursBeforeKeepingOnlyOneSnapshotByDay": "24",
5757
"sonar.dbcleaner.daysBeforeDeletingInactiveBranchesAndPRs": "30",
5858
"sonar.dbcleaner.branchesToKeepWhenInactive": [
59-
"comma,branch",
6059
"develop",
6160
"main",
6261
"master",
@@ -3437,9 +3436,6 @@
34373436
}
34383437
},
34393438
"branches": {
3440-
"comma,branch": {
3441-
"keepWhenInactive": true
3442-
},
34433439
"release-3.2": {
34443440
"keepWhenInactive": true
34453441
},
@@ -4461,81 +4457,6 @@
44614457
}
44624458
}
44634459
},
4464-
"non-existing": {
4465-
"name": "non-existing",
4466-
"visibility": "private",
4467-
"links": [
4468-
{
4469-
"type": "yahoo",
4470-
"name": "yahoo",
4471-
"url": "https://yahoo.com"
4472-
},
4473-
{
4474-
"type": "yahoo",
4475-
"name": "yahoo",
4476-
"url": "https://yahoo.com"
4477-
},
4478-
{
4479-
"type": "yahoo",
4480-
"name": "yahoo",
4481-
"url": "https://yahoo.com"
4482-
},
4483-
{
4484-
"type": "yahoo",
4485-
"name": "yahoo",
4486-
"url": "https://yahoo.com"
4487-
},
4488-
{
4489-
"type": "yahoo",
4490-
"name": "yahoo",
4491-
"url": "https://yahoo.com"
4492-
},
4493-
{
4494-
"type": "yahoo",
4495-
"name": "yahoo",
4496-
"url": "https://yahoo.com"
4497-
},
4498-
{
4499-
"type": "yahoo",
4500-
"name": "yahoo",
4501-
"url": "https://yahoo.com"
4502-
},
4503-
{
4504-
"type": "yahoo",
4505-
"name": "yahoo",
4506-
"url": "https://yahoo.com"
4507-
},
4508-
{
4509-
"type": "yahoo",
4510-
"name": "yahoo",
4511-
"url": "https://yahoo.com"
4512-
},
4513-
{
4514-
"type": "yahoo",
4515-
"name": "yahoo",
4516-
"url": "https://yahoo.com"
4517-
},
4518-
{
4519-
"type": "yahoo",
4520-
"name": "yahoo",
4521-
"url": "https://yahoo.com"
4522-
}
4523-
],
4524-
"permissions": {
4525-
"users": {
4526-
"admin": "admin"
4527-
},
4528-
"groups": {
4529-
"developers": "codeviewer, user",
4530-
"project-admins": "admin, codeviewer, user",
4531-
"security-auditors": "codeviewer, issueadmin, securityhotspotadmin, user",
4532-
"sonar-administrators": "admin, codeviewer, user",
4533-
"sonar-users": "user",
4534-
"tech-leads": "codeviewer, issueadmin, user"
4535-
}
4536-
},
4537-
"containsAiCode": true
4538-
},
45394460
"okorach-org_pr-demo_3a1857ec-cebc-49f2-96ac-9bbc99111469": {
45404461
"name": "pr-demo",
45414462
"visibility": "private",
@@ -4687,35 +4608,6 @@
46874608
}
46884609
]
46894610
},
4690-
"okorach_sonar-tools-target": {
4691-
"name": "Sonar Tools Target",
4692-
"visibility": "private",
4693-
"permissions": {
4694-
"users": {
4695-
"admin": "admin, codeviewer, user",
4696-
"syncer": "codeviewer, issueadmin, securityhotspotadmin, user"
4697-
},
4698-
"groups": {
4699-
"developers": "codeviewer, user",
4700-
"project-admins": "admin, codeviewer, user",
4701-
"security-auditors": "codeviewer, issueadmin, securityhotspotadmin, user",
4702-
"sonar-administrators": "admin, codeviewer, user",
4703-
"sonar-users": "user",
4704-
"tech-leads": "codeviewer, issueadmin, user"
4705-
}
4706-
},
4707-
"branches": {
4708-
"master": {
4709-
"isMain": true
4710-
},
4711-
"develop": {
4712-
"keepWhenInactive": true
4713-
},
4714-
"comma,branch": {
4715-
"keepWhenInactive": true
4716-
}
4717-
}
4718-
},
47194611
"org.owasp.webgoat:webgoat": {
47204612
"name": "WebGoat",
47214613
"visibility": "private",
@@ -4794,9 +4686,6 @@
47944686
}
47954687
},
47964688
"branches": {
4797-
"comma,branch": {
4798-
"keepWhenInactive": true
4799-
},
48004689
"release-2.x": {
48014690
"keepWhenInactive": true
48024691
},
@@ -5449,7 +5338,6 @@
54495338
"BANKING-INVESTMENT-EQUITY": "-DEFAULT_BRANCH-",
54505339
"BANKING-INVESTMENT-MERGER": "-DEFAULT_BRANCH-",
54515340
"BANKING-PORTAL": [
5452-
"comma,branch",
54535341
"main",
54545342
"release-3.2"
54555343
]

test/projects-provisioning/scan.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ cd "$DIR"
88

99
url=${1:-$SONAR_HOST_URL}
1010

11-
projects="project1 project2 project3 project4 proyecto5"
11+
projects="test:project1 test:project2 test:project3 test:project4 test:proyecto5"
1212
for p in $projects; do
1313
echo "Processing $p"
1414
sonar-scanner -Dsonar.projectKey=$p -Dsonar.host.url=$url -Dsonar.branch.name=develop -Dsonar.login=$SONAR_TOKEN -Dsonar.token=$SONAR_TOKEN
1515
done
1616

17-
branches="feature/new-feature some-branch comma,branch release-2.x release-3.x"
17+
branches="feature/new-feature some-branch release-3.x"
1818
for b in $branches; do
1919
echo "Processing $p"
2020
sonar-scanner -Dsonar.projectKey=$p -Dsonar.host.url=$url -Dsonar.projectKey=project1 -Dsonar.branch.name=$b -Dsonar.login=$SONAR_TOKEN -Dsonar.token=$SONAR_TOKEN
2121
done
2222

2323
projects=" \
24-
project1 project2 project3 project4 proyecto5
24+
test:project1 test:project2 test:project3 test:project4 test:proyecto5
2525
INSURANCE-LIFE INSURANCE-HOME INSURANCE-PET INSURANCE-HEALTH
2626
BANKING-INVESTMENT-ACQUISITIONS BANKING-INVESTMENT-EQUITY BANKING-INVESTMENT-DILIGENCE BANKING-INVESTMENT-MERGER
2727
BANKING-RETAIL-ATM BANKING-RETAIL-WEB BANKING-RETAIL-CLERK

test/test-sync.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ do
55
curl -X POST -u "$SONAR_TOKEN:" "$SONAR_HOST_URL/api/projects/delete?project=$proj"
66
opts=("-Dsonar.projectKey=$proj" "-Dsonar.projectName=$proj")
77
conf/run_all.sh "${opts[@]}" "$@"
8-
for branch in release-1.x release-2.x
8+
for branch in release-2.x release-2.x
99
do
1010
conf/run_all.sh "${opts[@]}" "$@" "-Dsonar.branch.name=$branch"
1111
done

test/unit/credentials-latest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
TARGET_TOKEN = getenv("SONAR_TOKEN_LATEST_ADMIN_USER")
2727

2828
ISSUE_FP = "64e848c0-d5f4-402e-8c80-af6536041b5e"
29-
ISSUE_FP_NBR_CHANGELOGS = 12
29+
ISSUE_FP_NBR_CHANGELOGS = 13
3030
ISSUE_FP_CHANGELOG_DATE = datetime(2025, 10, 23)
3131

3232
ISSUE_ACCEPTED = "e9eb08fe-bb53-443a-8a92-425589807c78"

test/unit/credentials.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
TARGET_TOKEN = getenv("SONAR_TOKEN_LATEST_ADMIN_USER")
2727

2828
ISSUE_FP = "64e848c0-d5f4-402e-8c80-af6536041b5e"
29-
ISSUE_FP_NBR_CHANGELOGS = 12
29+
ISSUE_FP_NBR_CHANGELOGS = 13
3030
ISSUE_FP_CHANGELOG_DATE = datetime(2025, 10, 23)
3131

3232
ISSUE_ACCEPTED = "e9eb08fe-bb53-443a-8a92-425589807c78"

test/unit/test_config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
from sonar import portfolios, applications, projects
3131
from sonar import logging
3232
import sonar.util.constants as c
33-
from sonar import utilities as util
3433

3534
import cli.options as opt
3635
from cli import config

test/unit/test_housekeeper.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_keep_branches_override(csv_file: Generator[str]) -> None:
4747
pytest.skip("No branches in Community")
4848
opts = f"{CMD} {tutil.SQS_OPTS} -P 730 -T 730 -R 730 -B 90 -f {csv_file}"
4949
assert tutil.run_cmd(housekeeper.main, opts) == errcodes.OK
50-
nbr_br = tutil.csv_col_count_values(csv_file, "Audit Check", "BRANCH_LAST_ANALYSIS")
50+
nbr_br = tutil.csv_col_count_values(csv_file, "Problem", "BRANCH_LAST_ANALYSIS")
5151
assert tutil.run_cmd(housekeeper.main, f"{opts} --keepWhenInactive 'dontkeepanything'") == errcodes.OK
5252
# With 'dontkeepanything' as branch regexp, more branches to delete should be found
53-
assert tutil.csv_col_count_values(csv_file, "Audit Check", "BRANCH_LAST_ANALYSIS") > nbr_br
53+
assert tutil.csv_col_count_values(csv_file, "Problem", "BRANCH_LAST_ANALYSIS") > nbr_br

0 commit comments

Comments
 (0)