1 # Copyright 2021 Canonical Ltd.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 from typing
import NoReturn
16 from unittest
import TestCase
17 from unittest
.mock
import patch
19 from n2vc
.definitions
import Offer
, RelationEndpoint
22 @patch("n2vc.definitions.get_ee_id_components")
23 class RelationEndpointTest(TestCase
):
24 def test_success(self
, mock_get_ee_id_components
) -> NoReturn
:
25 mock_get_ee_id_components
.return_value
= ("model", "application", "machine_id")
26 relation_endpoint
= RelationEndpoint(
27 "model.application.machine_id",
31 self
.assertEqual(relation_endpoint
.model_name
, "model")
32 self
.assertEqual(relation_endpoint
.application_name
, "application")
33 self
.assertEqual(relation_endpoint
.vca_id
, "vca")
34 self
.assertEqual(relation_endpoint
.endpoint
, "application:endpoint")
35 self
.assertEqual(relation_endpoint
.endpoint_name
, "endpoint")
37 str(relation_endpoint
), "application:endpoint (model: model, vca: vca)"
41 class OfferTest(TestCase
):
42 def test_success(self
) -> NoReturn
:
43 url
= "admin/test-model.my-offer"
45 self
.assertEqual(offer
.model_name
, "test-model")
46 self
.assertEqual(offer
.name
, "my-offer")
47 self
.assertEqual(offer
.username
, "admin")
48 self
.assertEqual(offer
.url
, url
)