Users, groups, permissions, model settings and reasoning display
Four features, plus the schema machinery they needed. **Schema sync.** The first live instance had data in it, and create_all only creates missing *tables* -- a new column silently never appeared. db/migrations.py now diffs the declared models against the database and ALTER TABLE ... ADD COLUMN for what is missing, deriving a backfill default from the column type (SQLite refuses a NOT NULL column without one, and a Python-side `default=dict` cannot be expressed in DDL). Verified against a copy of the live database: eight changes applied, all rows preserved, second run a no-op. Renames, drops and retypes are still manual and say so. **Permissions.** A flat set of named booleans: an instance baseline widened by each group the user belongs to. A group grants and never denies -- with denies, "why can this user not do X" cannot be answered without simulating every group. Admins bypass entirely, because an admin can grant it back to themselves in two clicks and pretending otherwise is theatre. Model *access* is separate: public, or granted to groups. The picker is not the boundary -- switching a chat to a model you cannot reach is a 403. **Model settings.** Ordering, pinned-first, an instance default and a per-user default, display names, descriptions, capability flags, and uploaded images. Images are stored and served locally rather than by URL: a remote URL makes every page render a request to a third party. Uploads are validated by magic number, not the declared content type, and stored under a random name. Models with no image get a generated initial whose hue is derived from the model id, so it is stable. **Reasoning display.** Streams into its own collapsible block above the answer, labelled "Thought for 14 seconds", collapsed once finished, and never replayed as context on the next turn. Two sources: the reasoning_content delta field, and <think> tags inline in content -- the latter needs a streaming splitter because the tags arrive split across chunks. Models emitting no reasoning show nothing, via a :has() rule rather than JavaScript. Verified against qwen35-9b on llama-swap: 694 reasoning events, 52 answer tokens, cleanly separated. Two bugs found and fixed while testing: - A bare `Mapped[list]` relationship is treated by SQLAlchemy as a scalar and returns None instead of []. It needs the element type. - FastAPI substitutes the default for an empty form value, so with `x: str | None = Form(None)` a submitted `x=` is indistinguishable from an absent field. That silently broke clearing a system prompt or a temperature. update_chat now reads the raw form and checks key presence. 143 tests, ruff clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,363 @@
|
||||
"""Groups, permissions and model access control."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlalchemy import select
|
||||
|
||||
from lembas.db.models import Chat, Connection, Group, Model, User
|
||||
from lembas.security import permissions
|
||||
from lembas.services import chat as chat_service
|
||||
from lembas.services import settings_store
|
||||
from lembas.services.crypto import encrypt
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def admin(client: TestClient, registered) -> None:
|
||||
"""The registered fixture already makes an administrator."""
|
||||
return None
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def plain_user(client: TestClient, db, registered) -> User:
|
||||
"""A second, non-admin account. Leaves the client signed in as them."""
|
||||
client.post("/auth/logout", follow_redirects=False)
|
||||
client.post(
|
||||
"/auth/register",
|
||||
data={"name": "Sam", "email": "sam@shire.test", "password": "potatoes-po-ta-toes"},
|
||||
follow_redirects=False,
|
||||
)
|
||||
return db.scalar(select(User).where(User.email == "sam@shire.test"))
|
||||
|
||||
|
||||
def _connection(db) -> Connection:
|
||||
connection = Connection(
|
||||
name="Test", base_url="http://127.0.0.1:1", api_key_encrypted=encrypt("")
|
||||
)
|
||||
db.add(connection)
|
||||
db.commit()
|
||||
return connection
|
||||
|
||||
|
||||
def _model(db, model_id: str, **kwargs) -> Model:
|
||||
model = Model(connection_id=_connection(db).id, model_id=model_id, **kwargs)
|
||||
db.add(model)
|
||||
db.commit()
|
||||
return model
|
||||
|
||||
|
||||
# --- Permission resolution ---------------------------------------------------
|
||||
def test_admins_get_everything(db, registered):
|
||||
admin_user = db.scalar(select(User).where(User.role == "admin"))
|
||||
assert all(permissions.resolve(db, admin_user).values())
|
||||
|
||||
|
||||
def test_signed_out_gets_nothing(db):
|
||||
assert not any(permissions.resolve(db, None).values())
|
||||
|
||||
|
||||
def test_plain_user_gets_the_baseline(db, plain_user):
|
||||
resolved = permissions.resolve(db, plain_user)
|
||||
assert resolved["chat.create"] is True
|
||||
# Off in the baseline by default.
|
||||
assert resolved["chat.params"] is False
|
||||
|
||||
|
||||
def test_a_group_widens_permissions(db, plain_user):
|
||||
group = Group(name="Power users", permissions_json={"chat.params": True})
|
||||
group.users = [plain_user]
|
||||
db.add(group)
|
||||
db.commit()
|
||||
assert permissions.resolve(db, plain_user)["chat.params"] is True
|
||||
|
||||
|
||||
def test_groups_union_rather_than_override(db, plain_user):
|
||||
"""A second group can only ever add. Absent means 'no opinion', not 'deny'."""
|
||||
db.add_all(
|
||||
[
|
||||
Group(name="A", permissions_json={"chat.params": True}, users=[plain_user]),
|
||||
Group(name="B", permissions_json={}, users=[plain_user]),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
assert permissions.resolve(db, plain_user)["chat.params"] is True
|
||||
|
||||
|
||||
def test_baseline_can_be_narrowed_instance_wide(db, plain_user):
|
||||
settings_store.update(db, {"default_permissions": {"chat.create": False}})
|
||||
assert permissions.resolve(db, plain_user)["chat.create"] is False
|
||||
|
||||
|
||||
def test_a_group_can_grant_back_what_the_baseline_removed(db, plain_user):
|
||||
settings_store.update(db, {"default_permissions": {"chat.create": False}})
|
||||
db.add(Group(name="Writers", permissions_json={"chat.create": True}, users=[plain_user]))
|
||||
db.commit()
|
||||
assert permissions.resolve(db, plain_user)["chat.create"] is True
|
||||
|
||||
|
||||
# --- Enforcement through the API ---------------------------------------------
|
||||
def test_creating_a_chat_is_refused_without_permission(client: TestClient, db, plain_user):
|
||||
settings_store.update(db, {"default_permissions": {"chat.create": False}})
|
||||
assert client.post("/api/chats").status_code == 403
|
||||
assert db.scalar(select(Chat)) is None
|
||||
|
||||
|
||||
def test_folder_routes_are_refused_without_permission(client: TestClient, db, plain_user):
|
||||
settings_store.update(db, {"default_permissions": {"folder.manage": False}})
|
||||
assert client.post("/api/folders", data={"name": "Nope"}).status_code == 403
|
||||
|
||||
|
||||
def test_changing_sampling_is_refused_without_permission(client: TestClient, db, plain_user):
|
||||
_model(db, "test-model")
|
||||
chat_id = client.post("/api/chats").headers["HX-Redirect"].rsplit("/", 1)[1]
|
||||
response = client.patch(f"/api/chats/{chat_id}", data={"temperature": "0.9"})
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
def test_sampling_is_allowed_once_a_group_grants_it(client: TestClient, db, plain_user):
|
||||
_model(db, "test-model")
|
||||
db.add(Group(name="Tuners", permissions_json={"chat.params": True}, users=[plain_user]))
|
||||
db.commit()
|
||||
|
||||
chat_id = client.post("/api/chats").headers["HX-Redirect"].rsplit("/", 1)[1]
|
||||
assert client.patch(f"/api/chats/{chat_id}", data={"temperature": "0.9"}).status_code == 204
|
||||
|
||||
chat = db.get(Chat, chat_id)
|
||||
db.refresh(chat)
|
||||
assert chat.params_json["temperature"] == 0.9
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("field", "value"),
|
||||
[("temperature", "5"), ("top_p", "-1"), ("max_tokens", "0"), ("temperature", "abc")],
|
||||
)
|
||||
def test_out_of_range_parameters_are_dropped_not_clamped(
|
||||
client: TestClient, db, registered, field, value
|
||||
):
|
||||
"""Silently changing what someone typed is worse than ignoring it."""
|
||||
_model(db, "test-model")
|
||||
chat_id = client.post("/api/chats").headers["HX-Redirect"].rsplit("/", 1)[1]
|
||||
client.patch(f"/api/chats/{chat_id}", data={field: value})
|
||||
|
||||
chat = db.get(Chat, chat_id)
|
||||
db.refresh(chat)
|
||||
assert field not in (chat.params_json or {})
|
||||
|
||||
|
||||
def test_an_empty_parameter_clears_it(client: TestClient, db, registered):
|
||||
_model(db, "test-model")
|
||||
chat_id = client.post("/api/chats").headers["HX-Redirect"].rsplit("/", 1)[1]
|
||||
client.patch(f"/api/chats/{chat_id}", data={"temperature": "0.7"})
|
||||
client.patch(f"/api/chats/{chat_id}", data={"temperature": ""})
|
||||
|
||||
chat = db.get(Chat, chat_id)
|
||||
db.refresh(chat)
|
||||
assert chat.params_json["temperature"] is None
|
||||
|
||||
|
||||
# --- Model access ------------------------------------------------------------
|
||||
def test_public_models_are_visible_to_everyone(db, plain_user):
|
||||
_model(db, "open-model", public=True)
|
||||
assert [m.model_id for m in permissions.models_visible_to(db, plain_user)] == ["open-model"]
|
||||
|
||||
|
||||
def test_restricted_models_are_hidden_without_a_group(db, plain_user):
|
||||
_model(db, "secret-model", public=False)
|
||||
assert permissions.models_visible_to(db, plain_user) == []
|
||||
|
||||
|
||||
def test_a_group_grants_access_to_a_restricted_model(db, plain_user):
|
||||
model = _model(db, "secret-model", public=False)
|
||||
group = Group(name="Insiders", users=[plain_user], models=[model])
|
||||
db.add(group)
|
||||
db.commit()
|
||||
assert [m.model_id for m in permissions.models_visible_to(db, plain_user)] == ["secret-model"]
|
||||
|
||||
|
||||
def test_admins_see_restricted_models(db, registered):
|
||||
_model(db, "secret-model", public=False)
|
||||
admin_user = db.scalar(select(User).where(User.role == "admin"))
|
||||
assert [m.model_id for m in permissions.models_visible_to(db, admin_user)] == ["secret-model"]
|
||||
|
||||
|
||||
def test_disabled_models_are_hidden_from_everyone(db, registered):
|
||||
_model(db, "off-model", enabled=False)
|
||||
admin_user = db.scalar(select(User).where(User.role == "admin"))
|
||||
assert permissions.models_visible_to(db, admin_user) == []
|
||||
|
||||
|
||||
def test_switching_to_an_inaccessible_model_is_refused(client: TestClient, db, plain_user):
|
||||
"""The picker is not the security boundary; a crafted request must fail."""
|
||||
_model(db, "open-model", public=True)
|
||||
_model(db, "secret-model", public=False)
|
||||
|
||||
chat_id = client.post("/api/chats").headers["HX-Redirect"].rsplit("/", 1)[1]
|
||||
response = client.patch(f"/api/chats/{chat_id}", data={"model_id": "secret-model"})
|
||||
assert response.status_code == 403
|
||||
|
||||
chat = db.get(Chat, chat_id)
|
||||
db.refresh(chat)
|
||||
assert chat.model_id == "open-model"
|
||||
|
||||
|
||||
def test_model_select_permission_is_required_to_switch(client: TestClient, db, plain_user):
|
||||
_model(db, "a-model", public=True)
|
||||
_model(db, "b-model", public=True)
|
||||
settings_store.update(db, {"default_permissions": {"chat.model_select": False}})
|
||||
|
||||
chat_id = client.post("/api/chats").headers["HX-Redirect"].rsplit("/", 1)[1]
|
||||
assert client.patch(f"/api/chats/{chat_id}", data={"model_id": "b-model"}).status_code == 403
|
||||
|
||||
|
||||
# --- Ordering and defaults ---------------------------------------------------
|
||||
def test_pinned_models_sort_first(db, registered):
|
||||
connection = _connection(db)
|
||||
db.add_all(
|
||||
[
|
||||
Model(connection_id=connection.id, model_id="ordinary", position=0),
|
||||
Model(connection_id=connection.id, model_id="favourite", position=9, pinned=True),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
admin_user = db.scalar(select(User).where(User.role == "admin"))
|
||||
assert [m.model_id for m in chat_service.available_models(db, admin_user)] == [
|
||||
"favourite",
|
||||
"ordinary",
|
||||
]
|
||||
|
||||
|
||||
def test_position_decides_order_among_unpinned(db, registered):
|
||||
connection = _connection(db)
|
||||
db.add_all(
|
||||
[
|
||||
Model(connection_id=connection.id, model_id="second", position=1),
|
||||
Model(connection_id=connection.id, model_id="first", position=0),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
admin_user = db.scalar(select(User).where(User.role == "admin"))
|
||||
assert [m.model_id for m in chat_service.available_models(db, admin_user)] == [
|
||||
"first",
|
||||
"second",
|
||||
]
|
||||
|
||||
|
||||
def test_instance_default_model_is_used_for_new_chats(client: TestClient, db, registered):
|
||||
connection = _connection(db)
|
||||
db.add_all(
|
||||
[
|
||||
Model(connection_id=connection.id, model_id="first", position=0),
|
||||
Model(connection_id=connection.id, model_id="chosen", position=5),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
settings_store.update(db, {"default_model": "chosen"})
|
||||
|
||||
client.post("/api/chats")
|
||||
assert db.scalar(select(Chat)).model_id == "chosen"
|
||||
|
||||
|
||||
def test_a_users_own_default_beats_the_instance_default(client: TestClient, db, plain_user):
|
||||
connection = _connection(db)
|
||||
db.add_all(
|
||||
[
|
||||
Model(connection_id=connection.id, model_id="instance-pick", position=0),
|
||||
Model(connection_id=connection.id, model_id="my-pick", position=5),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
settings_store.update(db, {"default_model": "instance-pick"})
|
||||
client.post("/api/preferences/default-model", data={"model_id": "my-pick"})
|
||||
|
||||
client.post("/api/chats")
|
||||
assert db.scalar(select(Chat)).model_id == "my-pick"
|
||||
|
||||
|
||||
def test_an_unreachable_default_falls_through(db, plain_user):
|
||||
"""A default the user has lost access to must not produce a dead chat."""
|
||||
connection = _connection(db)
|
||||
db.add_all(
|
||||
[
|
||||
Model(connection_id=connection.id, model_id="allowed", position=0, public=True),
|
||||
Model(connection_id=connection.id, model_id="gone", position=1, public=False),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
settings_store.update(db, {"default_model": "gone"})
|
||||
assert chat_service.default_model(db, plain_user)[0] == "allowed"
|
||||
|
||||
|
||||
def test_choosing_an_inaccessible_default_is_refused(client: TestClient, db, plain_user):
|
||||
_model(db, "secret-model", public=False)
|
||||
response = client.post(
|
||||
"/api/preferences/default-model", data={"model_id": "secret-model"}, follow_redirects=False
|
||||
)
|
||||
assert "error=" in response.headers["location"]
|
||||
db.refresh(plain_user)
|
||||
assert "default_model" not in (plain_user.settings_json or {})
|
||||
|
||||
|
||||
# --- Admin guards ------------------------------------------------------------
|
||||
def test_ordinary_users_cannot_reach_user_administration(client: TestClient, db, plain_user):
|
||||
for path in ("/admin/users", "/admin/groups", "/admin/models"):
|
||||
assert client.get(path, follow_redirects=False).status_code == 403, path
|
||||
|
||||
|
||||
def test_the_last_administrator_cannot_be_demoted(client: TestClient, db, registered):
|
||||
admin_user = db.scalar(select(User).where(User.role == "admin"))
|
||||
response = client.post(
|
||||
f"/admin/users/{admin_user.id}",
|
||||
data={"name": admin_user.name, "role": "user", "active": "true"},
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert "only+administrator" in response.headers["location"]
|
||||
|
||||
db.refresh(admin_user)
|
||||
assert admin_user.role == "admin"
|
||||
|
||||
|
||||
def test_you_cannot_delete_your_own_account(client: TestClient, db, registered):
|
||||
admin_user = db.scalar(select(User).where(User.role == "admin"))
|
||||
response = client.post(
|
||||
f"/admin/users/{admin_user.id}/delete", follow_redirects=False
|
||||
)
|
||||
assert "your+own+account" in response.headers["location"]
|
||||
assert db.get(User, admin_user.id) is not None
|
||||
|
||||
|
||||
def test_deactivating_a_user_revokes_their_sessions(client: TestClient, db, registered):
|
||||
"""Otherwise the change only lands when their cookie happens to expire."""
|
||||
other = TestClient(client.app)
|
||||
other.post(
|
||||
"/auth/register",
|
||||
data={"name": "Sam", "email": "sam@shire.test", "password": "potatoes-po-ta-toes"},
|
||||
follow_redirects=False,
|
||||
)
|
||||
assert other.get("/chat", follow_redirects=False).status_code == 200
|
||||
|
||||
target = db.scalar(select(User).where(User.email == "sam@shire.test"))
|
||||
client.post(
|
||||
f"/admin/users/{target.id}",
|
||||
data={"name": target.name, "role": "user"}, # `active` absent means off
|
||||
follow_redirects=False,
|
||||
)
|
||||
|
||||
assert other.get("/chat", follow_redirects=False).status_code == 303
|
||||
|
||||
|
||||
def test_a_pinned_model_appears_once_in_the_picker(client: TestClient, db, registered):
|
||||
"""Two options with the same value, both selected, is not a picker."""
|
||||
connection = _connection(db)
|
||||
db.add_all(
|
||||
[
|
||||
Model(connection_id=connection.id, model_id="favourite", pinned=True, position=0),
|
||||
Model(connection_id=connection.id, model_id="ordinary", position=1),
|
||||
]
|
||||
)
|
||||
db.commit()
|
||||
|
||||
chat_id = client.post("/api/chats").headers["HX-Redirect"].rsplit("/", 1)[1]
|
||||
page = client.get(f"/chat/{chat_id}").text
|
||||
assert page.count('<option value="favourite"') == 1
|
||||
assert page.count('<option value="ordinary"') == 1
|
||||
@@ -0,0 +1,140 @@
|
||||
"""Splitting a reasoning model's thinking from its answer."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from lembas.services.llm.openai_client import delta_reasoning
|
||||
from lembas.services.reasoning import (
|
||||
CONTENT,
|
||||
REASONING,
|
||||
ReasoningSplitter,
|
||||
format_duration,
|
||||
strip_reasoning,
|
||||
)
|
||||
|
||||
|
||||
def run(chunks: list[str]) -> tuple[str, str]:
|
||||
"""Feed chunks through the splitter and return (answer, reasoning)."""
|
||||
splitter = ReasoningSplitter()
|
||||
answer, thinking = [], []
|
||||
for chunk in chunks:
|
||||
for kind, piece in splitter.feed(chunk):
|
||||
(thinking if kind == REASONING else answer).append(piece)
|
||||
for kind, piece in splitter.flush():
|
||||
(thinking if kind == REASONING else answer).append(piece)
|
||||
return "".join(answer), "".join(thinking)
|
||||
|
||||
|
||||
# --- The dedicated field -----------------------------------------------------
|
||||
def test_reasoning_content_field():
|
||||
chunk = {"choices": [{"delta": {"reasoning_content": "hmm"}}]}
|
||||
assert delta_reasoning(chunk) == "hmm"
|
||||
|
||||
|
||||
def test_plain_reasoning_field_is_also_accepted():
|
||||
assert delta_reasoning({"choices": [{"delta": {"reasoning": "hmm"}}]}) == "hmm"
|
||||
|
||||
|
||||
def test_no_reasoning_field():
|
||||
assert delta_reasoning({"choices": [{"delta": {"content": "hi"}}]}) == ""
|
||||
|
||||
|
||||
@pytest.mark.parametrize("chunk", [{}, {"choices": []}, {"choices": [{"delta": {}}]}])
|
||||
def test_delta_reasoning_tolerates_junk(chunk):
|
||||
assert delta_reasoning(chunk) == ""
|
||||
|
||||
|
||||
# --- Inline <think> tags -----------------------------------------------------
|
||||
def test_plain_content_passes_straight_through():
|
||||
assert run(["Hello ", "world"]) == ("Hello world", "")
|
||||
|
||||
|
||||
def test_think_block_is_extracted():
|
||||
answer, thinking = run(["<think>weighing it up</think>The answer is 6."])
|
||||
assert answer == "The answer is 6."
|
||||
assert thinking == "weighing it up"
|
||||
|
||||
|
||||
def test_tag_split_across_chunks():
|
||||
"""The tag arrives in pieces, which is the whole reason this is a stream
|
||||
machine and not a regex."""
|
||||
answer, thinking = run(["<th", "ink>rea", "soning</thi", "nk>done"])
|
||||
assert answer == "done"
|
||||
assert thinking == "reasoning"
|
||||
|
||||
|
||||
def test_single_character_chunks():
|
||||
source = "<think>abc</think>xyz"
|
||||
assert run(list(source)) == ("xyz", "abc")
|
||||
|
||||
|
||||
def test_thinking_variant_is_not_mistaken_for_think():
|
||||
answer, thinking = run(["<thinking>deep</thinking>shallow"])
|
||||
assert answer == "shallow"
|
||||
assert thinking == "deep"
|
||||
|
||||
|
||||
def test_content_before_and_after_a_think_block():
|
||||
answer, thinking = run(["before <think>mid</think> after"])
|
||||
assert answer == "before after"
|
||||
assert thinking == "mid"
|
||||
|
||||
|
||||
def test_unterminated_think_block_flushes_as_reasoning():
|
||||
"""A truncated stream must not lose the partial thinking."""
|
||||
answer, thinking = run(["<think>never closed"])
|
||||
assert answer == ""
|
||||
assert thinking == "never closed"
|
||||
|
||||
|
||||
def test_newlines_survive():
|
||||
answer, thinking = run(["<think>a\nb</think>c\nd"])
|
||||
assert thinking == "a\nb"
|
||||
assert answer == "c\nd"
|
||||
|
||||
|
||||
def test_a_lone_angle_bracket_is_not_swallowed():
|
||||
assert run(["5 < 6 and 7 > 3"]) == ("5 < 6 and 7 > 3", "")
|
||||
|
||||
|
||||
def test_no_output_is_withheld_at_the_end():
|
||||
"""Whatever is buffered for a possible partial tag must be released on
|
||||
flush, or the last few characters of every reply would vanish."""
|
||||
answer, _ = run(["the end<thi"])
|
||||
assert answer == "the end<thi"
|
||||
|
||||
|
||||
def test_emits_incrementally_rather_than_only_at_the_end():
|
||||
"""Buffering the whole reply would defeat the point of streaming."""
|
||||
splitter = ReasoningSplitter()
|
||||
emitted = list(splitter.feed("a fairly long stretch of ordinary answer text"))
|
||||
assert emitted, "nothing emitted before flush"
|
||||
assert emitted[0][0] == CONTENT
|
||||
|
||||
|
||||
# --- Whole strings -----------------------------------------------------------
|
||||
def test_strip_reasoning_round_trip():
|
||||
answer, thinking = strip_reasoning("<think>because</think>Therefore 42.")
|
||||
assert (answer, thinking) == ("Therefore 42.", "because")
|
||||
|
||||
|
||||
def test_strip_reasoning_leaves_plain_text_alone():
|
||||
assert strip_reasoning("just an answer") == ("just an answer", "")
|
||||
|
||||
|
||||
# --- Duration phrasing -------------------------------------------------------
|
||||
@pytest.mark.parametrize(
|
||||
("milliseconds", "expected"),
|
||||
[
|
||||
(0, ""),
|
||||
(-5, ""),
|
||||
(400, "less than a second"),
|
||||
(1000, "1 second"),
|
||||
(8200, "8 seconds"),
|
||||
(60000, "1 minute"),
|
||||
(95000, "1m 35s"),
|
||||
],
|
||||
)
|
||||
def test_format_duration(milliseconds, expected):
|
||||
assert format_duration(milliseconds) == expected
|
||||
Reference in New Issue
Block a user