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

Add test + sonar for tasks subproject

parent c16d7d7b
No related branches found
No related tags found
1 merge request!72Develop
Pipeline #9381 passed
Pipeline: anis-next

#9383

    Pipeline: anis-next

    #9382

      ......@@ -27,6 +27,7 @@ list:
      @echo " test_services > Starts the services unit tests"
      @echo " install_tasks > install tasks dependencies (virtualenv)"
      @echo " shell_tasks > Shell into python tasks"
      @echo " test_tasks > Starts the tasks unit tests"
      @echo " create-db > Create a database for dev only (need token_enabled=0)"
      @echo " remove-pgdata > Remove the anis-next database"
      @echo " remove-matodata > Remove the anis-next matomo volumes"
      ......@@ -105,6 +106,9 @@ install_tasks:
      shell_tasks:
      @docker-compose exec tasks bash
      test_tasks:
      @docker-compose exec tasks /bin/bash -c "source ./venv/bin/activate && pytest"
      create-db:
      @docker-compose exec server sh /mnt/init-keycloak.sh
      @docker-compose exec server sh /mnt/create-db.sh
      ......
      ......@@ -58,3 +58,4 @@ eggs/
      *.egg
      __pycache__/
      *.pyc
      .pytest_cache
      ......@@ -5,6 +5,8 @@ dist
      var
      coverage
      data
      report
      .coverage
      # Only exists if Bazel was run
      /bazel-out
      ......@@ -56,3 +58,4 @@ eggs/
      *.egg
      __pycache__/
      *.pyc
      .pytest_cache
      stages:
      - test
      - sonar
      - dockerize
      - deploy
      ......@@ -17,6 +19,32 @@ dockerize:
      - docker build --cache-from $CI_REGISTRY/anis/anis-next/tasks:latest -t $CI_REGISTRY/anis/anis-next/tasks:latest .
      - docker push $CI_REGISTRY/anis/anis-next/tasks:latest
      test:
      image: python:3.8
      stage: test
      script:
      - cd tasks
      - export PYTHONPATH=/builds/anis/anis-next/tasks/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:
      - tasks/report
      sonar_scanner:
      image: sonarsource/sonar-scanner-cli:latest
      stage: sonar
      script:
      - cd tasks
      - sonar-scanner
      -Dsonar.projectKey=anis-tasks
      -Dsonar.sources=src
      -Dsonar.projectVersion=$VERSION
      -Dsonar.host.url=$SONARQUBE_URL
      -Dsonar.login=$SONAR_TOKEN_TASKS
      -Dsonar.python.coverage.reportPaths=report/coverage.xml
      -Dsonar.python.xunit.reportPath=report/pytest.xml
      deploy:
      image: alpine
      stage: deploy
      ......
      attrs==22.1.0
      certifi==2021.10.8
      charset-normalizer==2.0.12
      coverage==6.4.4
      decorator==5.1.1
      idna==3.3
      iniconfig==1.1.1
      packaging==21.3
      pika==1.2.0
      pluggy==1.0.0
      py==1.11.0
      pyparsing==3.0.9
      pytest==7.1.3
      pytest-asyncio==0.19.0
      pytest-cov==4.0.0
      pytest-mock==3.9.0
      requests==2.27.1
      retry==0.9.2
      tomli==2.0.1
      urllib3==1.26.8
      import os
      from unittest import mock
      from unittest.mock import call
      import pytest
      from anis_tasks.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