From 172faf48d65a397a7d7c3a3eb1f45907babc4a1e Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 4 Oct 2023 10:32:10 +0200 Subject: [PATCH 1/3] CI - stop job w/ pytest on first failure --- .github/workflows/.tests-python.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/.tests-python.yml b/.github/workflows/.tests-python.yml index 926dd18a..fce20dc2 100644 --- a/.github/workflows/.tests-python.yml +++ b/.github/workflows/.tests-python.yml @@ -54,7 +54,7 @@ jobs: if: matrix.python-version == '3.11' run: mypy fittrackee - name: Pytest - run: pytest fittrackee -p no:warnings --cov fittrackee --cov-report term-missing + run: pytest fittrackee -p no:warnings --cov fittrackee --cov-report term-missing --maxfail=1 postgresql: name: postgresql ${{ matrix.psql-version }} (python 3.11) @@ -84,7 +84,7 @@ jobs: poetry config virtualenvs.create false poetry install --no-interaction --quiet - name: Pytest - run: pytest fittrackee -p no:warnings --cov fittrackee --cov-report term-missing + run: pytest fittrackee -p no:warnings --cov fittrackee --cov-report term-missing --maxfail=1 end2end: name: e2e tests @@ -129,7 +129,7 @@ jobs: export TEST_APP_URL=http://$(hostname --ip-address):5000 sleep 5 nohup flask worker --processes=1 >> nohup.out 2>&1 & - pytest e2e --driver Remote --capability browserName firefox --selenium-host selenium --selenium-port 4444 + pytest e2e --driver Remote --capability browserName firefox --selenium-host selenium --selenium-port 4444 --maxfail=1 end2end_package: name: e2e tests with package @@ -182,7 +182,7 @@ jobs: export TEST_APP_URL=http://$(hostname --ip-address):5000 sleep 5 nohup flask worker --processes=1 >> nohup.out 2>&1 & - pytest e2e --driver Remote --capability browserName firefox --selenium-host selenium --selenium-port 4444 + pytest e2e --driver Remote --capability browserName firefox --selenium-host selenium --selenium-port 4444 --maxfail=1 end2end_package_update: name: e2e tests after update @@ -239,4 +239,4 @@ jobs: export TEST_APP_URL=http://$(hostname --ip-address):5000 sleep 5 nohup flask worker --processes=1 >> nohup.out 2>&1 & - pytest e2e --driver Remote --capability browserName firefox --selenium-host selenium --selenium-port 4444 \ No newline at end of file + pytest e2e --driver Remote --capability browserName firefox --selenium-host selenium --selenium-port 4444 --maxfail=1 \ No newline at end of file From e75a7f3f9d7c42b6e95ec6775b40b6e53a43b23f Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 4 Oct 2023 10:38:22 +0200 Subject: [PATCH 2/3] CI - run jobs only on push or PR from forks --- .github/workflows/.tests-javascript.yml | 2 ++ .github/workflows/.tests-python.yml | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/.tests-javascript.yml b/.github/workflows/.tests-javascript.yml index 6b56f99e..66d222a0 100644 --- a/.github/workflows/.tests-javascript.yml +++ b/.github/workflows/.tests-javascript.yml @@ -5,12 +5,14 @@ on: paths: ['fittrackee_client/**'] pull_request: paths: ['fittrackee_client/**'] + types: [opened, synchronize, reopened] env: working-directory: fittrackee_client jobs: javascript: + if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.fork }} runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 diff --git a/.github/workflows/.tests-python.yml b/.github/workflows/.tests-python.yml index fce20dc2..8de726d1 100644 --- a/.github/workflows/.tests-python.yml +++ b/.github/workflows/.tests-python.yml @@ -2,9 +2,10 @@ name: Python CI on: push: - paths-ignore: ['docs/**', 'docsrc/**', 'fittrackee_client/**', '*.md'] + paths-ignore: ['docs/**', 'docsrc/**', 'docker/**', 'fittrackee_client/**', '*.md'] pull_request: - paths-ignore: ['docs/**', 'docsrc/**', 'fittrackee_client/**', '*.md'] + paths-ignore: ['docs/**', 'docsrc/**', 'docker/**', 'fittrackee_client/**', '*.md'] + types: [opened, synchronize, reopened] env: APP_SETTINGS: fittrackee.config.TestingConfig @@ -15,6 +16,7 @@ env: jobs: python: + if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.fork }} name: python ${{ matrix.python-version }} (postgresql 15) runs-on: ubuntu-latest container: python:${{ matrix.python-version }} @@ -57,6 +59,7 @@ jobs: run: pytest fittrackee -p no:warnings --cov fittrackee --cov-report term-missing --maxfail=1 postgresql: + if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.fork }} name: postgresql ${{ matrix.psql-version }} (python 3.11) runs-on: ubuntu-latest container: python:3.11 @@ -87,6 +90,7 @@ jobs: run: pytest fittrackee -p no:warnings --cov fittrackee --cov-report term-missing --maxfail=1 end2end: + if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.fork }} name: e2e tests runs-on: ubuntu-latest needs: ["python"] @@ -132,6 +136,7 @@ jobs: pytest e2e --driver Remote --capability browserName firefox --selenium-host selenium --selenium-port 4444 --maxfail=1 end2end_package: + if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.fork }} name: e2e tests with package runs-on: ubuntu-latest needs: ["python"] @@ -185,6 +190,7 @@ jobs: pytest e2e --driver Remote --capability browserName firefox --selenium-host selenium --selenium-port 4444 --maxfail=1 end2end_package_update: + if: ${{ github.event_name == 'push' || github.event.pull_request.head.repo.fork }} name: e2e tests after update runs-on: ubuntu-latest needs: ["python"] From 5ee89bc15e83fb1950a381b613273b2e261ebbbc Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 4 Oct 2023 10:39:31 +0200 Subject: [PATCH 3/3] API - update tests config --- fittrackee/config.py | 4 ++-- fittrackee/tests/users/test_auth_api.py | 6 +++--- fittrackee/tests/users/test_users_model.py | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/fittrackee/config.py b/fittrackee/config.py index 1f70d123..e1479b54 100644 --- a/fittrackee/config.py +++ b/fittrackee/config.py @@ -97,8 +97,8 @@ class TestingConfig(BaseConfig): SECRET_KEY = 'test key' # nosec BCRYPT_LOG_ROUNDS = 4 TOKEN_EXPIRATION_DAYS = 0 - TOKEN_EXPIRATION_SECONDS = 3 - PASSWORD_TOKEN_EXPIRATION_SECONDS = 3 + TOKEN_EXPIRATION_SECONDS = 60 + PASSWORD_TOKEN_EXPIRATION_SECONDS = 60 UI_URL = 'http://0.0.0.0:5000' SENDER_EMAIL = 'fittrackee@example.com' OAUTH2_TOKEN_EXPIRES_IN = { diff --git a/fittrackee/tests/users/test_auth_api.py b/fittrackee/tests/users/test_auth_api.py index 8247444b..c26b1ea2 100644 --- a/fittrackee/tests/users/test_auth_api.py +++ b/fittrackee/tests/users/test_auth_api.py @@ -2128,7 +2128,7 @@ class TestPasswordResetRequest(ApiTestCaseMixin): 'email': user_1.email, }, { - 'expiration_delay': '3 seconds', + 'expiration_delay': 'a minute', 'username': user_1.username, 'password_reset_url': ( f'http://0.0.0.0:5000/password-reset?token={token}' @@ -2235,7 +2235,7 @@ class TestPasswordUpdate(ApiTestCaseMixin): token = get_user_token(user_1.id, password_reset=True) client = app.test_client() - with freeze_time(now + timedelta(seconds=4)): + with freeze_time(now + timedelta(seconds=61)): response = client.post( '/api/auth/password/update', data=json.dumps( @@ -2649,7 +2649,7 @@ class TestUserLogout(ApiTestCaseMixin): client, auth_token = self.get_test_client_and_auth_token( app, user_1.email ) - with freeze_time(now + timedelta(seconds=4)): + with freeze_time(now + timedelta(seconds=61)): response = client.post( '/api/auth/logout', headers=dict(Authorization=f'Bearer {auth_token}'), diff --git a/fittrackee/tests/users/test_users_model.py b/fittrackee/tests/users/test_users_model.py index 2ca2440e..c1e9ddfc 100644 --- a/fittrackee/tests/users/test_users_model.py +++ b/fittrackee/tests/users/test_users_model.py @@ -376,7 +376,7 @@ class TestUserModelToken: ) -> None: auth_token = user_1.encode_auth_token(user_1.id) now = datetime.utcnow() - with freeze_time(now + timedelta(seconds=4)): + with freeze_time(now + timedelta(seconds=61)): assert ( User.decode_auth_token(auth_token) == 'signature expired, please log in again'