• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Clinical-Genomics / trailblazer / 10490912680

21 Aug 2024 01:29PM UTC coverage: 88.118% (-0.2%) from 88.353%
10490912680

push

github

web-flow
Add cancel endpoint (#475)

15 of 23 new or added lines in 5 files covered. (65.22%)

2084 of 2365 relevant lines covered (88.12%)

0.88 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

78.57
/trailblazer/server/utils.py
1
import datetime
1✔
2
from http import HTTPStatus
1✔
3
from flask import Request, jsonify
1✔
4
import logging
1✔
5
from functools import wraps
1✔
6
from pydantic import ValidationError
1✔
7

8
from trailblazer.exc import CancelSlurmAnalysisNotSupportedError, MissingAnalysis
1✔
9
from trailblazer.dto import AnalysesRequest
1✔
10
from trailblazer.services.authentication_service.exceptions import AuthenticationError
1✔
11

12
LOG = logging.getLogger(__name__)
1✔
13

14

15
def parse_analyses_request(request: Request) -> AnalysesRequest:
1✔
16
    """Parse a request for retrieving analyses."""
17
    query_params = {}
1✔
18
    for key in request.args.keys():
1✔
19
        if key_has_list_of_values(key):
1✔
20
            query_params[key[:-2]] = request.args.getlist(key)
1✔
21
        else:
22
            query_params[key] = request.args.get(key)
1✔
23
    return AnalysesRequest.model_validate(query_params)
1✔
24

25

26
def key_has_list_of_values(key: str) -> bool:
1✔
27
    return key.endswith("[]")
1✔
28

29

30
def stringify_timestamps(data: dict) -> dict[str, str]:
1✔
31
    """Convert datetime into string before dumping in order to avoid information loss"""
32
    for key, val in data.items():
×
33
        if isinstance(val, datetime.datetime):
×
34
            data[key] = str(val)
×
35
    return data
×
36

37

38
def handle_endpoint_errors(func):
1✔
39

40
    @wraps(func)
1✔
41
    def wrapper(*args, **kwargs):
1✔
42
        try:
1✔
43
            return func(*args, **kwargs)
1✔
44
        except AuthenticationError:
1✔
45
            return jsonify("User not allowed"), HTTPStatus.FORBIDDEN
×
46
        except MissingAnalysis as error:
1✔
47
            return jsonify(error=str(error)), HTTPStatus.NOT_FOUND
1✔
48
        except CancelSlurmAnalysisNotSupportedError as error:
1✔
NEW
49
            return jsonify(error=str(error)), HTTPStatus.BAD_REQUEST
×
50
        except ValidationError as error:
1✔
51
            LOG.error(f"Validation error in analysis endpoint: {error}")
1✔
52
            return jsonify(error=str(error)), HTTPStatus.BAD_REQUEST
1✔
53
        except Exception as error:
×
54
            LOG.error(f"Unexpected error in analysis endpoint: {error}")
×
55
            return (
×
56
                jsonify(error="An error occurred while processing your request."),
57
                HTTPStatus.INTERNAL_SERVER_ERROR,
58
            )
59

60
    return wrapper
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc