Add upload/download tests for size boundaries and concurrency
- Add size boundary tests: 1B, 1KB, 10KB, 100KB, 1MB, 5MB, 10MB, 50MB - Add large file tests (100MB-1GB) marked with @pytest.mark.large - Add chunk boundary tests at 64KB boundaries - Add concurrent upload/download tests (2, 5, 10 parallel) - Add data integrity tests (binary, text, unicode, compressed) - Add generate_content() and sized_content fixture for test helpers - Add @pytest.mark.large and @pytest.mark.concurrent markers - Fix Content-Disposition header encoding for non-ASCII filenames (RFC 5987)
This commit is contained in:
@@ -97,6 +97,7 @@ def upload_test_file(
|
||||
content: bytes,
|
||||
filename: str = "test.bin",
|
||||
tag: Optional[str] = None,
|
||||
version: Optional[str] = None,
|
||||
) -> dict:
|
||||
"""
|
||||
Helper function to upload a test file via the API.
|
||||
@@ -108,6 +109,7 @@ def upload_test_file(
|
||||
content: File content as bytes
|
||||
filename: Original filename
|
||||
tag: Optional tag to assign
|
||||
version: Optional version to assign
|
||||
|
||||
Returns:
|
||||
The upload response as a dict
|
||||
@@ -116,6 +118,8 @@ def upload_test_file(
|
||||
data = {}
|
||||
if tag:
|
||||
data["tag"] = tag
|
||||
if version:
|
||||
data["version"] = version
|
||||
|
||||
response = client.post(
|
||||
f"/api/v1/project/{project}/{package}/upload",
|
||||
@@ -126,6 +130,41 @@ def upload_test_file(
|
||||
return response.json()
|
||||
|
||||
|
||||
def generate_content(size: int, seed: Optional[int] = None) -> bytes:
|
||||
"""
|
||||
Generate deterministic or random content of a specified size.
|
||||
|
||||
Args:
|
||||
size: Size of content in bytes
|
||||
seed: Optional seed for reproducible content (None for random)
|
||||
|
||||
Returns:
|
||||
Bytes of the specified size
|
||||
"""
|
||||
if size == 0:
|
||||
return b""
|
||||
if seed is not None:
|
||||
import random
|
||||
rng = random.Random(seed)
|
||||
return bytes(rng.randint(0, 255) for _ in range(size))
|
||||
return os.urandom(size)
|
||||
|
||||
|
||||
def generate_content_with_hash(size: int, seed: Optional[int] = None) -> tuple[bytes, str]:
|
||||
"""
|
||||
Generate content of specified size and compute its SHA256 hash.
|
||||
|
||||
Args:
|
||||
size: Size of content in bytes
|
||||
seed: Optional seed for reproducible content
|
||||
|
||||
Returns:
|
||||
Tuple of (content_bytes, sha256_hash)
|
||||
"""
|
||||
content = generate_content(size, seed)
|
||||
return content, compute_sha256(content)
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Project/Package Factories
|
||||
# =============================================================================
|
||||
|
||||
Reference in New Issue
Block a user