backend: initial commit
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
from bincio.extract.sport import normalise_sport
|
||||
|
||||
|
||||
def test_cycling_variants():
|
||||
for raw in ("cycling", "Biking", "road_biking", "virtual_ride", "e-biking"):
|
||||
assert normalise_sport(raw) == "cycling", raw
|
||||
|
||||
|
||||
def test_running_variants():
|
||||
for raw in ("running", "Run", "trail_running", "virtual_run"):
|
||||
assert normalise_sport(raw) == "running", raw
|
||||
|
||||
|
||||
def test_unknown_falls_back_to_other():
|
||||
assert normalise_sport("yoga") == "other"
|
||||
assert normalise_sport(None) == "other"
|
||||
@@ -0,0 +1,36 @@
|
||||
from bincio.extract.writer import make_activity_id, _slugify
|
||||
from bincio.extract.models import ParsedActivity, DataPoint
|
||||
from datetime import datetime, timezone
|
||||
|
||||
|
||||
def _dummy_activity(title=None):
|
||||
ts = datetime(2024, 6, 1, 7, 30, 12, tzinfo=timezone.utc)
|
||||
return ParsedActivity(
|
||||
points=[DataPoint(timestamp=ts)],
|
||||
sport="cycling",
|
||||
started_at=ts,
|
||||
source_file="test.fit",
|
||||
source_hash="sha256:abc",
|
||||
title=title,
|
||||
)
|
||||
|
||||
|
||||
def test_id_with_title():
|
||||
act = _dummy_activity("Morning Ride")
|
||||
aid = make_activity_id(act)
|
||||
assert aid.startswith("2024-06-01T")
|
||||
assert "morning-ride" in aid
|
||||
|
||||
|
||||
def test_id_without_title():
|
||||
act = _dummy_activity()
|
||||
aid = make_activity_id(act)
|
||||
assert "2024-06-01T" in aid
|
||||
# No trailing dash
|
||||
assert not aid.endswith("-")
|
||||
|
||||
|
||||
def test_slugify():
|
||||
assert _slugify("Morning Ride!") == "morning-ride"
|
||||
assert _slugify(" Vélo ") == "velo" # é → e via NFKD + ASCII
|
||||
assert _slugify("") == ""
|
||||
Reference in New Issue
Block a user