Skip to content

Commit

Permalink
feat: deprecation warnings on select application attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaqq committed Sep 30, 2024
1 parent bcbce1e commit 218aae5
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 12 deletions.
41 changes: 39 additions & 2 deletions juju/application.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
import hashlib
import json
import logging
import typing
import warnings
from typing import Dict, List, Union
from pathlib import Path

from . import jasyncio, model, tag, utils
Expand All @@ -24,6 +25,42 @@


class Application(model.ModelEntity):
@property
def name(self) -> str:
return self.entity_id

@property
def exposed(self) -> bool:
return self.safe_data["exposed"]

@property
def owner_tag(self) -> str:
warnings.warn("Deprecated", DeprecationWarning)
return self.safe_data["owner-tag"]

@property
def life(self) -> str:
return self.safe_data["life"]

@property
def min_units(self) -> int:
warnings.warn("Deprecated", DeprecationWarning)
return self.safe_data["min-units"]

@property
def constraints(self) -> Dict[str, Union[str, int, bool]]:
return self.safe_data["constraints"]

@property
def subordinate(self) -> bool:
warnings.warn("Deprecated", DeprecationWarning)
return self.safe_data["subordinate"]

@property
def workload_version(self) -> str:
warnings.warn("Deprecated, use Unit.workload_version instead", DeprecationWarning)
return self.safe_data["workload-version"]

@property
def _unit_match_pattern(self):
return r'^{}.*$'.format(self.entity_id)
Expand Down Expand Up @@ -63,7 +100,7 @@ def subordinate_units(self):
return [u for u in self.units if u.is_subordinate]

@property
def relations(self) -> typing.List[Relation]:
def relations(self) -> List[Relation]:
return [rel for rel in self.model.relations if rel.matches(self.name)]

def related_applications(self, endpoint_name=None):
Expand Down
15 changes: 5 additions & 10 deletions tests/unit/test_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ async def test_expose_with_exposed_endpoints_as_raw_dict(self, mock_conn):
mock_facade().Expose.return_value.set_result([])

app = Application(entity_id="app-id", model=Model())
app.name = "panther"
app._facade = mock_facade
app._facade_version = mock_facade_version

Expand All @@ -37,7 +36,7 @@ async def test_expose_with_exposed_endpoints_as_raw_dict(self, mock_conn):
})

mock_facade().Expose.assert_called_once_with(
application="panther",
application="app-id",
exposed_endpoints={
"": {
"expose-to-spaces": ["alpha"],
Expand All @@ -53,7 +52,6 @@ async def test_expose_with_exposed_endpoints(self, mock_conn):
mock_facade().Expose.return_value.set_result([])

app = Application(entity_id="app-id", model=Model())
app.name = "panther"
app._facade = mock_facade
app._facade_version = mock_facade_version

Expand All @@ -67,7 +65,7 @@ async def test_expose_with_exposed_endpoints(self, mock_conn):
})

mock_facade().Expose.assert_called_once_with(
application="panther",
application="app-id",
exposed_endpoints={
"": {
"expose-to-spaces": ["alpha"],
Expand All @@ -89,7 +87,6 @@ async def test_expose_endpoints_on_older_controller(self, mock_conn):
mock_facade().Expose.return_value.set_result([])

app = Application(entity_id="app-id", model=Model())
app.name = "panther"
app._facade = mock_facade
app._facade_version = mock_facade_version

Expand Down Expand Up @@ -125,7 +122,7 @@ async def test_expose_endpoints_on_older_controller(self, mock_conn):

# Check that we call the facade with the right arity.
await app.expose()
mock_facade().Expose.assert_called_once_with(application="panther")
mock_facade().Expose.assert_called_once_with(application="app-id")


class TestUnExposeApplication(unittest.IsolatedAsyncioTestCase):
Expand All @@ -137,7 +134,6 @@ async def test_unexpose_endpoints_on_older_controller(self, mock_conn):
mock_facade().Unexpose.return_value.set_result([])

app = Application(entity_id="app-id", model=Model())
app.name = "panther"
app._facade = mock_facade
app._facade_version = mock_facade_version

Expand All @@ -148,7 +144,7 @@ async def test_unexpose_endpoints_on_older_controller(self, mock_conn):

# Check that we call the facade with the right arity.
await app.unexpose()
mock_facade().Unexpose.assert_called_once_with(application="panther")
mock_facade().Unexpose.assert_called_once_with(application="app-id")

@mock.patch("juju.model.Model.connection")
async def test_unexpose_endpoints_on_29_controller(self, mock_conn):
Expand All @@ -158,14 +154,13 @@ async def test_unexpose_endpoints_on_29_controller(self, mock_conn):
mock_facade().Unexpose.return_value.set_result([])

app = Application(entity_id="app-id", model=Model())
app.name = "panther"
app._facade = mock_facade
app._facade_version = mock_facade_version

await app.unexpose(exposed_endpoints=["alpha", "beta"])

mock_facade().Unexpose.assert_called_once_with(
application="panther",
application="app-id",
exposed_endpoints=["alpha", "beta"]
)

Expand Down

0 comments on commit 218aae5

Please sign in to comment.