import pytest
from fastapi import FastAPI
from fastapi.testclient import TestClient

from .routes import router

app = FastAPI()
app.include_router(router)
client = TestClient(app)


@pytest.mark.usefixtures("client", "access_token")
def test_list_fraction_rules(client, access_token):
    headers = {"Authorization": f"Bearer {access_token}"}
    response = client.get("/fraction_rule_octave/", headers=headers)
    assert response.status_code == 200
    assert "items" in response.json()
    assert "page" in response.json()
    assert "page_size" in response.json()


@pytest.mark.usefixtures("client", "access_token")
def test_get_fraction_rule_not_found(client, access_token):
    headers = {"Authorization": f"Bearer {access_token}"}
    response = client.get("/fraction_rule_octave/invalid_id", headers=headers)
    assert response.status_code == 404


def test_create_fraction_rule_forbidden():
    response = client.post("/fraction_rule_octave/", json={"rule": "Test Rule"})
    assert response.status_code in (403, 405, 404)


def test_update_fraction_rule_forbidden():
    response = client.put("/fraction_rule_octave/1", json={"rule": "Updated Rule"})
    assert response.status_code in (403, 405, 404)
