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

SwissDataScienceCenter / renku-data-services / 10353957042

12 Aug 2024 02:35PM UTC coverage: 90.758% (+0.4%) from 90.398%
10353957042

Pull #338

github

web-flow
Merge 3a49eb6c2 into 8afb94949
Pull Request #338: feat!: expand environments specification

227 of 237 new or added lines in 7 files covered. (95.78%)

48 existing lines in 9 files now uncovered.

9202 of 10139 relevant lines covered (90.76%)

1.61 hits per line

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

94.03
/components/renku_data_services/session/models.py
1
"""Models for Sessions."""
2✔
2

3
from dataclasses import dataclass
2✔
4
from datetime import datetime
2✔
5
from enum import StrEnum
2✔
6
from pathlib import PurePosixPath
2✔
7

8
from renku_data_services import errors
2✔
9

10

11
class EnvironmentKind(StrEnum):
2✔
12
    """The type of environment."""
2✔
13

14
    GLOBAL: str = "GLOBAL"
2✔
15
    CUSTOM: str = "CUSTOM"
2✔
16

17

18
@dataclass(kw_only=True, frozen=True, eq=True)
2✔
19
class BaseEnvironment:
2✔
20
    """Base session environment model."""
2✔
21

22
    name: str
2✔
23
    description: str | None
2✔
24
    container_image: str
2✔
25
    default_url: str
2✔
26
    port: int
2✔
27
    working_directory: PurePosixPath
2✔
28
    mount_directory: PurePosixPath
2✔
29
    uid: int
2✔
30
    gid: int
2✔
31
    environment_kind: EnvironmentKind
2✔
32

33

34
@dataclass(kw_only=True, frozen=True, eq=True)
2✔
35
class UnsavedEnvironment(BaseEnvironment):
2✔
36
    """Session environment model that has not been saved."""
2✔
37

38
    port: int = 8888
2✔
39
    description: str | None = None
2✔
40
    working_directory: PurePosixPath = PurePosixPath("/home/jovyan/work")
2✔
41
    mount_directory: PurePosixPath = PurePosixPath("/home/jovyan/work")
2✔
42
    uid: int = 1000
2✔
43
    gid: int = 1000
2✔
44

45
    def __post_init__(self) -> None:
2✔
46
        if not self.working_directory.is_absolute():
2✔
NEW
47
            raise errors.ValidationError(message="The working directory for a session is supposed to be absolute")
×
48
        if not self.mount_directory.is_absolute():
2✔
NEW
49
            raise errors.ValidationError(message="The mount directory for a session is supposed to be absolute")
×
50
        if self.working_directory.is_reserved():
2✔
NEW
51
            raise errors.ValidationError(
×
52
                message="The requested value for the working directory is reserved by the OS and cannot be used."
53
            )
54
        if self.mount_directory.is_reserved():
2✔
NEW
55
            raise errors.ValidationError(
×
56
                message="The requested value for the mount directory is reserved by the OS and cannot be used."
57
            )
58

59

60
@dataclass(kw_only=True, frozen=True, eq=True)
2✔
61
class Environment(BaseEnvironment):
2✔
62
    """Session environment model that has been saved in the DB."""
2✔
63

64
    id: str
2✔
65
    creation_date: datetime
2✔
66
    created_by: str
2✔
67

68

69
@dataclass(frozen=True, eq=True, kw_only=True)
2✔
70
class BaseSessionLauncher:
2✔
71
    """Session launcher model."""
2✔
72

73
    project_id: str
2✔
74
    name: str
2✔
75
    description: str | None
2✔
76
    environment: str | UnsavedEnvironment | Environment
2✔
77
    resource_class_id: int | None
2✔
78

79

80
@dataclass(frozen=True, eq=True, kw_only=True)
2✔
81
class UnsavedSessionLauncher(BaseSessionLauncher):
2✔
82
    """Session launcher model that has not been persisted in the DB."""
2✔
83

84
    environment: str | UnsavedEnvironment
2✔
85
    """When a string is passed for the environment it should be the ID of an existing environment."""
2✔
86

87

88
@dataclass(frozen=True, eq=True, kw_only=True)
2✔
89
class SessionLauncher(BaseSessionLauncher):
2✔
90
    """Session launcher model that has been already saved in the DB."""
2✔
91

92
    id: str
2✔
93
    creation_date: datetime
2✔
94
    created_by: str
2✔
95
    environment: Environment
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