Add ai generated tests
This commit is contained in:
66
test/test_services/test_card_manager.py
Normal file
66
test/test_services/test_card_manager.py
Normal file
@@ -0,0 +1,66 @@
|
||||
import pytest
|
||||
from fastapi import status
|
||||
|
||||
|
||||
def test_add_card(client, auth_headers, test_group):
|
||||
"""Test adding a card to a group."""
|
||||
response = client.post(f"/cards/{test_group.id}", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
|
||||
data = response.json()
|
||||
assert "id" in data
|
||||
assert "uuid" in data
|
||||
assert data["group_id"] == test_group.id
|
||||
assert len(data["uuid"]) > 0 # UUID should be generated
|
||||
|
||||
|
||||
def test_add_card_to_nonexistent_group(client, auth_headers):
|
||||
"""Test adding a card to a non-existent group."""
|
||||
response = client.post("/cards/99999", headers=auth_headers)
|
||||
# This might succeed and create a card with a non-existent group_id
|
||||
# or fail depending on foreign key constraints
|
||||
# For now, let's assume it might fail
|
||||
# assert response.status_code == 404
|
||||
|
||||
|
||||
def test_delete_card(client, auth_headers, test_card):
|
||||
"""Test deleting a card."""
|
||||
response = client.delete(f"/cards/{test_card.id}", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
assert "deleted successfully" in response.json()["message"].lower()
|
||||
|
||||
|
||||
def test_delete_nonexistent_card(client, auth_headers):
|
||||
"""Test deleting a non-existent card."""
|
||||
response = client.delete("/cards/99999", headers=auth_headers)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_get_cards_for_group(client, auth_headers, test_group, test_card):
|
||||
"""Test getting all cards for a group."""
|
||||
response = client.get(f"/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("/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"/cards/{test_group.id}", headers=user_auth_headers)
|
||||
assert response.status_code == 403
|
||||
|
||||
# Try to get cards
|
||||
response = client.get(f"/cards/{test_group.id}", headers=user_auth_headers)
|
||||
assert response.status_code == 403
|
||||
Reference in New Issue
Block a user