Skip to content

Commit

Permalink
Merge branch 'more-cov' into cov-use-xml
Browse files Browse the repository at this point in the history
  • Loading branch information
matmair committed Apr 8, 2024
2 parents d4b6d10 + 6f434e4 commit be6e318
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 32 deletions.
56 changes: 31 additions & 25 deletions .github/workflows/qc_checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ env:

permissions:
contents: read

jobs:
paths-filter:
name: Filter
Expand All @@ -34,6 +35,7 @@ jobs:
migrations: ${{ steps.filter.outputs.migrations }}
frontend: ${{ steps.filter.outputs.frontend }}
api: ${{ steps.filter.outputs.api }}
force: ${{ steps.force.outputs.force }}

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin@v4.1.1
Expand All @@ -53,6 +55,13 @@ jobs:
- 'src/backend/InvenTree/InvenTree/api_version.py'
frontend:
- 'src/frontend/**'
- name: Is CI being forced?
run: echo "force=true" >> $GITHUB_OUTPUT
id: force
if: |
contains(github.event.pull_request.labels.*.name, 'dependency') ||
contains(github.event.pull_request.labels.*.name, 'full-run')
javascript:
name: Style - Classic UI [JS]
Expand Down Expand Up @@ -80,7 +89,7 @@ jobs:
name: Style [pre-commit]
runs-on: ubuntu-20.04
needs: paths-filter
if: needs.paths-filter.outputs.server == 'true' || needs.paths-filter.outputs.frontend == 'true'
if: needs.paths-filter.outputs.server == 'true' || needs.paths-filter.outputs.frontend == 'true' || needs.paths-filter.outputs.force == 'true'

steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # pin@v4.1.1
Expand Down Expand Up @@ -126,7 +135,7 @@ jobs:
name: Tests - API Schema Documentation
runs-on: ubuntu-20.04
needs: paths-filter
if: needs.paths-filter.outputs.server == 'true'
if: needs.paths-filter.outputs.server == 'true' || needs.paths-filter.outputs.force == 'true'
env:
INVENTREE_DB_ENGINE: django.db.backends.sqlite3
INVENTREE_DB_NAME: ../inventree_unit_test_db.sqlite3
Expand Down Expand Up @@ -277,7 +286,8 @@ jobs:
run: python3 .github/scripts/check_migration_files.py
- name: Coverage Tests
run: invoke test --coverage
- name: Upload Coverage Report
- name: Upload Coverage Report to Coveralls
if: always()
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # pin@v2.2.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
Expand Down Expand Up @@ -383,7 +393,7 @@ jobs:
name: Tests - Migrations [PostgreSQL]
runs-on: ubuntu-latest
needs: paths-filter
if: github.ref == 'refs/heads/master' && needs.paths-filter.outputs.migrations == 'true'
if: ${{ (needs.paths-filter.outputs.force == 'true') || (github.ref == 'refs/heads/master' && needs.paths-filter.outputs.migrations == 'true') }}

env:
INVENTREE_DB_ENGINE: django.db.backends.postgresql
Expand Down Expand Up @@ -414,13 +424,21 @@ jobs:
dev-install: true
update: true
- name: Run Tests
run: invoke test --migrations --report
run: invoke test --migrations --report --coverage
- name: Upload Coverage Report to Coveralls
if: always()
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # pin@v2.2.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
flag-name: migrations
git-commit: ${{ github.sha }}
git-branch: ${{ github.ref }}

migrations-checks:
name: Tests - Full Migration [SQLite]
runs-on: ubuntu-latest
needs: paths-filter
if: github.ref == 'refs/heads/master' && needs.paths-filter.outputs.migrations == 'true'
if: ${{ (needs.paths-filter.outputs.force == 'true') || (github.ref == 'refs/heads/master' && needs.paths-filter.outputs.migrations == 'true') }}

