From f1e0e0acf0e27bd556152f13d0cc5394f9fdc50c Mon Sep 17 00:00:00 2001 From: kitos Date: Thu, 25 Jun 2026 16:28:16 +0200 Subject: [PATCH] fix(tempo): delegate user-token worklog path to log_worklog so tests can mock it --- backend/app/services/tempo_service.py | 31 ++++++++++++++++----------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/backend/app/services/tempo_service.py b/backend/app/services/tempo_service.py index 244de8d..ef36309 100644 --- a/backend/app/services/tempo_service.py +++ b/backend/app/services/tempo_service.py @@ -291,25 +291,32 @@ def auto_log_test_worklog( from tempoapiclient import client_v4 as tempo_client base_url = _get_tempo_base_url(db) tempo = tempo_client.Tempo(auth_token=admin_token, base_url=base_url) + try: + result = tempo.create_worklog( + accountId=jira_account_id, + issueId=int(link.jira_issue_id), + dateFrom=work_date, + timeSpentSeconds=duration_seconds, + description=description, + ) + except BaseException as exc: + raise RuntimeError(f"Tempo API error: {exc}") from exc elif has_tempo_configured(user): - tempo = get_user_tempo_client(user, db=db) + result = log_worklog( + user, + jira_issue_id=int(link.jira_issue_id), + author_account_id=jira_account_id, + date=work_date, + time_spent_seconds=duration_seconds, + description=description, + db=db, + ) else: logger.debug( "No Tempo credentials available; skipping worklog for test %s", test.id ) return None - try: - result = tempo.create_worklog( - accountId=jira_account_id, - issueId=int(link.jira_issue_id), - dateFrom=work_date, - timeSpentSeconds=duration_seconds, - description=description, - ) - except BaseException as exc: - raise RuntimeError(f"Tempo API error: {exc}") from exc - logger.info( "Tempo worklog created for test %s by user %s: %ds on %s", test.id, getattr(user, "username", user), duration_seconds, work_date,