Remove session protecting during testing
continuous-integration/drone/push Build is failing Details

master
Drew Bednar 1 year ago
parent 4bab4b8499
commit f7e9e680a7

@ -12,7 +12,7 @@ Session = sessionmaker(engine)
# Configure Authentication
login_manager = LoginManager()
login_manager.session_protection = "strong"
login_manager.session_protection = "basic"
login_manager.login_view = "user.user_login"

@ -5,6 +5,7 @@ from flask_login.test_client import FlaskLoginClient
from htmx_contact import create_app
from htmx_contact.config import ContactSettings
from htmx_contact.models import Contact
from htmx_contact.models import User
@ -18,6 +19,36 @@ def test_user():
return User(id=1, primary_email="test", password="test", username="test")
@pytest.fixture()
def test_contacts(test_user):
return [
Contact(
id=1,
user_id=test_user.id,
first_name="Mark",
last_name="Zuckerberg",
email="zuck@facebook.com",
phone="555-777-1337",
),
Contact(
id=2,
user_id=test_user.id,
first_name="Shaan",
last_name="Puri",
email="shaan@twitter.com",
phone="666-777-1337",
),
Contact(
id=3,
user_id=test_user.id,
first_name="Sam",
last_name="Par",
email="sam@thesampar.com",
phone="587-343-1337",
),
]
@pytest.fixture()
def app(test_config):
app = create_app(config=test_config)
@ -25,6 +56,8 @@ def app(test_config):
app.config.update(
{
"TESTING": True,
# disbale session protection or session "freshness" will cause failures.
"SESSION_PROTECTION": None,
}
)
@ -42,7 +75,8 @@ def anynomous_client(app):
@pytest.fixture()
def client(app, test_user):
return app.test_client(user=test_user)
with app.test_client(user=test_user) as client:
yield client
@pytest.fixture()

@ -13,6 +13,18 @@ def test_login_get_contacts(anynomous_client):
assert response.status_code == 302
def test_contacts(client, test_contacts):
mock_session_instance = Mock()
mock_session_instance.configure_mock(**{"scalars.return_value.all.return_value": test_contacts})
with patch("htmx_contact.main.Session") as sqla_session:
sqla_session.configure_mock(**{"return_value.__enter__.return_value": mock_session_instance})
response = client.get("/contacts")
assert response.status_code == 200
# check they all are in there
for contact in test_contacts:
assert contact.first_name in response.text
def test_get_contacts(client):
with client.session_transaction() as session:
response = client.get("/contacts", follow_redirects=True)

Loading…
Cancel
Save