From 8a58e2676299cadfe97f40270c6f30b7ffcb280c Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Tue, 17 Jun 2025 14:22:28 -0500 Subject: [PATCH 01/17] docs(app): Changes files from directories --- main.py => app/main.py | 2 +- opensense.py => app/opensense.py | 0 Dockerfile => docker/Dockerfile | 34 +++++++++---------- .../fixtures}/vcr_cassettes/metrics.yaml | 0 .../fixtures}/vcr_cassettes/temperature.yaml | 0 .../fixtures}/vcr_cassettes/version.yaml | 0 test_main.py => tests/test_main.py | 0 7 files changed, 18 insertions(+), 18 deletions(-) rename main.py => app/main.py (96%) rename opensense.py => app/opensense.py (100%) rename Dockerfile => docker/Dockerfile (96%) rename {fixtures => tests/fixtures}/vcr_cassettes/metrics.yaml (100%) rename {fixtures => tests/fixtures}/vcr_cassettes/temperature.yaml (100%) rename {fixtures => tests/fixtures}/vcr_cassettes/version.yaml (100%) rename test_main.py => tests/test_main.py (100%) diff --git a/main.py b/app/main.py similarity index 96% rename from main.py rename to app/main.py index 136b393..ed968d7 100644 --- a/main.py +++ b/app/main.py @@ -1,7 +1,7 @@ '''Module containing the main function of the app.''' from flask import Flask, Response from prometheus_client import generate_latest, CONTENT_TYPE_LATEST -import opensense +import app.opensense as opensense #import test_main app = Flask(__name__) diff --git a/opensense.py b/app/opensense.py similarity index 100% rename from opensense.py rename to app/opensense.py diff --git a/Dockerfile b/docker/Dockerfile similarity index 96% rename from Dockerfile rename to docker/Dockerfile index ca5f91e..cb4b136 100644 --- a/Dockerfile +++ b/docker/Dockerfile @@ -1,18 +1,18 @@ -FROM python:3.13.1-alpine@sha256:f9d772b2b40910ee8de2ac2b15ff740b5f26b37fc811f6ada28fce71a2542b0e - -RUN addgroup -S appgroup && adduser -S -G appgroup appuser - -WORKDIR /app - -COPY main.py opensense.py version.txt requirements.txt /app/ - -RUN pip install --no-cache-dir -r /app/requirements.txt --require-hashes && \ - chown -R appuser:appgroup /app - -ENV FLASK_APP=main.py \ - PYTHONUNBUFFERED=1 - -USER appuser - -ENTRYPOINT [ "flask" ] +FROM python:3.13.1-alpine@sha256:f9d772b2b40910ee8de2ac2b15ff740b5f26b37fc811f6ada28fce71a2542b0e + +RUN addgroup -S appgroup && adduser -S -G appgroup appuser + +WORKDIR /app + +COPY main.py opensense.py version.txt requirements.txt /app/ + +RUN pip install --no-cache-dir -r /app/requirements.txt --require-hashes && \ + chown -R appuser:appgroup /app + +ENV FLASK_APP=main.py \ + PYTHONUNBUFFERED=1 + +USER appuser + +ENTRYPOINT [ "flask" ] CMD [ "run", "--host=0.0.0.0" ] \ No newline at end of file diff --git a/fixtures/vcr_cassettes/metrics.yaml b/tests/fixtures/vcr_cassettes/metrics.yaml similarity index 100% rename from fixtures/vcr_cassettes/metrics.yaml rename to tests/fixtures/vcr_cassettes/metrics.yaml diff --git a/fixtures/vcr_cassettes/temperature.yaml b/tests/fixtures/vcr_cassettes/temperature.yaml similarity index 100% rename from fixtures/vcr_cassettes/temperature.yaml rename to tests/fixtures/vcr_cassettes/temperature.yaml diff --git a/fixtures/vcr_cassettes/version.yaml b/tests/fixtures/vcr_cassettes/version.yaml similarity index 100% rename from fixtures/vcr_cassettes/version.yaml rename to tests/fixtures/vcr_cassettes/version.yaml diff --git a/test_main.py b/tests/test_main.py similarity index 100% rename from test_main.py rename to tests/test_main.py From 1d600bc2e11d7faf7ae1cf3d499e44ebccc7ee43 Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Tue, 17 Jun 2025 14:31:27 -0500 Subject: [PATCH 02/17] fix(ci): Changed paths for scripts --- .github/workflows/build_test.yml | 4 ++-- .github/workflows/hadolint.yml | 2 +- .github/workflows/sonarqube.yml | 11 ++++++----- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.github/workflows/build_test.yml b/.github/workflows/build_test.yml index a6866a7..2cbedd2 100644 --- a/.github/workflows/build_test.yml +++ b/.github/workflows/build_test.yml @@ -18,7 +18,7 @@ jobs: steps: - uses: actions/checkout@v4 - name: Build the Docker image - run: docker build . --file Dockerfile --tag pommed3rre/hivebox:$(cat version.txt) + run: docker build . --file docker/Dockerfile --tag pommed3rre/hivebox:$(cat version.txt) - name: Run Docker container run: docker run -d -p 5000:5000 pommed3rre/hivebox:$(cat version.txt) @@ -36,7 +36,7 @@ jobs: - name: Run tests run: | - python test_main.py + python tests/test_main.py TEST_EXIT_CODE=$? if [ $TEST_EXIT_CODE -ne 0 ]; then echo "Tests failed!" diff --git a/.github/workflows/hadolint.yml b/.github/workflows/hadolint.yml index 67f3db6..3118bcb 100644 --- a/.github/workflows/hadolint.yml +++ b/.github/workflows/hadolint.yml @@ -19,4 +19,4 @@ jobs: - uses: actions/checkout@v4 - uses: hadolint/hadolint-action@v3.1.0 with: - dockerfile: Dockerfile + dockerfile: docker/Dockerfile diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index 9ae7570..854d391 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -1,11 +1,12 @@ name: SonarQube analysis -on: +on: push: - branches: [ "main", "test" ] + branches: + - main pull_request: - branches: [ "main" ] - workflow_dispatch: + branches: + - main permissions: pull-requests: read @@ -33,7 +34,7 @@ jobs: - name: Run tests with coverage run: | - coverage run test_main.py + coverage run tests/test_main.py coverage xml - name: Analyze with SonarQube From 3849adcfd17977e004491bac91a81c8013900f7e Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Wed, 18 Jun 2025 11:20:45 -0500 Subject: [PATCH 03/17] fix(docker): Resolved Dockerfile paths --- .github/dependabot.yml | 2 +- docker/Dockerfile | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index a14c5fb..1ffe30d 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -25,6 +25,6 @@ updates: - package-ecosystem: "github-actions" directory: "/" schedule: - interval: "monthly" + interval: "weekly" reviewers: - "GabrielPalmar" diff --git a/docker/Dockerfile b/docker/Dockerfile index cb4b136..32912fa 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -4,12 +4,13 @@ RUN addgroup -S appgroup && adduser -S -G appgroup appuser WORKDIR /app -COPY main.py opensense.py version.txt requirements.txt /app/ +COPY app/ /app/app/ +COPY version.txt requirements.txt /app/ RUN pip install --no-cache-dir -r /app/requirements.txt --require-hashes && \ chown -R appuser:appgroup /app -ENV FLASK_APP=main.py \ +ENV FLASK_APP=app.main.py:app \ PYTHONUNBUFFERED=1 USER appuser From 30378520770647415502afdf5d64adf4db2a6bcf Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Wed, 18 Jun 2025 11:32:12 -0500 Subject: [PATCH 04/17] fix(app): Module syntax and paths --- app/main.py | 2 +- tests/test_main.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/main.py b/app/main.py index ed968d7..acb9660 100644 --- a/app/main.py +++ b/app/main.py @@ -1,7 +1,7 @@ '''Module containing the main function of the app.''' from flask import Flask, Response from prometheus_client import generate_latest, CONTENT_TYPE_LATEST -import app.opensense as opensense +from app import opensense #import test_main app = Flask(__name__) diff --git a/tests/test_main.py b/tests/test_main.py index dab0066..85eccfa 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -8,7 +8,7 @@ API_HOST = os.environ.get('API_HOST', 'http://127.0.0.1:5000') my_vcr = vcr.VCR( - cassette_library_dir='fixtures/vcr_cassettes', + cassette_library_dir='tests/fixtures/vcr_cassettes', record_mode='once', match_on=['uri', 'method'], ) From 8302ccbe1403d4a0b3854ebd4b0ec232d5fa3728 Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Wed, 18 Jun 2025 11:52:58 -0500 Subject: [PATCH 05/17] fix(ci): Paths and syntax) --- .github/workflows/pylint.yml | 6 +++++- app/main.py | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml index 1a6e8e1..98ebc38 100644 --- a/.github/workflows/pylint.yml +++ b/.github/workflows/pylint.yml @@ -33,4 +33,8 @@ jobs: pip install prometheus_client - name: Analysing the code with pylint run: | - pylint $(git ls-files '*.py') + # Set PYTHONPATH so pylint can find the app module + export PYTHONPATH="${PYTHONPATH}:$(pwd)" + pylint app/ --ignore=__pycache__ + env: + PYTHONPATH: ${{ github.workspace }} \ No newline at end of file diff --git a/app/main.py b/app/main.py index acb9660..9310069 100644 --- a/app/main.py +++ b/app/main.py @@ -10,7 +10,7 @@ def print_version(): '''Function printing the current version of the app.''' - with open('version.txt', 'r', encoding="utf-8") as f: + with open('../version.txt', 'r', encoding="utf-8") as f: version = f.read() return f"Current app version: {version}\n" From f9e8bb8799a4482521994c8a6db0147a030538b5 Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Wed, 18 Jun 2025 11:59:42 -0500 Subject: [PATCH 06/17] fix(ci): Paths and syntax in sonar --- .github/workflows/sonarqube.yml | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index 854d391..5f565e1 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -19,7 +19,7 @@ jobs: - name: Checkout code uses: actions/checkout@v4 with: - fetch-depth: 0 # Disable shallow clones for better analysis + fetch-depth: 0 - name: Set up Python uses: actions/setup-python@v5 @@ -30,12 +30,15 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - pip install coverage pytest vcrpy + pip install coverage vcrpy - name: Run tests with coverage run: | - coverage run tests/test_main.py - coverage xml + # Run your test file directly with coverage + coverage run tests/test_main.py + coverage xml + env: + PYTHONPATH: ${{ github.workspace }} - name: Analyze with SonarQube uses: SonarSource/sonarqube-scan-action@master @@ -46,5 +49,7 @@ jobs: args: > -Dsonar.projectKey=GabrielPalmar_HiveBox-Project -Dsonar.organization=gabrielpalmar - -Dsonar.sources=. - -Dsonar.exclusions=**/*test*/**,**/fixtures/**,**/__pycache__/**,**/venv/**,**/.git/** \ No newline at end of file + -Dsonar.sources=app + -Dsonar.tests=tests + -Dsonar.python.coverage.reportPaths=coverage.xml + -Dsonar.exclusions=**/fixtures/**,**/__pycache__/**,**/venv/**,**/.git/**,docker/**,k8s/**,scripts/** \ No newline at end of file From 78c95146fa6fcb13ed572f1ddeda3b0c225f3231 Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Wed, 18 Jun 2025 12:12:01 -0500 Subject: [PATCH 07/17] fix(ci): Paths and syntax in sonar pt.2 --- .github/workflows/sonarqube.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index 5f565e1..aea867d 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -35,7 +35,7 @@ jobs: - name: Run tests with coverage run: | # Run your test file directly with coverage - coverage run tests/test_main.py + coverage run --source=app tests/test_main.py coverage xml env: PYTHONPATH: ${{ github.workspace }} From e14dc0130600ad6c71c9dec9cde1a70f6f77ab44 Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Wed, 18 Jun 2025 12:22:09 -0500 Subject: [PATCH 08/17] fix(ci): Run simple Sonarqube --- .github/workflows/sonarqube.yml | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index aea867d..fbf1dcf 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -32,14 +32,13 @@ jobs: pip install -r requirements.txt pip install coverage vcrpy - - name: Run tests with coverage + - name: Run tests run: | - # Run your test file directly with coverage - coverage run --source=app tests/test_main.py - coverage xml + # Simple test execution without coverage measurement + python tests/test_main.py env: PYTHONPATH: ${{ github.workspace }} - + - name: Analyze with SonarQube uses: SonarSource/sonarqube-scan-action@master env: @@ -51,5 +50,4 @@ jobs: -Dsonar.organization=gabrielpalmar -Dsonar.sources=app -Dsonar.tests=tests - -Dsonar.python.coverage.reportPaths=coverage.xml -Dsonar.exclusions=**/fixtures/**,**/__pycache__/**,**/venv/**,**/.git/**,docker/**,k8s/**,scripts/** \ No newline at end of file From 185eeb284b9f29c4186c84af15cdbf42cd6b92b5 Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Wed, 18 Jun 2025 12:33:25 -0500 Subject: [PATCH 09/17] fix(ci): Run simple Sonarqube pt. 3 --- .github/workflows/sonarqube.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index fbf1dcf..8397e93 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -30,7 +30,6 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - pip install coverage vcrpy - name: Run tests run: | @@ -50,4 +49,5 @@ jobs: -Dsonar.organization=gabrielpalmar -Dsonar.sources=app -Dsonar.tests=tests + -Dsonar.coverage.exclusions=**/* -Dsonar.exclusions=**/fixtures/**,**/__pycache__/**,**/venv/**,**/.git/**,docker/**,k8s/**,scripts/** \ No newline at end of file From 7be62771f86de1485d27306bb2a5fb9d968a4a9c Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Wed, 18 Jun 2025 13:04:56 -0500 Subject: [PATCH 10/17] fix(ci): Default Sonarqube --- .github/workflows/sonarqube.yml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index 8397e93..a0e273a 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -30,14 +30,13 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt + pip install coverage pytest vcrpy - - name: Run tests + - name: Run tests with coverage run: | - # Simple test execution without coverage measurement - python tests/test_main.py - env: - PYTHONPATH: ${{ github.workspace }} - + coverage run tests/test_main.py + coverage xml + - name: Analyze with SonarQube uses: SonarSource/sonarqube-scan-action@master env: @@ -47,7 +46,5 @@ jobs: args: > -Dsonar.projectKey=GabrielPalmar_HiveBox-Project -Dsonar.organization=gabrielpalmar - -Dsonar.sources=app - -Dsonar.tests=tests - -Dsonar.coverage.exclusions=**/* + -Dsonar.sources=. -Dsonar.exclusions=**/fixtures/**,**/__pycache__/**,**/venv/**,**/.git/**,docker/**,k8s/**,scripts/** \ No newline at end of file From 579c6983d0d352dbf9a6231d60fb1ceda6e8d290 Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Thu, 19 Jun 2025 11:10:49 -0500 Subject: [PATCH 11/17] fix(ci): Trying new params in SQ --- .github/workflows/sonarqube.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index a0e273a..bdf1202 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -34,8 +34,9 @@ jobs: - name: Run tests with coverage run: | - coverage run tests/test_main.py - coverage xml + coverage run --source=app tests/test_main.py + coverage xml + coverage report - name: Analyze with SonarQube uses: SonarSource/sonarqube-scan-action@master @@ -46,5 +47,7 @@ jobs: args: > -Dsonar.projectKey=GabrielPalmar_HiveBox-Project -Dsonar.organization=gabrielpalmar - -Dsonar.sources=. + -Dsonar.sources=app + -Dsonar.tests=tests + -Dsonar.python.coverage.reportPaths=coverage.xml -Dsonar.exclusions=**/fixtures/**,**/__pycache__/**,**/venv/**,**/.git/**,docker/**,k8s/**,scripts/** \ No newline at end of file From a92aa083628e918fe3a6552ed8bc51a765773e9a Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Thu, 19 Jun 2025 13:02:33 -0500 Subject: [PATCH 12/17] chore(ci): Adding new test module script for SQ --- .github/workflows/sonarqube.yml | 2 +- app/main.py | 11 ---------- tests/test_main.py | 2 +- tests/test_modules.py | 36 +++++++++++++++++++++++++++++++++ 4 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 tests/test_modules.py diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index bdf1202..42cd394 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -34,7 +34,7 @@ jobs: - name: Run tests with coverage run: | - coverage run --source=app tests/test_main.py + coverage run --source=app tests/test_modules.py coverage xml coverage report diff --git a/app/main.py b/app/main.py index 9310069..e9eaee7 100644 --- a/app/main.py +++ b/app/main.py @@ -2,7 +2,6 @@ from flask import Flask, Response from prometheus_client import generate_latest, CONTENT_TYPE_LATEST from app import opensense -#import test_main app = Flask(__name__) @@ -25,15 +24,5 @@ def metrics(): '''Function to return Prometheus metrics.''' return Response(generate_latest(), mimetype=CONTENT_TYPE_LATEST) -### Test module ### -# @app.route('/test') -# def test(): -# '''Function to test the app.''' -# success = test_main.run_all_tests() -# if success: -# return "All tests passed!\n", 200 -# else: -# return "Some tests failed. Check the logs for details.\n", 500 - if __name__ == "__main__": app.run() diff --git a/tests/test_main.py b/tests/test_main.py index 85eccfa..7c9ec55 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,4 +1,4 @@ -'''This module contains the test cases for the opensense module.''' +'''This module contains the test cases for the main module.''' import sys import re import os diff --git a/tests/test_modules.py b/tests/test_modules.py new file mode 100644 index 0000000..c9d0edb --- /dev/null +++ b/tests/test_modules.py @@ -0,0 +1,36 @@ +'''This module contains tests for the Flask and OpenSense modules.''' +import os +import sys +from app.main import app +from app import opensense + +sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) + +def test_app_exists(): + """Test that the Flask app exists""" + assert app is not None + +def test_version_endpoint(): + """Test version endpoint with test client""" + client = app.test_client() + response = client.get('/version') + assert response.status_code == 200 + +def test_temperature_endpoint(): + """Test temperature endpoint with test client""" + client = app.test_client() + response = client.get('/temperature') + assert response.status_code in [200, 500] + +def test_metrics_endpoint(): + """Test metrics endpoint""" + client = app.test_client() + response = client.get('/metrics') + assert response.status_code == 200 + +# Add a simple test for the opensense module +def test_opensense_get_temperature(): + """Test that opensense.get_temperature returns a string""" + result = opensense.get_temperature() + assert isinstance(result, str) + assert "Average temperature:" in result From b17e836f15c1a0ae91b680a4e0f31c04943016e8 Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Thu, 19 Jun 2025 13:09:43 -0500 Subject: [PATCH 13/17] fix(ci): Added pytest.ini file for cleaner syntax --- pytest.ini | 7 +++++++ tests/test_modules.py | 4 ---- 2 files changed, 7 insertions(+), 4 deletions(-) create mode 100644 pytest.ini diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..d810fe3 --- /dev/null +++ b/pytest.ini @@ -0,0 +1,7 @@ +[tool:pytest] +testpaths = tests +pythonpath = . +python_files = test_*.py +python_classes = Test* +python_functions = test_* +addopts = --verbose --tb=short \ No newline at end of file diff --git a/tests/test_modules.py b/tests/test_modules.py index c9d0edb..8e68208 100644 --- a/tests/test_modules.py +++ b/tests/test_modules.py @@ -1,11 +1,7 @@ '''This module contains tests for the Flask and OpenSense modules.''' -import os -import sys from app.main import app from app import opensense -sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..')) - def test_app_exists(): """Test that the Flask app exists""" assert app is not None From 96c5e0d1351558668445716795890711b2b96267 Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Thu, 19 Jun 2025 13:12:12 -0500 Subject: [PATCH 14/17] fix(ci): Changes to pytest --- .github/workflows/sonarqube.yml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index 42cd394..dcc9bfa 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -34,10 +34,8 @@ jobs: - name: Run tests with coverage run: | - coverage run --source=app tests/test_modules.py - coverage xml - coverage report - + pytest --cov=app --cov-report=xml:coverage.xml --cov-report=term-missing tests/test_modules.py -v + - name: Analyze with SonarQube uses: SonarSource/sonarqube-scan-action@master env: From ed96dcbe38e1b40b3d3b139d7a3dc83b1d3caa0e Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Thu, 19 Jun 2025 13:13:57 -0500 Subject: [PATCH 15/17] fix(ci): Changes to pytest pt. 2 --- .github/workflows/sonarqube.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index dcc9bfa..8f57811 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -30,7 +30,7 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - pip install coverage pytest vcrpy + pip install coverage pytest pytest-cov vcrpy - name: Run tests with coverage run: | From 1ab2e906e0cbba96a8a29f46182b592b818376a8 Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Thu, 19 Jun 2025 13:18:56 -0500 Subject: [PATCH 16/17] fix(ci): Changes to pytest pt. 3 --- .github/workflows/sonarqube.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sonarqube.yml b/.github/workflows/sonarqube.yml index 8f57811..505cbcd 100644 --- a/.github/workflows/sonarqube.yml +++ b/.github/workflows/sonarqube.yml @@ -30,11 +30,15 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt - pip install coverage pytest pytest-cov vcrpy + pip install coverage pytest vcrpy - name: Run tests with coverage run: | - pytest --cov=app --cov-report=xml:coverage.xml --cov-report=term-missing tests/test_modules.py -v + export PYTHONPATH="${GITHUB_WORKSPACE}:${PYTHONPATH}" + coverage run --source=app -m pytest tests/test_modules.py -v + coverage xml -o coverage.xml + coverage report --show-missing + working-directory: ${{ github.workspace }} - name: Analyze with SonarQube uses: SonarSource/sonarqube-scan-action@master From 5b6dc90bb8f2231e42d412ecb55c6a734ffdac2e Mon Sep 17 00:00:00 2001 From: GabrielPalmar Date: Thu, 19 Jun 2025 13:28:07 -0500 Subject: [PATCH 17/17] fix(ci): Changes to pytest pt. 4 --- app/main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/main.py b/app/main.py index e9eaee7..df141fb 100644 --- a/app/main.py +++ b/app/main.py @@ -1,4 +1,5 @@ '''Module containing the main function of the app.''' +import os from flask import Flask, Response from prometheus_client import generate_latest, CONTENT_TYPE_LATEST from app import opensense @@ -8,8 +9,9 @@ @app.route('/version') def print_version(): '''Function printing the current version of the app.''' + version_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'version.txt') - with open('../version.txt', 'r', encoding="utf-8") as f: + with open(version_file, 'r', encoding="utf-8") as f: version = f.read() return f"Current app version: {version}\n"