Skip to content

Commit

Permalink
Merge pull request #518 from mozilla-iam/fix_tests
Browse files Browse the repository at this point in the history
Fix existing tests, pre-commit, and Github Actions
  • Loading branch information
dividehex authored Aug 19, 2024
2 parents 15f69a2 + 9272991 commit 22cd6a3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
15 changes: 11 additions & 4 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,18 @@ jobs:
STATUS_TITLE: Linting/Unittesting
STATUS_VALUE: ':link-run: *Running*'

- name: Install tox
run: pip install tox
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pre-commit tox
- name: Running Tox
run: tox
- name: Run pre-commit
run: pre-commit run --all-files

build:
name: Building
Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/pull_requests_only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: PR Linting / Unit Testing

on:
pull_request:
branches:
- '*'

permissions:
contents: 'read'

jobs:
lint:
name: Linting / Unit Testing
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: 'actions/checkout@v4'

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pre-commit tox
- name: Run pre-commit
run: pre-commit run --all-files
12 changes: 7 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
args: [--allow-multiple-documents]

- id: check-added-large-files

- repo: https://github.com/psf/black
rev: 22.10.0
- repo: local
hooks:
- id: black
- id: run-tox
name: Run tox tests
entry: tox
language: system
pass_filenames: false
23 changes: 14 additions & 9 deletions tests/test_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@
import dashboard.models.user as user


class TestUser(object):
def setup(self):
self.fixture_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), "data/userinfo.json")

self.session_fixture = json.loads(open(self.fixture_file).read())
self.good_apps_list = {"apps": []}

self.u = user.User(session=self.session_fixture, app_config=None)
self.u.api_token = "foo"
class TestUser:
def setup_method(self):
try:
self.fixture_file = os.path.join(os.path.abspath(os.path.dirname(__file__)), "data/userinfo.json")
with open(self.fixture_file) as f:
self.session_fixture = json.load(f)

self.good_apps_list = {"apps": []}

self.u = user.User(session=self.session_fixture, app_config=None)
self.u.api_token = "foo"
except (FileNotFoundError, json.JSONDecodeError, KeyError) as e:
self.u = None
raise RuntimeError(f"Failed to set up TestUser: {str(e)}")

def test_object_init(self):
assert self.u is not None
Expand Down
1 change: 1 addition & 0 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
env_list =
eslint, lint, py312
minversion = 4.6.0
skip_missing_interpreters = false

[testenv]
description = run the tests with pytest
Expand Down

0 comments on commit 22cd6a3

Please sign in to comment.