All checks were successful
CI/CD Pipeline / VM Test - security (push) Successful in 7s
CI/CD Pipeline / Backend Linting (push) Successful in 4s
CI/CD Pipeline / VM Test - backend-integration (push) Successful in 11s
CI/CD Pipeline / VM Test - full-stack (push) Successful in 8s
CI/CD Pipeline / VM Test - performance (push) Successful in 8s
CI/CD Pipeline / Nix Flake Check (push) Successful in 38s
CI/CD Pipeline / CI Summary (push) Successful in 0s
CI/CD Pipeline / Frontend Linting (push) Successful in 17s
300 lines
7.9 KiB
Python
300 lines
7.9 KiB
Python
"""Integration tests for Z-order persistence."""
|
|
|
|
from uuid import uuid4
|
|
|
|
import pytest
|
|
from httpx import AsyncClient
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
from app.database.models.board import Board
|
|
from app.database.models.board_image import BoardImage
|
|
from app.database.models.image import Image
|
|
from app.database.models.user import User
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_z_order(client: AsyncClient, test_user: User, db: AsyncSession):
|
|
"""Test updating Z-order of an image."""
|
|
board = Board(
|
|
id=uuid4(),
|
|
user_id=test_user.id,
|
|
title="Test Board",
|
|
viewport_state={"x": 0, "y": 0, "zoom": 1.0, "rotation": 0},
|
|
)
|
|
db.add(board)
|
|
|
|
image = Image(
|
|
id=uuid4(),
|
|
user_id=test_user.id,
|
|
filename="test.jpg",
|
|
storage_path=f"{test_user.id}/test.jpg",
|
|
file_size=1024,
|
|
mime_type="image/jpeg",
|
|
width=800,
|
|
height=600,
|
|
metadata={"format": "jpeg", "checksum": "abc123"},
|
|
)
|
|
db.add(image)
|
|
|
|
board_image = BoardImage(
|
|
id=uuid4(),
|
|
board_id=board.id,
|
|
image_id=image.id,
|
|
position={"x": 100, "y": 100},
|
|
transformations={
|
|
"scale": 1.0,
|
|
"rotation": 0,
|
|
"opacity": 1.0,
|
|
"flipped_h": False,
|
|
"flipped_v": False,
|
|
"greyscale": False,
|
|
},
|
|
z_order=0,
|
|
)
|
|
db.add(board_image)
|
|
await db.commit()
|
|
|
|
# Update Z-order
|
|
response = await client.patch(
|
|
f"/api/images/boards/{board.id}/images/{image.id}",
|
|
json={"z_order": 5},
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["z_order"] == 5
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_z_order_persists_across_requests(
|
|
client: AsyncClient, test_user: User, db: AsyncSession
|
|
):
|
|
"""Test that Z-order changes persist."""
|
|
board = Board(
|
|
id=uuid4(),
|
|
user_id=test_user.id,
|
|
title="Test Board",
|
|
viewport_state={"x": 0, "y": 0, "zoom": 1.0, "rotation": 0},
|
|
)
|
|
db.add(board)
|
|
|
|
image = Image(
|
|
id=uuid4(),
|
|
user_id=test_user.id,
|
|
filename="test.jpg",
|
|
storage_path=f"{test_user.id}/test.jpg",
|
|
file_size=1024,
|
|
mime_type="image/jpeg",
|
|
width=800,
|
|
height=600,
|
|
metadata={"format": "jpeg", "checksum": "abc123"},
|
|
)
|
|
db.add(image)
|
|
|
|
board_image = BoardImage(
|
|
id=uuid4(),
|
|
board_id=board.id,
|
|
image_id=image.id,
|
|
position={"x": 100, "y": 100},
|
|
transformations={
|
|
"scale": 1.0,
|
|
"rotation": 0,
|
|
"opacity": 1.0,
|
|
"flipped_h": False,
|
|
"flipped_v": False,
|
|
"greyscale": False,
|
|
},
|
|
z_order=0,
|
|
)
|
|
db.add(board_image)
|
|
await db.commit()
|
|
|
|
# Update Z-order
|
|
await client.patch(
|
|
f"/api/images/boards/{board.id}/images/{image.id}",
|
|
json={"z_order": 10},
|
|
)
|
|
|
|
# Fetch board images to verify persistence
|
|
response = await client.get(f"/api/images/boards/{board.id}/images")
|
|
|
|
assert response.status_code == 200
|
|
board_images = response.json()
|
|
assert len(board_images) == 1
|
|
assert board_images[0]["z_order"] == 10
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_multiple_images_z_order(client: AsyncClient, test_user: User, db: AsyncSession):
|
|
"""Test Z-order with multiple images."""
|
|
board = Board(
|
|
id=uuid4(),
|
|
user_id=test_user.id,
|
|
title="Test Board",
|
|
viewport_state={"x": 0, "y": 0, "zoom": 1.0, "rotation": 0},
|
|
)
|
|
db.add(board)
|
|
|
|
images = []
|
|
for i in range(3):
|
|
image = Image(
|
|
id=uuid4(),
|
|
user_id=test_user.id,
|
|
filename=f"test{i}.jpg",
|
|
storage_path=f"{test_user.id}/test{i}.jpg",
|
|
file_size=1024,
|
|
mime_type="image/jpeg",
|
|
width=800,
|
|
height=600,
|
|
metadata={"format": "jpeg", "checksum": f"abc{i}"},
|
|
)
|
|
db.add(image)
|
|
images.append(image)
|
|
|
|
board_image = BoardImage(
|
|
id=uuid4(),
|
|
board_id=board.id,
|
|
image_id=image.id,
|
|
position={"x": 100, "y": 100},
|
|
transformations={
|
|
"scale": 1.0,
|
|
"rotation": 0,
|
|
"opacity": 1.0,
|
|
"flipped_h": False,
|
|
"flipped_v": False,
|
|
"greyscale": False,
|
|
},
|
|
z_order=i,
|
|
)
|
|
db.add(board_image)
|
|
|
|
await db.commit()
|
|
|
|
# Update Z-order of middle image to be highest
|
|
await client.patch(
|
|
f"/api/images/boards/{board.id}/images/{images[1].id}",
|
|
json={"z_order": 10},
|
|
)
|
|
|
|
# Verify
|
|
response = await client.get(f"/api/images/boards/{board.id}/images")
|
|
board_images = response.json()
|
|
|
|
# Find the updated image
|
|
updated = next((bi for bi in board_images if str(bi["image_id"]) == str(images[1].id)), None)
|
|
assert updated is not None
|
|
assert updated["z_order"] == 10
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_z_order_negative_value(client: AsyncClient, test_user: User, db: AsyncSession):
|
|
"""Test that negative Z-order is allowed (for layering below 0)."""
|
|
board = Board(
|
|
id=uuid4(),
|
|
user_id=test_user.id,
|
|
title="Test Board",
|
|
viewport_state={"x": 0, "y": 0, "zoom": 1.0, "rotation": 0},
|
|
)
|
|
db.add(board)
|
|
|
|
image = Image(
|
|
id=uuid4(),
|
|
user_id=test_user.id,
|
|
filename="test.jpg",
|
|
storage_path=f"{test_user.id}/test.jpg",
|
|
file_size=1024,
|
|
mime_type="image/jpeg",
|
|
width=800,
|
|
height=600,
|
|
metadata={"format": "jpeg", "checksum": "abc123"},
|
|
)
|
|
db.add(image)
|
|
|
|
board_image = BoardImage(
|
|
id=uuid4(),
|
|
board_id=board.id,
|
|
image_id=image.id,
|
|
position={"x": 100, "y": 100},
|
|
transformations={
|
|
"scale": 1.0,
|
|
"rotation": 0,
|
|
"opacity": 1.0,
|
|
"flipped_h": False,
|
|
"flipped_v": False,
|
|
"greyscale": False,
|
|
},
|
|
z_order=0,
|
|
)
|
|
db.add(board_image)
|
|
await db.commit()
|
|
|
|
# Set negative Z-order
|
|
response = await client.patch(
|
|
f"/api/images/boards/{board.id}/images/{image.id}",
|
|
json={"z_order": -1},
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["z_order"] == -1
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_z_order_with_other_updates(client: AsyncClient, test_user: User, db: AsyncSession):
|
|
"""Test updating Z-order along with position and transformations."""
|
|
board = Board(
|
|
id=uuid4(),
|
|
user_id=test_user.id,
|
|
title="Test Board",
|
|
viewport_state={"x": 0, "y": 0, "zoom": 1.0, "rotation": 0},
|
|
)
|
|
db.add(board)
|
|
|
|
image = Image(
|
|
id=uuid4(),
|
|
user_id=test_user.id,
|
|
filename="test.jpg",
|
|
storage_path=f"{test_user.id}/test.jpg",
|
|
file_size=1024,
|
|
mime_type="image/jpeg",
|
|
width=800,
|
|
height=600,
|
|
metadata={"format": "jpeg", "checksum": "abc123"},
|
|
)
|
|
db.add(image)
|
|
|
|
board_image = BoardImage(
|
|
id=uuid4(),
|
|
board_id=board.id,
|
|
image_id=image.id,
|
|
position={"x": 100, "y": 100},
|
|
transformations={
|
|
"scale": 1.0,
|
|
"rotation": 0,
|
|
"opacity": 1.0,
|
|
"flipped_h": False,
|
|
"flipped_v": False,
|
|
"greyscale": False,
|
|
},
|
|
z_order=0,
|
|
)
|
|
db.add(board_image)
|
|
await db.commit()
|
|
|
|
# Update everything including Z-order
|
|
response = await client.patch(
|
|
f"/api/images/boards/{board.id}/images/{image.id}",
|
|
json={
|
|
"position": {"x": 200, "y": 200},
|
|
"transformations": {"scale": 2.0},
|
|
"z_order": 15,
|
|
},
|
|
)
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["position"]["x"] == 200
|
|
assert data["transformations"]["scale"] == 2.0
|
|
assert data["z_order"] == 15
|
|
|