Feature 10887: Add cross-model relations support
Changes:
- Extend `add_relation` method in N2VCJujuConn to include the CMR case
- Add `add_relation` method to K8sJujuConn
- Add n2vc/definitions.py file that includes definition ofjects for
Offer and RelationEndpoint.
- Change `n2vc.libjuju.Libjuju.list_offers` method to be private, and accept a filter `offer_name` parameter.
- Update `n2vc.libjuju.Libjuju.consume` method arguments.
- Add `n2vc.libjuju.Libjuju.offer` method to create an offer.
Unit tests associated to the code changes have been either created or
updated accordingly
Change-Id: Ibf8d574528dee0fa898e0e97578dd3a6aa68316a
Signed-off-by: David Garcia <david.garcia@canonical.com>
diff --git a/n2vc/tests/unit/test_definitions.py b/n2vc/tests/unit/test_definitions.py
new file mode 100644
index 0000000..5d58a76
--- /dev/null
+++ b/n2vc/tests/unit/test_definitions.py
@@ -0,0 +1,48 @@
+# Copyright 2021 Canonical Ltd.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from typing import NoReturn
+from unittest import TestCase
+from unittest.mock import patch
+
+from n2vc.definitions import Offer, RelationEndpoint
+
+
+@patch("n2vc.definitions.get_ee_id_components")
+class RelationEndpointTest(TestCase):
+ def test_success(self, mock_get_ee_id_components) -> NoReturn:
+ mock_get_ee_id_components.return_value = ("model", "application", "machine_id")
+ relation_endpoint = RelationEndpoint(
+ "model.application.machine_id",
+ "vca",
+ "endpoint",
+ )
+ self.assertEqual(relation_endpoint.model_name, "model")
+ self.assertEqual(relation_endpoint.application_name, "application")
+ self.assertEqual(relation_endpoint.vca_id, "vca")
+ self.assertEqual(relation_endpoint.endpoint, "application:endpoint")
+ self.assertEqual(relation_endpoint.endpoint_name, "endpoint")
+ self.assertEqual(
+ str(relation_endpoint), "application:endpoint (model: model, vca: vca)"
+ )
+
+
+class OfferTest(TestCase):
+ def test_success(self) -> NoReturn:
+ url = "admin/test-model.my-offer"
+ offer = Offer(url)
+ self.assertEqual(offer.model_name, "test-model")
+ self.assertEqual(offer.name, "my-offer")
+ self.assertEqual(offer.username, "admin")
+ self.assertEqual(offer.url, url)