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

SwissDataScienceCenter / renku-data-services / 8941260124

03 May 2024 03:23PM UTC coverage: 90.381% (-0.02%) from 90.399%
8941260124

push

gihub-action

web-flow
feat: add custom idle/hibernation times to resource pools (#182)

29 of 30 new or added lines in 5 files covered. (96.67%)

6 existing lines in 4 files now uncovered.

5985 of 6622 relevant lines covered (90.38%)

0.9 hits per line

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

97.37
/components/renku_data_services/base_api/misc.py
1
"""Common blueprints."""
1✔
2
from dataclasses import dataclass
1✔
3
from functools import wraps
1✔
4
from typing import Any
1✔
5

6
from sanic import Request, json
1✔
7

8
from renku_data_services import errors
1✔
9
from renku_data_services.base_api.blueprint import BlueprintFactoryResponse, CustomBlueprint
1✔
10

11

12
@dataclass(kw_only=True)
1✔
13
class MiscBP(CustomBlueprint):
1✔
14
    """Server contains all handlers for CRC and the configuration."""
1✔
15

16
    apispec: dict[str, Any]
1✔
17
    version: str
1✔
18

19
    def get_apispec(self) -> BlueprintFactoryResponse:
1✔
20
        """Servers the OpenAPI specification."""
21

22
        async def _get_apispec(_: Request):
1✔
23
            return json(self.apispec)
1✔
24

25
        return "/spec.json", ["GET"], _get_apispec
1✔
26

27
    def get_error(self) -> BlueprintFactoryResponse:
1✔
28
        """Returns a sample error response."""
29

30
        async def _get_error(_: Request):
1✔
31
            raise errors.ValidationError(message="Sample validation error")
1✔
32

33
        return "/error", ["GET"], _get_error
1✔
34

35
    def get_version(self) -> BlueprintFactoryResponse:
1✔
36
        """Returns the version."""
37

38
        async def _get_version(_: Request):
1✔
39
            return json({"version": self.version})
1✔
40

41
        return "/version", ["GET"], _get_version
1✔
42

43

44
def validate_db_ids(f):
1✔
45
    """Decorator for a Sanic handler that errors out if passed in IDs are outside of the valid range for postgres."""
46

47
    @wraps(f)
1✔
48
    async def decorated_function(*args, **kwargs):
1✔
49
        resource_pool_id = kwargs.get("resource_pool_id")
1✔
50
        class_id = kwargs.get("class_id")
1✔
51
        min_val = 1  # postgres primary keys start at 1
1✔
52
        max_val = 2_147_483_647  # the max value for a default postgres primary key sequence
1✔
53
        if resource_pool_id and not min_val <= resource_pool_id <= max_val:
1✔
54
            raise errors.ValidationError(
1✔
55
                message=f"The provided resource pool ID is outside of the allowed range [{min_val}, {max_val}]"
56
            )
57
        if class_id and not min_val <= class_id <= max_val:
1✔
UNCOV
58
            raise errors.ValidationError(
×
59
                message=f"The provided resource class ID is outside of the allowed range [{min_val}, {max_val}]"
60
            )
61
        response = await f(*args, **kwargs)
1✔
62
        return response
1✔
63

64
    return decorated_function
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