sonarqube happy as well
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Tobias Trabelsi 2022-05-22 00:26:38 +02:00
parent 3485bf5123
commit 887ed5c0ef
Signed by: lerentis
GPG Key ID: FF0C2839718CAF2E
7 changed files with 24 additions and 12 deletions

View File

@ -13,7 +13,7 @@ steps:
image: python:3-alpine image: python:3-alpine
commands: commands:
- "pip install -r requirements.txt" - "pip install -r requirements.txt"
- "pytest --cov=app tests/" - "pytest --cov=app --cov-report xml:coverage.xml tests/"
when: when:
event: event:
- push - push

3
.gitignore vendored
View File

@ -1,3 +1,4 @@
env.sh env.sh
__pycache__ __pycache__
.pytest_cache .pytest_cache
*.xml

0
.scannerwork/.sonar_lock Normal file
View File

View File

@ -0,0 +1,6 @@
projectKey=test
serverUrl=http://localhost:9000
serverVersion=9.4.0.54424
dashboardUrl=http://localhost:9000/dashboard?id=test
ceTaskId=AYDouXJ4vMwlS3L7ASHs
ceTaskUrl=http://localhost:9000/api/ce/task?id=AYDouXJ4vMwlS3L7ASHs

View File

@ -4,15 +4,15 @@ import gitlab
import os import os
def getProject(client, project_name): def get_project(client, project_name):
return client.projects.get(project_name) return client.projects.get(project_name)
def getLanguage(project): def get_language(project):
return list(project.languages().items()) return list(project.languages().items())
def helmSet(lang): def helm_set(lang):
ret = '' ret = ''
for i in range(len(lang)): for i in range(len(lang)):
ret += f"--set global.language[{i}]={lang[i][0]}" ret += f"--set global.language[{i}]={lang[i][0]}"
@ -21,4 +21,4 @@ def helmSet(lang):
if __name__ == '__main__': if __name__ == '__main__':
with gitlab.Gitlab(url=os.environ['GITLAB_URL'], private_token=os.environ['GITLAB_TOKEN'], user_agent='my-package/1.0.0') as gl: with gitlab.Gitlab(url=os.environ['GITLAB_URL'], private_token=os.environ['GITLAB_TOKEN'], user_agent='my-package/1.0.0') as gl:
print(helmSet(getLanguage(getProject(gl, 'root/test'))), end=" ") print(helm_set(get_language(get_project(gl, 'root/test'))), end=" ")

5
sonar-project.properties Normal file
View File

@ -0,0 +1,5 @@
sonar.projectKey=test
sonar.sources=app
sonar.host.url=http://localhost:9000
sonar.python.version=3.10
sonar.python.coverage.reportPaths=./coverage.xml

View File

@ -1,5 +1,5 @@
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
from app.languages import getProject, helmSet from app.languages import get_project, helm_set
import gitlab import gitlab
from gitlab.v4.objects import ProjectManager as pm from gitlab.v4.objects import ProjectManager as pm
@ -126,21 +126,21 @@ def test_get_project():
'access_level': 50, 'access_level': 50,
'notification_level': 3}, 'notification_level': 3},
'group_access': None}} 'group_access': None}}
with patch.object(pm, 'get', return_value=project_object) as mock_method: with patch.object(pm, 'get', return_value=project_object):
gl = gitlab.Gitlab() gl = gitlab.Gitlab()
project = getProject(gl, 'root/test') project = get_project(gl, 'root/test')
assert project['id'] == 34 assert project['id'] == 34
def test_get_language(): def test_get_language():
getLanguage = MagicMock(return_value=[('Go', 100.0)]) get_language = MagicMock(return_value=[('Go', 100.0)])
expected = [('Go', 100.0)] expected = [('Go', 100.0)]
actual = getLanguage("project") actual = get_language("project")
assert expected == actual assert expected == actual
def test_helm_set(): def test_helm_set():
excepted = '--set global.language[0]=Go' excepted = '--set global.language[0]=Go'
actual = helmSet([('Go', 100.0)]) actual = helm_set([('Go', 100.0)])
assert excepted == actual assert excepted == actual