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

SwissDataScienceCenter / renku-data-services / 9446003648

10 Jun 2024 09:35AM UTC coverage: 90.298% (+0.06%) from 90.239%
9446003648

Pull #248

github

web-flow
Merge 9ff3e8a6c into 1e340ea36
Pull Request #248: feat: add support for bitbucket

40 of 46 new or added lines in 3 files covered. (86.96%)

4 existing lines in 4 files now uncovered.

8488 of 9400 relevant lines covered (90.3%)

1.6 hits per line

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

95.24
/components/renku_data_services/base_api/misc.py
1
"""Common blueprints."""
2✔
2

3
from collections.abc import Awaitable, Callable
2✔
4
from dataclasses import dataclass
2✔
5
from functools import wraps
2✔
6
from typing import Any, NoReturn, ParamSpec, TypeVar, cast
2✔
7

8
from sanic import Request, json
2✔
9
from sanic.response import JSONResponse
2✔
10

11
from renku_data_services import errors
2✔
12
from renku_data_services.base_api.blueprint import BlueprintFactoryResponse, CustomBlueprint
2✔
13

14

15
@dataclass(kw_only=True)
2✔
16
class MiscBP(CustomBlueprint):
2✔
17
    """Server contains all handlers for CRC and the configuration."""
2✔
18

19
    apispec: dict[str, Any]
2✔
20
    version: str
2✔
21

22
    def get_apispec(self) -> BlueprintFactoryResponse:
2✔
23
        """Servers the OpenAPI specification."""
24

25
        async def _get_apispec(_: Request) -> JSONResponse:
2✔
26
            return json(self.apispec)
1✔
27

28
        return "/spec.json", ["GET"], _get_apispec
2✔
29

30
    def get_error(self) -> BlueprintFactoryResponse:
2✔
31
        """Returns a sample error response."""
32

33
        async def _get_error(_: Request) -> NoReturn:
2✔
34
            raise errors.ValidationError(message="Sample validation error")
1✔
35

36
        return "/error", ["GET"], _get_error
2✔
37

38
    def get_version(self) -> BlueprintFactoryResponse:
2✔
39
        """Returns the version."""
40

41
        async def _get_version(_: Request) -> JSONResponse:
2✔
42
            return json({"version": self.version})
2✔
43

44
        return "/version", ["GET"], _get_version
2✔
45

46

47
_T = TypeVar("_T")
2✔
48
_P = ParamSpec("_P")
2✔
49

50

51
def validate_db_ids(f: Callable[_P, Awaitable[_T]]) -> Callable[_P, Awaitable[_T]]:
2✔
52
    """Decorator for a Sanic handler that errors out if passed in IDs are outside of the valid range for postgres."""
53

54
    @wraps(f)
2✔
55
    async def decorated_function(*args: _P.args, **kwargs: _P.kwargs) -> _T:
2✔
56
        resource_pool_id = cast(int | None, kwargs.get("resource_pool_id"))
2✔
57
        class_id = cast(int | None, kwargs.get("class_id"))
2✔
58
        min_val = 1  # postgres primary keys start at 1
2✔
59
        max_val = 2_147_483_647  # the max value for a default postgres primary key sequence
2✔
60
        if resource_pool_id and not min_val <= resource_pool_id <= max_val:
2✔
UNCOV
61
            raise errors.ValidationError(
×
62
                message=f"The provided resource pool ID is outside of the allowed range [{min_val}, {max_val}]"
63
            )
64
        if class_id and not min_val <= class_id <= max_val:
2✔
65
            raise errors.ValidationError(
×
66
                message=f"The provided resource class ID is outside of the allowed range [{min_val}, {max_val}]"
67
            )
68
        response = await f(*args, **kwargs)
2✔
69
        return response
2✔
70

71
    return decorated_function
2✔
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

© 2025 Coveralls, Inc