Skip to content

Commit 8f410a0

Browse files
committed
Add first SC tests
1 parent c11fa2b commit 8f410a0

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

test/test_sonarcloud.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#!/usr/bin/env python3
2+
#
3+
# sonar-tools tests
4+
# Copyright (C) 2024 Olivier Korach
5+
# mailto:olivier.korach AT gmail DOT com
6+
#
7+
# This program is free software; you can redistribute it and/or
8+
# modify it under the terms of the GNU Lesser General Public
9+
# License as published by the Free Software Foundation; either
10+
# version 3 of the License, or (at your option) any later version.
11+
#
12+
# This program is distributed in the hope that it will be useful,
13+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15+
# Lesser General Public License for more details.
16+
#
17+
# You should have received a copy of the GNU Lesser General Public License
18+
# along with this program; if not, write to the Free Software Foundation,
19+
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20+
#
21+
""" sonarcloud tests """
22+
23+
import os
24+
import sys
25+
from unittest.mock import patch
26+
import pytest
27+
28+
import utilities as util
29+
from sonar import errcodes
30+
import cli.options as opt
31+
from cli import config
32+
33+
CMD = "config.py"
34+
SC_OPTS = [f"-{opt.URL_SHORT}", "https://sonarcloud.io", f"-{opt.TOKEN_SHORT}", os.getenv("SONAR_TOKEN_SONARCLOUD")]
35+
36+
OPTS = [CMD] + SC_OPTS + [f"-{opt.EXPORT_SHORT}", f"-{opt.REPORT_FILE_SHORT}", util.JSON_FILE]
37+
38+
39+
def test_sc_config_export() -> None:
40+
"""test_sc_config_export"""
41+
util.clean(util.JSON_FILE)
42+
with pytest.raises(SystemExit) as e:
43+
with patch.object(sys, "argv", OPTS + [f"-{opt.ORG_SHORT}", "okorach"]):
44+
config.main()
45+
assert int(str(e.value)) == errcodes.OK
46+
assert util.file_not_empty(util.JSON_FILE)
47+
util.clean(util.JSON_FILE)
48+
49+
def test_sc_config_export_no_org() -> None:
50+
"""test_sc_config_export"""
51+
util.clean(util.JSON_FILE)
52+
with pytest.raises(SystemExit) as e:
53+
with patch.object(sys, "argv", OPTS):
54+
config.main()
55+
assert int(str(e.value)) == errcodes.ARGS_ERROR
56+
assert not os.path.isfile(util.JSON_FILE)

0 commit comments

Comments
 (0)