75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
import pytest
|
|
from fastapi import status
|
|
|
|
def test_get_cards_for_group(client, auth_headers, test_group, test_card):
|
|
"""Test getting all cards for a group."""
|
|
response = client.get(f"/api/v1/cards/{test_group.id}", headers=auth_headers)
|
|
assert response.status_code == 200
|
|
|
|
cards = response.json()
|
|
assert len(cards) >= 1
|
|
assert any(card["id"] == test_card.id for card in cards)
|
|
|
|
|
|
def test_get_cards_for_nonexistent_group(client, auth_headers):
|
|
"""Test getting cards for a non-existent group."""
|
|
response = client.get("/api/v1/cards/99999", headers=auth_headers)
|
|
assert response.status_code == 200
|
|
|
|
cards = response.json()
|
|
assert len(cards) == 0 # Empty list for non-existent group
|
|
|
|
|
|
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/", headers=user_auth_headers)
|
|
assert response.status_code == 403
|
|
|
|
# Try to get cards
|
|
response = client.get(f"/api/v1/cards/{test_group.id}", headers=user_auth_headers)
|
|
assert response.status_code == 403
|
|
|
|
def test_update_card(client, auth_headers, test_group, test_card):
|
|
"""Test Patching a card entity"""
|
|
update_data = {
|
|
"name": "changed_name",
|
|
"enabled": "False"
|
|
}
|
|
|
|
response = client.patch(
|
|
f"/api/v1/cards/{test_card.id}",
|
|
json=update_data,
|
|
headers=auth_headers
|
|
)
|
|
assert response.status_code == 200
|
|
|
|
data = response.json()
|
|
assert data["name"] == "changed_name"
|
|
assert data["enabled"] == False
|
|
assert data["group_id"] == test_card.group_id
|
|
|
|
def test_update_wrong_card(client, auth_headers, test_group, test_card):
|
|
"""Test Patching a card entity"""
|
|
|
|
response = client.patch(
|
|
f"/api/v1/cards/9999",
|
|
json={},
|
|
headers=auth_headers
|
|
)
|
|
assert response.status_code == 404
|
|
assert "Card not found" in response.json()["detail"]
|
|
|
|
def test_update_card_with_wrong_group(client, auth_headers, test_group, test_card):
|
|
"""Test Patching a card entity with wrong group"""
|
|
update_data = {
|
|
"group_id": "9999"
|
|
}
|
|
|
|
response = client.patch(
|
|
f"/api/v1/cards/{test_card.id}",
|
|
json=update_data,
|
|
headers=auth_headers
|
|
)
|
|
assert response.status_code == 404
|
|
assert "GroupID not found" in response.json()["detail"] |