Coverage for n2vc/tests/unit/test_definitions.py: 100%

23 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-05-07 06:04 +0000

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 

15from typing import NoReturn 

16from unittest import TestCase 

17from unittest.mock import patch 

18 

19from n2vc.definitions import Offer, RelationEndpoint 

20 

21 

22@patch("n2vc.definitions.get_ee_id_components") 

23class 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", 

28 "vca", 

29 "endpoint", 

30 ) 

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") 

36 self.assertEqual( 

37 str(relation_endpoint), "application:endpoint (model: model, vca: vca)" 

38 ) 

39 

40 

41class OfferTest(TestCase): 

42 def test_success(self) -> NoReturn: 

43 url = "admin/test-model.my-offer" 

44 offer = Offer(url) 

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)