same as original code now -5 days of my life

This commit is contained in:
2025-02-07 18:27:20 -05:00
parent 511b070cbb
commit 1f5361da88
12 changed files with 394 additions and 394 deletions

View File

@@ -1,12 +1,8 @@
from fastapi.testclient import TestClient
from fastapi import BackgroundTasks
import pytest
from unittest.mock import Mock, patch
import asyncio
import os
from main import app
from services.file import FileService
from services.task import TaskService
@@ -146,9 +142,71 @@ async def test_open_box():
assert response.status_code == 201
assert response.json()["success"] == True
@pytest.mark.asyncio
async def test_delete_open_box():
with open(TEST_FILE_PATH, "rb") as test_file:
files = {"file": test_file}
# Make request
response = client.post("/api/files", data=DEFAULT_METADATA, files=files)
file_id = response.json()["files"][0]["id"]
# Check response
assert response.status_code == 201
assert response.json()["success"] == True
file_data = response.json()["files"][0]
assert file_data["source"] == DEFAULT_METADATA["source"]
assert file_data["type"] == DEFAULT_METADATA["type"]
assert file_data["status"] == "pending"
assert file_data["service"] == None
assert file_data["filename"] == "manabox_test_file.csv"
assert file_data["filesize_kb"] == get_file_size_kb(TEST_FILE_PATH)
assert file_data["id"] is not None
# Execute background tasks if they were added
background_tasks = BackgroundTasks()
for task in background_tasks.tasks:
await task()
# Create a box first
create_response = client.post("/api/boxes",
data={
"type": "play",
"set_code": "INR",
"sku": "1423",
"num_cards_expected": 504
}
)
box_id = create_response.json()["box"][0]["product_id"]
# Open the box
open_response = client.post(f"/api/boxes/{box_id}/open",
data={
"product_id": box_id,
"file_ids": [file_id],
"num_cards_actual": 500
}
)
# Check if the box is opened
assert open_response.status_code == 201
assert open_response.json()["success"] == True
# Get the open box ID
open_box_id = open_response.json()["open_box"][0]["id"]
# Delete the open box
response = client.delete(f"/api/boxes/{open_box_id}/open")
assert response.status_code == 200
assert response.json()["success"] == True
def test_cleanup():
cleanup = True
# Delete all boxes created during testing
for box_id in test_boxes:
client.delete(f"/api/boxes/{box_id}")
if cleanup:
for box_id in test_boxes:
client.delete(f"/api/boxes/{box_id}")