From 2d85b6ba7a189ade08ac205064d7e1e46dfbde1e Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Tue, 30 May 2023 11:41:47 -0600 Subject: [PATCH 1/2] Avoid removing the track if set to latest in channel normalization Fixes #863 --- juju/origin.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/juju/origin.py b/juju/origin.py index 083e1622..0dca7468 100644 --- a/juju/origin.py +++ b/juju/origin.py @@ -97,7 +97,9 @@ def parse(s): return Channel(track, risk) def normalize(self): - track = self.track if self.track != "latest" else "" + # TODO (cderici): this is essentially a noop, needs to be revised in both + # 2.9 and 3.x + track = self.track if self.track != "" else "" risk = self.risk if self.risk != "" else "" return Channel(track, risk) From 6d7ac14ab1364a5eeb00dc270ad342759d8936ad Mon Sep 17 00:00:00 2001 From: Caner Derici Date: Tue, 30 May 2023 12:05:24 -0600 Subject: [PATCH 2/2] Fix unit tests --- tests/unit/test_bundle.py | 2 +- tests/unit/test_origin.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/test_bundle.py b/tests/unit/test_bundle.py index 64c569ba..d2f9370a 100644 --- a/tests/unit/test_bundle.py +++ b/tests/unit/test_bundle.py @@ -355,7 +355,7 @@ async def test_run_with_charmhub_charm_no_channel(self, event_loop): context = Mock() context.resolve.return_value = "ch:charm1" - context.origins = {"ch:charm1": {"stable": Mock()}} + context.origins = {"ch:charm1": {"latest/stable": Mock()}} context.trusted = False context.model = model diff --git a/tests/unit/test_origin.py b/tests/unit/test_origin.py index b2b3fa5e..979cdc65 100644 --- a/tests/unit/test_origin.py +++ b/tests/unit/test_origin.py @@ -30,7 +30,7 @@ def test_parse_numeric(self): def test_parse_then_normalize(self): ch = Channel.parse("latest/stable").normalize() - self.assertEqual(ch, Channel(None, "stable")) + self.assertEqual(ch, Channel("latest", "stable")) def test_str_risk_only(self): ch = Channel.parse("stable") @@ -50,7 +50,7 @@ def test_str_numeric(self): def test_str_then_normalize(self): ch = Channel.parse("latest/stable").normalize() - self.assertEqual(str(ch), "stable") + self.assertEqual(str(ch), "latest/stable") class TestPlatform(unittest.TestCase):