Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore - fix tests to run w/o flask_sqlalchemy #993

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ jobs:
- name: update pip
run: |
python -m pip install -U pip
- name: nobabel, nowebauthn, noauthlib, async
- name: nobabel, nowebauthn, noauthlib, noflasksqlalchemy, async
run: |
pip install tox
tox -e nobabel,nowebauthn,noauthlib,async
tox -e nobabel,nowebauthn,noauthlib,noflasksqlalchemy,async
cov:
runs-on: ubuntu-latest
steps:
Expand Down
4 changes: 4 additions & 0 deletions examples/fsqlalchemy1/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Copyright 2019-2022 by J. Christopher Wagner (jwag). All rights reserved.
# flake8: noqa: F402
import pytest

pytest.importorskip("flask_sqlalchemy")

from fsqlalchemy1.app import Blog

Expand Down
2 changes: 2 additions & 0 deletions tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -1080,6 +1080,7 @@ def test_verifying_token_from_version_4x(app, client):

def test_change_token_uniquifier(app):
pytest.importorskip("sqlalchemy")
pytest.importorskip("flask_sqlalchemy")

# make sure that existing token no longer works once we change the token uniquifier
from sqlalchemy import Column, String
Expand Down Expand Up @@ -1133,6 +1134,7 @@ class User(db.Model, fsqla.FsUserMixin):

def test_null_token_uniquifier(app):
pytest.importorskip("sqlalchemy")
pytest.importorskip("flask_sqlalchemy")

# If existing record has a null fs_token_uniquifier, should be set on first use.
from sqlalchemy import Column, String
Expand Down
4 changes: 3 additions & 1 deletion tests/test_change_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@ def _on(app, **data):


@pytest.mark.settings(change_email_error_view="/change-email")
def test_ce(app, client, get_message):
def test_ce(app, clients, get_message):
client = clients

@change_email_confirmed.connect_via(app)
def _on(app, **kwargs):
assert kwargs["old_email"] == "[email protected]"
Expand Down
5 changes: 4 additions & 1 deletion tests/test_changeable.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
pytestmark = pytest.mark.changeable()


def test_changeable_flag(app, client, get_message):
def test_changeable_flag(app, clients, get_message):
client = clients
recorded = []

@password_changed.connect_via(app)
Expand Down Expand Up @@ -259,6 +260,8 @@ def test_change_invalidates_auth_token(app, client):


def test_auth_uniquifier(app):
pytest.importorskip("sqlalchemy")
pytest.importorskip("flask_sqlalchemy")
# If add fs_token_uniquifier to user model - change password shouldn't invalidate
# auth tokens.
from sqlalchemy import Column, String
Expand Down
4 changes: 3 additions & 1 deletion tests/test_datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def test_modify_permissions_multi(app, datastore):

def test_uuid(app, request, tmpdir, realdburl):
"""Test that UUID extension of postgresql works as a primary id for users"""
importorskip("sqlalchemy")
importorskip("flask_sqlalchemy")
import uuid
from flask_sqlalchemy import SQLAlchemy
from sqlalchemy import Boolean, Column, DateTime, Integer, ForeignKey, String
Expand Down Expand Up @@ -592,6 +592,7 @@ def test_mf_recovery_codes(app, datastore):

def test_permissions_fsqla_v2(app):
importorskip("sqlalchemy")
importorskip("flask_sqlalchemy")
# Make sure folks with fsqla_v2 work with new AsList column type
from sqlalchemy import insert
from flask_sqlalchemy import SQLAlchemy
Expand Down Expand Up @@ -641,6 +642,7 @@ class User(db.Model, fsqla.FsUserMixin):

def test_permissions_41(request, app, realdburl):
importorskip("sqlalchemy")
importorskip("flask_sqlalchemy")
# Check compatibility with 4.1 DB
from sqlalchemy import Column, insert
from flask_sqlalchemy import SQLAlchemy
Expand Down
5 changes: 3 additions & 2 deletions tests/test_recovery_codes.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

recovery code tests

