[Tests] Fix various tests
add new fields to card tests; stop test_get_session from writing into prod db
This commit is contained in:
@@ -99,7 +99,7 @@ def test_group(db_session):
|
||||
@pytest.fixture
|
||||
def test_card(db_session, test_group):
|
||||
"""Create a test card."""
|
||||
card = Card(key="test-key-123", group_id=test_group.id)
|
||||
card = Card(key="test-key-123", group_id=test_group.id, enabled=True, name="test_card", card_serial="00:00:00:00:00:00:00")
|
||||
db_session.add(card)
|
||||
db_session.commit()
|
||||
db_session.refresh(card)
|
||||
|
||||
@@ -23,7 +23,7 @@ def test_get_cards_for_nonexistent_group(client, auth_headers):
|
||||
def test_card_operations_by_non_admin(client, test_group, user_auth_headers):
|
||||
"""Test that non-admin users cannot perform card operations."""
|
||||
# Try to add a card
|
||||
response = client.post(f"/api/v1/cards/{test_group.id}", headers=user_auth_headers)
|
||||
response = client.post(f"/api/v1/cards/", headers=user_auth_headers)
|
||||
assert response.status_code == 403
|
||||
|
||||
# Try to get cards
|
||||
|
||||
@@ -26,25 +26,16 @@ def test_create_db_and_tables():
|
||||
def test_get_session(db_session):
|
||||
"""Test database session generator."""
|
||||
# Test that we can get a session
|
||||
session_gen = get_session()
|
||||
session = next(session_gen)
|
||||
|
||||
assert isinstance(session, Session)
|
||||
assert isinstance(db_session, Session)
|
||||
|
||||
# Test that session works
|
||||
user = UserDB(name="Test", passwordhash="hash")
|
||||
session.add(user)
|
||||
session.commit()
|
||||
user = UserDB(name="Test_User", passwordhash="hash")
|
||||
db_session.add(user)
|
||||
db_session.commit()
|
||||
|
||||
retrieved_user = session.get(UserDB, user.id)
|
||||
retrieved_user = db_session.get(UserDB, user.id)
|
||||
assert retrieved_user is not None
|
||||
assert retrieved_user.name == "Test"
|
||||
|
||||
# Clean up generator
|
||||
try:
|
||||
next(session_gen)
|
||||
except StopIteration:
|
||||
pass
|
||||
assert retrieved_user.name == "Test_User"
|
||||
|
||||
|
||||
def test_add_and_refresh(db_session):
|
||||
|
||||
@@ -9,7 +9,7 @@ def test_check_access_with_valid_timetable(db_session):
|
||||
db_session.add(group)
|
||||
db_session.commit()
|
||||
|
||||
card = Card(key="test-key-123", group_id=group.id)
|
||||
card = Card(key="test-key-123", group_id=group.id, enabled=True, name="test_card", card_serial="00:00:00:00:00:00:00")
|
||||
db_session.add(card)
|
||||
|
||||
timetable = Timetable(
|
||||
@@ -36,7 +36,7 @@ def test_check_access_outside_hours(db_session):
|
||||
db_session.add(group)
|
||||
db_session.commit()
|
||||
|
||||
card = Card(key="test-key-123", group_id=group.id)
|
||||
card = Card(key="test-key-123", group_id=group.id, enabled=True, name="test_card", card_serial="00:00:00:00:00:00:00")
|
||||
db_session.add(card)
|
||||
|
||||
timetable = Timetable(
|
||||
|
||||
Reference in New Issue
Block a user