Skip to content

Commit 7593328

Browse files
committed
Update charmhub info test
1 parent c1aae9f commit 7593328

2 files changed

Lines changed: 21 additions & 3 deletions

File tree

juju/charmhub.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,20 @@ async def info(self, name, channel=None):
7474
if err_code:
7575
raise JujuError(f'charmhub.info - {err_code} : {res.errors.error_list.message}')
7676
result = res.result
77-
result.channel_map = self._channel_map_to_dict(result.channel_map)
77+
result.channel_map = CharmHub._channel_map_to_dict(
78+
result.channel_map)
7879
result = result.serialize()
7980
else:
8081
charmhub_url = await self._charmhub_url()
8182
url = "{}/v2/charms/info/{}?fields=channel-map".format(
8283
charmhub_url.value, name)
8384
_response = self.request_charmhub_with_retry(url, 5)
8485
result = json.loads(_response.text)
86+
result['channel-map'] = CharmHub._channel_list_to_map(result['channel-map'])
8587
return result
8688

87-
def _channel_list_to_map(self, channel_list_map):
89+
@staticmethod
90+
def _channel_list_to_map(channel_list_map):
8891
"""Charmhub API returns the channel map as a list of channel objects
8992
(with risk, track, revision, download etc). This turns that into a map
9093
that's keyed with the channel=track/risk for easy
@@ -106,7 +109,8 @@ def _channel_list_to_map(self, channel_list_map):
106109
= ch
107110
return channel_map
108111

109-
def _channel_map_to_dict(self, channel_map):
112+
@staticmethod
113+
def _channel_map_to_dict(channel_map):
110114
"""Converts the client.definitions.Channel objects into python maps
111115
inside a channel map (for pylibjuju <3.0)
112116

tests/integration/test_charmhub.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,20 @@ async def test_info(event_loop):
1212
_, name = await model.charmhub.get_charm_id("hello-juju")
1313
assert name == "hello-juju"
1414

15+
charm_name = 'juju-qa-test'
16+
charm_info = await model.charmhub.info(charm_name)
17+
assert charm_info['name'] == 'juju-qa-test'
18+
assert charm_info['type'] == 'charm'
19+
assert charm_info['id'] == 'Hw30RWzpUBnJLGtO71SX8VDWvd3WrjaJ'
20+
assert '2.0/stable' in charm_info['channel-map']
21+
cm_rev = charm_info['channel-map']['2.0/stable']['revision']
22+
if type(cm_rev) == dict:
23+
# New client (>= 3.0)
24+
assert cm_rev['revision'] == 22
25+
else:
26+
# Old client (<= 2.9)
27+
assert cm_rev == 22
28+
1529

1630
@base.bootstrapped
1731
@pytest.mark.asyncio

0 commit comments

Comments
 (0)