:copyright: (c) 2022-2023 by J. Christopher Wagner (jwag).
:copyright: (c) 2022-2024 by J. Christopher Wagner (jwag).
:license: MIT, see LICENSE for more details.
"""

Expand All @@ -24,9 +24,10 @@


@pytest.mark.settings(multi_factor_recovery_codes=True)
def test_rc_json(app, client, get_message):
def test_rc_json(app, clients, get_message):
# Test recovery codes
# gal has two-factor already setup for 'sms'
client = clients
headers = {"Accept": "application/json", "Content-Type": "application/json"}
tf_authenticate(app, client)

Expand Down
3 changes: 2 additions & 1 deletion tests/test_registerable.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,8 @@ def test_form_error(app, client, get_message):

@pytest.mark.settings(username_enable=True)
@pytest.mark.unified_signin()
def test_username(app, client, get_message):
def test_username(app, clients, get_message):
client = clients
data = dict(
email="[email protected]",
username="dude",
Expand Down
8 changes: 6 additions & 2 deletions tests/test_two_factor.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,9 +305,10 @@ def test_two_factor_illegal_state(app, client, get_message):


@pytest.mark.settings(two_factor_required=True)
def test_two_factor_flag(app, client, get_message):
def test_two_factor_flag(app, clients, get_message):
# trying to verify code without going through two-factor
# first login function
client = clients
wrong_code = b"000000"
response = client.post(
"/tf-validate", data=dict(code=wrong_code), follow_redirects=True
Expand Down Expand Up @@ -1113,8 +1114,9 @@ def test_admin_setup_reset(app, client, get_message):


@pytest.mark.settings(two_factor_required=True)
def test_datastore(app, client, get_message):
def test_datastore(app, clients, get_message):
# Test that user record is properly set after proper 2FA setup.
client = clients
sms_sender = SmsSenderFactory.createSender("test")
data = dict(email="[email protected]", password="password")
response = client.post(
Expand Down Expand Up @@ -1335,6 +1337,7 @@ def test_bad_sender(app, client, get_message):

def test_replace_send_code(app, get_message):
pytest.importorskip("sqlalchemy")
pytest.importorskip("flask_sqlalchemy")

# replace tf_send_code - and have it return an error to check that.
from flask_sqlalchemy import SQLAlchemy
Expand Down Expand Up @@ -1489,6 +1492,7 @@ def test_setup_nofresh(app, client, get_message):
@pytest.mark.settings(two_factor_enabled_methods=["email"])
def test_no_sms(app, get_message):
pytest.importorskip("sqlalchemy")
pytest.importorskip("flask_sqlalchemy")

# Make sure that don't require tf_phone_number if SMS isn't an option.
from sqlalchemy import (
Expand Down
7 changes: 5 additions & 2 deletions tests/test_unified_signin.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,8 @@ def test_verify_link_spa(app, client, get_message):
assert is_authenticated(client, get_message)


def test_setup(app, client, get_message):
def test_setup(app, clients, get_message):
client = clients
set_email(app)
us_authenticate(client)
response = client.get("us-setup")
Expand Down Expand Up @@ -1005,7 +1006,8 @@ def test_unique_phone(app, client, get_message):


@pytest.mark.settings(freshness=timedelta(minutes=0))
def test_verify(app, client, get_message):
def test_verify(app, clients, get_message):
client = clients
# Test setup when re-authenticate required
# With freshness set to 0 - the first call should require reauth (by
# redirecting); but the second should work due to grace period.
Expand Down Expand Up @@ -1659,6 +1661,7 @@ def test_bad_sender(app, client, get_message):
@pytest.mark.registerable()
def test_replace_send_code(app, get_message):
pytest.importorskip("sqlalchemy")
pytest.importorskip("flask_sqlalchemy")

from flask_sqlalchemy import SQLAlchemy
from flask_security.models import fsqla_v2 as fsqla
Expand Down
20 changes: 10 additions & 10 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[tox]
basepython = python3.11
envlist =
py{39,310,311,312,py39}-{low,release}
mypy
Expand All @@ -10,7 +11,7 @@ envlist =
docs
coverage
makedist
skip_missing_interpreters = true
skip_missing_interpreters = false

[testenv]
allowlist_externals = tox
Expand Down Expand Up @@ -52,7 +53,6 @@ commands =
pytest --basetemp={envtmpdir} {posargs:tests}

[testenv:async]
basepython = python3.11
deps =
-r requirements/tests.txt
commands =
Expand All @@ -61,7 +61,6 @@ commands =
pytest --basetemp={envtmpdir} {posargs:tests}

[testenv:nowebauthn]
basepython = python3.9
deps =
-r requirements/tests.txt
commands =
Expand All @@ -70,38 +69,41 @@ commands =
pytest --basetemp={envtmpdir} {posargs:tests}

[testenv:nobabel]
basepython = python3.9
deps =
-r requirements/tests.txt
commands =
pip uninstall -y babel flask_babel
pytest --basetemp={envtmpdir} {posargs:tests}

[testenv:noauthlib]
basepython = python3.9
deps =
-r requirements/tests.txt
commands =
pip uninstall -y authlib
tox -e compile_catalog
pytest --basetemp={envtmpdir} {posargs:tests}

[testenv:noflasksqlalchemy]
deps =
-r requirements/tests.txt
commands =
pip uninstall -y flask_sqlalchemy
tox -e compile_catalog
pytest --basetemp={envtmpdir} {posargs:tests}

[testenv:style]
basepython = python3.11
deps = pre-commit
skip_install = true
commands =
pre-commit autoupdate
pre-commit run --all-files --show-diff-on-failure

[testenv:docs]
basepython = python3.11
deps = -r requirements/docs.txt
commands = sphinx-build -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html


[testenv:coverage]
basepython = python3.11
deps =
-r requirements/tests.txt
commands =
Expand All @@ -119,7 +121,6 @@ commands =
pytest --basetemp={envtmpdir} {posargs}

[testenv:makedist]
basepython = python3.11
deps =
-r requirements/tests.txt
build
Expand All @@ -132,7 +133,6 @@ commands =
check-wheel-contents dist

[testenv:mypy]
basepython = python3.11
deps =
-r requirements/tests.txt
types-setuptools
Expand Down
Loading