Skip to content

Commit 17bf293

Browse files
committed
Add sonarcloud tests
1 parent 0b793fd commit 17bf293

File tree

2 files changed

+66
-2
lines changed

2 files changed

+66
-2
lines changed

test/test_sonarcloud.py

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,17 @@
2626
import pytest
2727

2828
import utilities as util
29-
from sonar import errcodes
29+
from sonar import errcodes, exceptions
30+
from sonar import organizations
3031
import cli.options as opt
3132
from cli import config
3233

3334
CMD = "config.py"
3435
SC_OPTS = [f"-{opt.URL_SHORT}", "https://sonarcloud.io", f"-{opt.TOKEN_SHORT}", os.getenv("SONAR_TOKEN_SONARCLOUD")]
3536

3637
OPTS = [CMD] + SC_OPTS + [f"-{opt.EXPORT_SHORT}", f"-{opt.REPORT_FILE_SHORT}", util.JSON_FILE]
37-
38+
MY_ORG_1 = "okorach"
39+
MY_ORG_2 = "okorach-github"
3840

3941
def test_sc_config_export() -> None:
4042
"""test_sc_config_export"""
@@ -55,3 +57,64 @@ def test_sc_config_export_no_org() -> None:
5557
config.main()
5658
assert int(str(e.value)) == errcodes.ARGS_ERROR
5759
assert not os.path.isfile(util.JSON_FILE)
60+
61+
62+
def test_org_search() -> None:
63+
"""test_org_search"""
64+
org_list = organizations.search(endpoint=util.SC)
65+
assert MY_ORG_1 in org_list
66+
assert MY_ORG_2 in org_list
67+
68+
69+
def test_org_get_list() -> None:
70+
"""test_org_search"""
71+
org_list = organizations.get_list(endpoint=util.SC)
72+
assert MY_ORG_1 in org_list
73+
assert MY_ORG_2 in org_list
74+
75+
org_list = organizations.get_list(endpoint=util.SC, key_list=[MY_ORG_1])
76+
assert MY_ORG_1 in org_list
77+
assert MY_ORG_2 not in org_list
78+
79+
80+
def test_org_get_non_existing() -> None:
81+
"""test_org_search_sq"""
82+
with pytest.raises(exceptions.ObjectNotFound):
83+
_ = organizations.Organization.get_object(endpoint=util.SC, key="oko_foo_bar")
84+
85+
with pytest.raises(exceptions.ObjectNotFound):
86+
_ = organizations.get_list(endpoint=util.SC, key_list=["oko_foo_bar"])
87+
88+
89+
def test_org_str() -> None:
90+
"""test_org_str"""
91+
org = organizations.Organization.get_object(endpoint=util.SC, key=MY_ORG_1)
92+
assert str(org) == f"organization key '{MY_ORG_1}'"
93+
94+
95+
def test_org_export() -> None:
96+
"""test_org_export"""
97+
org = organizations.Organization.get_object(endpoint=util.SC, key=MY_ORG_1)
98+
exp = org.export()
99+
assert "newCodePeriod" in exp
100+
101+
102+
def test_org_attr() -> None:
103+
"""test_org_attr"""
104+
org = organizations.Organization.get_object(endpoint=util.SC, key=MY_ORG_1)
105+
assert org.key == MY_ORG_1
106+
assert org.name == "Olivier Korach"
107+
assert org._json["url"] == "https://github.com/okorach"
108+
(nc_type, nc_val) = org.new_code_period()
109+
assert nc_type == "PREVIOUS_VERSION"
110+
assert org.subscription() == "FREE"
111+
assert org.alm()["key"] == "github"
112+
113+
114+
def test_org_search_sq() -> None:
115+
"""test_org_search_sq"""
116+
with pytest.raises(exceptions.UnsupportedOperation):
117+
_ = organizations.search(endpoint=util.SQ)
118+
119+
with pytest.raises(exceptions.UnsupportedOperation):
120+
_ = organizations.get_list(endpoint=util.SQ)

test/utilities.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
CE_OPTS = [f"-{opt.URL_SHORT}", LATEST_CE, f"-{opt.TOKEN_SHORT}", os.getenv("SONAR_TOKEN_ADMIN_USER")]
4444

4545
SQ = platform.Platform(url=os.getenv("SONAR_HOST_URL"), token=os.getenv("SONAR_TOKEN_ADMIN_USER"))
46+
SC = platform.Platform(url="https://sonarcloud.io", token=os.getenv("SONAR_TOKEN_SONARCLOUD"))
4647
TEST_SQ = platform.Platform(url=LATEST_TEST, token=os.getenv("SONAR_TOKEN_ADMIN_USER"))
4748

4849

0 commit comments

Comments
 (0)