Setup screen (create/open library), update buttons, drag-and-drop import, Garmin Connect login with MFA prompt, sources overview, settings, live log. Jobs run one at a time in a worker thread. Single instance on Windows. Dashboard can be copied to extra paths (copy_dashboard_to). App API test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
30 lines
1.3 KiB
Python
30 lines
1.3 KiB
Python
"""The app's Api without a window: library create/open, settings, and jobs running in the worker thread."""
|
|
import time
|
|
import pytest
|
|
from mygarmin import app
|
|
from test_pipeline import inbox # noqa: F401 (fixture)
|
|
|
|
def wait(api):
|
|
for _ in range(600):
|
|
if not api._busy: return
|
|
time.sleep(0.05)
|
|
raise TimeoutError(api._busy)
|
|
|
|
def test_app_api(tmp_path, inbox, monkeypatch):
|
|
monkeypatch.setattr(app, 'STATE', str(tmp_path / 'app.json'))
|
|
api = app.Api()
|
|
assert api.state()['library'] is None
|
|
s = api.create_library(str(tmp_path / 'lib'), 'Sam', '1990', 'F', 'Europe/London')
|
|
assert s['library']['settings']['name'] == 'Sam' and s['recent'] == [str(tmp_path / 'lib')]
|
|
assert api.import_paths([str(inbox)])['ok']
|
|
assert not api.build()['ok'] # one job at a time
|
|
wait(api)
|
|
st = api.state()['library']
|
|
assert st['shown'] == 4 and st['health']['days'] == 2 and st['dashboard']
|
|
assert api.export()['ok']; wait(api)
|
|
assert api.state()['library']['exports']
|
|
s = api.save_settings('Sam B', '1990', 'F', 'Europe/London', 'C:\\x\\a.html\n\n')
|
|
assert s['library']['settings']['copy_dashboard_to'] == ['C:\\x\\a.html']
|
|
assert app.Api().state()['library']['root'] == str(tmp_path / 'lib') # reopens the last library
|
|
assert api.open_library(str(tmp_path))['error']
|