File size: 1,186 Bytes
8bcdcab
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91fa7cf
8bcdcab
 
 
 
 
 
 
 
 
 
 
91fa7cf
8bcdcab
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
"""Tests for /api/process/audio endpoint."""

from __future__ import annotations

import io

from fastapi.testclient import TestClient


def test_audio_rejects_non_audio(client: TestClient) -> None:
    """Should reject non-audio content type."""
    fake = io.BytesIO(b"not audio")
    response = client.post(
        "/api/process/audio",
        data={"options": '{"pitch_shift": 0}'},
        files={"file": ("test.txt", fake, "text/plain")},
    )
    assert response.status_code in (400, 422)


def test_audio_rejects_missing_content_type(client: TestClient) -> None:
    """Should reject file with no content type."""
    fake = io.BytesIO(b"some bytes")
    response = client.post(
        "/api/process/audio",
        data={"options": '{"pitch_shift": 0}'},
        files={"file": ("test.bin", fake, "")},
    )
    # Empty content_type should be treated as invalid
    assert response.status_code in (400, 422)


def test_audio_rejects_missing_file(client: TestClient) -> None:
    """Should reject request without file."""
    response = client.post(
        "/api/process/audio",
        data={"options": '{"pitch_shift": 0}'},
    )
    assert response.status_code == 422