Skip to content
Snippets Groups Projects
Commit 52edeb7c authored by François Agneray's avatar François Agneray
Browse files

Add test + sonar for services subproject

parent 4115ae30
No related branches found
No related tags found
1 merge request!72Develop
Pipeline #9377 failed
Pipeline: anis-next

#9378

    ......@@ -24,6 +24,7 @@ list:
    @echo " phpcs > Run php code sniffer test suite"
    @echo " install_services > install services dependencies (virtualenv)"
    @echo " shell_services > Shell into python services"
    @echo " test_services > Starts the services unit tests"
    @echo " install_tasks > install tasks dependencies (virtualenv)"
    @echo " shell_tasks > Shell into python tasks"
    @echo " create-db > Create a database for dev only (need token_enabled=0)"
    ......@@ -95,6 +96,9 @@ install_services:
    shell_services:
    @docker-compose exec services bash
    test_services:
    @docker-compose exec services /bin/bash -c "source ./venv/bin/activate && pytest"
    install_tasks:
    @docker run --init -it --rm --user $(UID):$(GID) -v $(CURDIR)/tasks:/project -w /project python:3.8 /bin/bash -c "python3 -m venv venv && source /project/venv/bin/activate && pip install -r requirements.txt"
    ......
    stages:
    - test
    - sonar
    - dockerize
    - deploy
    ......@@ -6,6 +8,32 @@ variables:
    VERSION: "3.7"
    SONARQUBE_URL: https://sonarqube.lam.fr
    test:
    image: python:3.8
    stage: test
    script:
    - cd services
    - export PYTHONPATH=/builds/anis/anis-next/services/src
    - /bin/bash -c "python3 -m venv venv && source ./venv/bin/activate && pip install -r requirements.txt"
    - /bin/bash -c "source ./venv/bin/activate && pytest --cov=src --cov-report xml:report/coverage.xml --junitxml=report/pytest.xml"
    artifacts:
    paths:
    - services/report
    sonar_scanner:
    image: sonarsource/sonar-scanner-cli:latest
    stage: sonar
    script:
    - cd services
    - sonar-scanner
    -Dsonar.projectKey=anis-services
    -Dsonar.sources=src
    -Dsonar.projectVersion=$VERSION
    -Dsonar.host.url=$SONARQUBE_URL
    -Dsonar.login=$SONAR_TOKEN_SERVICES
    -Dsonar.python.coverage.reportPaths=report/coverage.xml
    -Dsonar.python.xunit.reportPath=report/pytest.xml
    dockerize:
    image: docker:stable
    stage: dockerize
    ......
    import os
    from unittest import mock
    from unittest.mock import call
    import pytest
    from anis_services.utils import *
    class Object(object):
    pass
    class MockJWT:
    def decode(self, *args):
    pass
    class TestIfsctoolsUtils:
    @mock.patch.dict(os.environ, {}, clear=True)
    def test_check_config(self):
    with pytest.raises(ConfigKeyNotFound):
    check_config()
    0% Loading or .
    You are about to add 0 people to the discussion. Proceed with caution.
    Finish editing this message first!
    Please register or to comment