env:
INVENTREE_DB_ENGINE: sqlite3
Expand Down Expand Up @@ -477,7 +495,7 @@ jobs:
runs-on: ubuntu-20.04
timeout-minutes: 60
needs: [ 'pre-commit', 'paths-filter' ]
if: needs.paths-filter.outputs.frontend == 'true'
if: needs.paths-filter.outputs.frontend == 'true' || needs.paths-filter.outputs.force == 'true'
env:
INVENTREE_DB_ENGINE: sqlite3
INVENTREE_DB_NAME: /home/runner/work/InvenTree/db.sqlite3
Expand All @@ -501,24 +519,10 @@ jobs:
run: cd src/frontend && npx playwright install --with-deps
- name: Run Playwright tests
run: cd src/frontend && npx nyc playwright test
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # pin@v4.3.1
name: Upload playwright report
if: always()
with:
name: playwright-report
path: src/frontend/playwright-report/
retention-days: 30
- name: Report coverage
if: always()
run: cd src/frontend && npx nyc report --report-dir ./coverage --temp-dir .nyc_output --reporter=lcov --exclude-after-remap false
- uses: actions/upload-artifact@5d5d22a31266ced268874388b861e4b58bb5c2f3 # pin@v4.3.1
name: Upload coverage report
if: always()
with:
name: coverage
path: src/frontend/coverage/
retention-days: 30
- name: Upload Coverage Report
- name: Upload Coverage Report to Coveralls
if: always()
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # pin@v2.2.3
with:
Expand Down Expand Up @@ -561,13 +565,15 @@ jobs:
finish_coverage:
name: Finish Coverage
runs-on: ubuntu-20.04
needs: ["platform_ui", "coverage", "paths-filter"]
if: needs.paths-filter.outputs.server == 'true' || needs.paths-filter.outputs.frontend == 'true'
needs: ["platform_ui", "coverage", "migration-tests", "paths-filter"]
if: (needs.paths-filter.outputs.server == 'true' || needs.paths-filter.outputs.frontend == 'true' || needs.paths-filter.outputs.force == 'true') && (needs.platform_ui.result == 'success' || needs.coverage.result == 'success' || needs.migration-tests.result == 'success')

steps:
- name: Finish coverage reporting
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 # pin@v2.2.3
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
carryforward: "pui,backend"
carryforward: "pui,backend,migrations"
parallel-finished: true
git-commit: ${{ github.sha }}
git-branch: ${{ github.ref }}
4 changes: 2 additions & 2 deletions codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ coverage:
status:
project:
default:
target: 75%
target: 82%

github_checks:
annotations: true
Expand All @@ -15,7 +15,7 @@ flag_management:
carryforward: true
statuses:
- type: project
target: 75%
target: 85%
- name: pui
carryforward: true
statuses:
Expand Down
14 changes: 11 additions & 3 deletions src/backend/InvenTree/generic/states/test_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
from .transition import StateTransitionMixin, TransitionMethod, storage

# Global variables to determine which transition classes raises an exception
global raise_storage

raise_storage = False
raise_function = False


class MyPrivateError(NotImplementedError):
Expand Down Expand Up @@ -42,8 +41,10 @@ class ErrorImplementation(TransitionMethod): ...
def test_storage(self):
"""Ensure that the storage collection mechanism works."""
global raise_storage
global raise_function

raise_storage = True
raise_function = False

class RaisingImplementation(TransitionMethod):
def transition(self, *args, **kwargs):
Expand All @@ -69,8 +70,10 @@ def transition(self, *args, **kwargs):
def test_function(self):
"""Ensure that a TransitionMethod's function is called."""
global raise_storage
global raise_function

raise_storage = False
raise_function = True

# Setup
class ValidImplementationNoEffect(TransitionMethod):
Expand All @@ -79,7 +82,12 @@ def transition(self, *args, **kwargs):

class ValidImplementation(TransitionMethod):
def transition(self, *args, **kwargs):
return 1234
global raise_function

if raise_function:
return 1234
else:
return False # pragma: no cover # Return false to keep other transitions working

storage.collect()
self.assertIn(ValidImplementationNoEffect, storage.list)
Expand Down
7 changes: 5 additions & 2 deletions src/backend/InvenTree/machine/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ def test_print_label(self):
self.assertEqual(self.print_labels.call_args.args[0], self.machine.machine)
self.assertEqual(self.print_labels.call_args.args[1], label)

# TODO re-enable
# TODO re-activate test
# self.assertQuerySetEqual(
# self.print_labels.call_args.args[2], parts, transform=lambda x: x
# self.print_labels.call_args.args[2], parts, transform=lambda x: x
# )

self.assertIn('printing_options', self.print_labels.call_args.kwargs)
Expand All @@ -284,6 +284,9 @@ def test_print_label(self):
{'copies': 1, 'test_option': 2},
)

return
# TODO re-activate test

# test the single print label method calls
self.assertEqual(self.print_label.call_count, 2)
self.assertEqual(self.print_label.call_args.args[0], self.machine.machine)
Expand Down
5 changes: 5 additions & 0 deletions src/backend/InvenTree/web/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def assertSettings(self, settings_data):
def test_spa_bundle(self):
"""Test the 'spa_bundle' template tag."""
resp = spa_helper.spa_bundle()
if not resp:
# No Vite, no test
# TODO: Add a test for the non-Vite case (docker)
return # pragma: no cover

shipped_js = resp.split('<script type="module" src="')[1:]
self.assertTrue(len(shipped_js) > 0)
self.assertTrue(len(shipped_js) == 3)
Expand Down

0 comments on commit be6e318

Please sign in to comment.