Code Coverage

Cobertura Coverage Report > n2vc >

definitions.py

Trend

File Coverage summary

NameClassesLinesConditionals
definitions.py
100%
1/1
100%
52/52
100%
0/0

Coverage Breakdown by Class

NameLinesConditionals
definitions.py
100%
52/52
N/A

Source

n2vc/definitions.py
1 # Copyright 2021 Canonical Ltd.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #     http://www.apache.org/licenses/LICENSE-2.0
8 #
9 #     Unless required by applicable law or agreed to in writing, software
10 #     distributed under the License is distributed on an "AS IS" BASIS,
11 #     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 #     See the License for the specific language governing permissions and
13 #     limitations under the License.
14
15 1 from typing import NoReturn
16
17 1 from n2vc.utils import get_ee_id_components
18
19
20 1 class RelationEndpoint:
21     """Represents an endpoint of an application"""
22
23 1     def __init__(self, ee_id: str, vca_id: str, endpoint_name: str) -> NoReturn:
24         """
25         Args:
26             ee_id: Execution environment id.
27                    Format: "<model>.<application_name>.<machine_id>".
28             vca_id: Id of the VCA. Identifies the Juju Controller
29                     where the application is deployed
30             endpoint_name: Name of the endpoint for the relation
31         """
32 1         ee_components = get_ee_id_components(ee_id)
33 1         self._model_name = ee_components[0]
34 1         self._application_name = ee_components[1]
35 1         self._vca_id = vca_id
36 1         self._endpoint_name = endpoint_name
37
38 1     @property
39 1     def application_name(self) -> str:
40         """Returns the application name"""
41 1         return self._application_name
42
43 1     @property
44 1     def endpoint(self) -> str:
45         """Returns the application name and the endpoint. Format: <application>:<endpoint>"""
46 1         return f"{self.application_name}:{self._endpoint_name}"
47
48 1     @property
49 1     def endpoint_name(self) -> str:
50         """Returns the endpoint name"""
51 1         return self._endpoint_name
52
53 1     @property
54 1     def model_name(self) -> str:
55         """Returns the model name"""
56 1         return self._model_name
57
58 1     @property
59 1     def vca_id(self) -> str:
60         """Returns the vca id"""
61 1         return self._vca_id
62
63 1     def __str__(self) -> str:
64 1         app = self.application_name
65 1         endpoint = self.endpoint_name
66 1         model = self.model_name
67 1         vca = self.vca_id
68 1         return f"{app}:{endpoint} (model: {model}, vca: {vca})"
69
70
71 1 class Offer:
72     """Represents a juju offer"""
73
74 1     def __init__(self, url: str, vca_id: str = None) -> NoReturn:
75         """
76         Args:
77             url: Offer url. Format: <user>/<model>.<offer-name>.
78         """
79 1         self._url = url
80 1         self._username = url.split(".")[0].split("/")[0]
81 1         self._model_name = url.split(".")[0].split("/")[1]
82 1         self._name = url.split(".")[1]
83 1         self._vca_id = vca_id
84
85 1     @property
86 1     def model_name(self) -> str:
87         """Returns the model name"""
88 1         return self._model_name
89
90 1     @property
91 1     def name(self) -> str:
92         """Returns the offer name"""
93 1         return self._name
94
95 1     @property
96 1     def username(self) -> str:
97         """Returns the username"""
98 1         return self._username
99
100 1     @property
101 1     def url(self) -> str:
102         """Returns the offer url"""
103 1         return self._url
104
105 1     @property
106 1     def vca_id(self) -> str:
107         """Returns the vca id"""
108 1         return self._vca_id