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

SwissDataScienceCenter / renku-python / 9058668052

13 May 2024 07:05AM UTC coverage: 77.713% (-8.4%) from 86.115%
9058668052

Pull #3727

github

web-flow
Merge 128d38387 into 050ed61bf
Pull Request #3727: fix: don't fail session launch when gitlab couldn't be reached

15 of 29 new or added lines in 3 files covered. (51.72%)

2594 existing lines in 125 files now uncovered.

23893 of 30745 relevant lines covered (77.71%)

3.2 hits per line

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

95.0
/renku/infrastructure/gateway/plan_gateway.py
1
# Copyright Swiss Data Science Center (SDSC). A partnership between
2
# École Polytechnique Fédérale de Lausanne (EPFL) and
3
# Eidgenössische Technische Hochschule Zürich (ETHZ).
4
#
5
# Licensed under the Apache License, Version 2.0 (the "License");
6
# you may not use this file except in compliance with the License.
7
# You may obtain a copy of the License at
8
#
9
#     http://www.apache.org/licenses/LICENSE-2.0
10
#
11
# Unless required by applicable law or agreed to in writing, software
12
# distributed under the License is distributed on an "AS IS" BASIS,
13
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
# See the License for the specific language governing permissions and
15
# limitations under the License.
16
"""Renku plan database gateway implementation."""
7✔
17

18
from typing import Dict, List, Optional, cast
7✔
19

20
import deal
7✔
21

22
from renku.core import errors
7✔
23
from renku.core.interface.plan_gateway import IPlanGateway
7✔
24
from renku.domain_model.project_context import project_context
7✔
25
from renku.domain_model.workflow.plan import AbstractPlan
7✔
26

27

28
class PlanGateway(IPlanGateway):
7✔
29
    """Gateway for plan database operations."""
30

31
    def get_by_id(self, id: Optional[str]) -> Optional[AbstractPlan]:
7✔
32
        """Get a plan by id."""
33
        return project_context.database["plans"].get(id)
4✔
34

35
    def get_by_name(self, name: str) -> Optional[AbstractPlan]:
7✔
36
        """Get a plan by name."""
37
        return project_context.database["plans-by-name"].get(name)
3✔
38

39
    def get_by_name_or_id(self, name_or_id: str) -> AbstractPlan:
7✔
40
        """Get a plan by name or id."""
41
        workflow = self.get_by_id(name_or_id) or self.get_by_name(name_or_id)
2✔
42

43
        if not workflow:
2✔
UNCOV
44
            raise errors.WorkflowNotFoundError(name_or_id)
×
45
        return workflow
2✔
46

47
    def list_by_name(self, starts_with: str, ends_with: Optional[str] = None) -> List[str]:
7✔
48
        """Search plans by name."""
49
        return [
×
50
            name
51
            for name in project_context.database["plans-by-name"].keys(min=starts_with, max=ends_with)
52
            if not cast(AbstractPlan, self.get_by_name(name)).deleted
53
        ]
54

55
    def get_newest_plans_by_names(self, include_deleted: bool = False) -> Dict[str, AbstractPlan]:
7✔
56
        """Return a mapping of all plan names to their newest plans."""
57
        database = project_context.database
4✔
58
        if include_deleted:
4✔
59
            return dict(database["plans-by-name"])
1✔
60
        return {k: v for k, v in database["plans-by-name"].items() if not v.deleted}
4✔
61

62
    def get_all_plans(self) -> List[AbstractPlan]:
7✔
63
        """Get all plans in project."""
64
        return list(project_context.database["plans"].values())
7✔
65

66
    @deal.pre(lambda _: _.plan.date_created is not None)
7✔
67
    @deal.pre(lambda _: _.plan.date_created >= project_context.project.date_created)
7✔
68
    @deal.pre(lambda _: _.plan.date_modified is None or _.plan.date_modified >= project_context.project.date_created)
7✔
69
    @deal.pre(lambda _: _.plan.date_removed is None or _.plan.date_removed >= project_context.project.date_created)
7✔
70
    def add(self, plan: AbstractPlan) -> None:
7✔
71
        """Add a plan to the database."""
72
        database = project_context.database
3✔
73

74
        if database["plans"].get(plan.id) is not None:
3✔
75
            return
3✔
76

77
        database["plans"].add(plan)
3✔
78

79
        if plan.derived_from is not None:
3✔
80
            derived_from = self.get_by_id(plan.derived_from)
3✔
81

82
            if derived_from is not None:
3✔
83
                database["plans-by-name"].pop(derived_from.name, None)
3✔
84
        database["plans-by-name"].add(plan)
3✔
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