This commit is contained in:
Iliyan Angelov
2025-12-05 17:43:03 +02:00
parent e1988fe37a
commit 13c91f95f4
51 changed files with 11933 additions and 289 deletions

View File

@@ -121,6 +121,32 @@ def test_staff_role(db_session):
return role
@pytest.fixture
def test_accountant_role(db_session):
"""Create an accountant role."""
role = Role(
name="accountant",
description="Accountant role"
)
db_session.add(role)
db_session.commit()
db_session.refresh(role)
return role
@pytest.fixture
def test_housekeeping_role(db_session):
"""Create a housekeeping role."""
role = Role(
name="housekeeping",
description="Housekeeping role"
)
db_session.add(role)
db_session.commit()
db_session.refresh(role)
return role
@pytest.fixture
def test_user(db_session, test_role):
"""Create a test user."""
@@ -175,6 +201,42 @@ def test_staff_user(db_session, test_staff_role):
return user
@pytest.fixture
def test_accountant_user(db_session, test_accountant_role):
"""Create a test accountant user."""
hashed_password = bcrypt.hashpw("accountantpassword123".encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
user = User(
email="accountant@example.com",
password=hashed_password,
full_name="Accountant User",
phone="1234567890",
role_id=test_accountant_role.id,
is_active=True
)
db_session.add(user)
db_session.commit()
db_session.refresh(user)
return user
@pytest.fixture
def test_housekeeping_user(db_session, test_housekeeping_role):
"""Create a test housekeeping user."""
hashed_password = bcrypt.hashpw("housekeepingpassword123".encode('utf-8'), bcrypt.gensalt()).decode('utf-8')
user = User(
email="housekeeping@example.com",
password=hashed_password,
full_name="Housekeeping User",
phone="1234567890",
role_id=test_housekeeping_role.id,
is_active=True
)
db_session.add(user)
db_session.commit()
db_session.refresh(user)
return user
@pytest.fixture
def auth_token(client, test_user):
"""Get authentication token for test user (from cookies)."""
@@ -227,6 +289,38 @@ def staff_token(client, test_staff_user):
return None
@pytest.fixture
def accountant_token(client, test_accountant_user):
"""Get authentication token for accountant user (from cookies)."""
response = client.post(
"/api/auth/login",
json={
"email": "accountant@example.com",
"password": "accountantpassword123"
}
)
if response.status_code == 200:
cookie_token = response.cookies.get("accessToken")
return cookie_token
return None
@pytest.fixture
def housekeeping_token(client, test_housekeeping_user):
"""Get authentication token for housekeeping user (from cookies)."""
response = client.post(
"/api/auth/login",
json={
"email": "housekeeping@example.com",
"password": "housekeepingpassword123"
}
)
if response.status_code == 200:
cookie_token = response.cookies.get("accessToken")
return cookie_token
return None
@pytest.fixture
def authenticated_client(client, test_user):
"""Create an authenticated test client (uses cookies)."""
@@ -257,6 +351,32 @@ def admin_client(client, test_admin_user):
return client
@pytest.fixture
def accountant_client(client, test_accountant_user):
"""Create an authenticated accountant test client (uses cookies)."""
response = client.post(
"/api/auth/login",
json={
"email": "accountant@example.com",
"password": "accountantpassword123"
}
)
return client
@pytest.fixture
def housekeeping_client(client, test_housekeeping_user):
"""Create an authenticated housekeeping test client (uses cookies)."""
response = client.post(
"/api/auth/login",
json={
"email": "housekeeping@example.com",
"password": "housekeepingpassword123"
}
)
return client
@pytest.fixture
def test_room_type(db_session):
"""Create a test room type."""