Skip to content

Commit aaa651c

Browse files
authored
Merge pull request #482 from SimonRichardson/find-parameters
#482 The following adds the optional find parameters that are exposed in the API. The find API already existed, this is just to augment what was already there. It's now possible to just request bundles. ```py result = await model.charmhub.find("kuber", charm_type="bundle") ```
2 parents bde724b + e75ea01 commit aaa651c

2 files changed

Lines changed: 23 additions & 4 deletions

File tree

juju/charmhub.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,19 @@ async def info(self, name, channel=None):
2424
facade = self._facade()
2525
return await facade.Info(tag="application-{}".format(name), channel=channel)
2626

27-
async def find(self, query):
27+
async def find(self, query, category=None, channel=None,
28+
charm_type=None, platforms=None, publisher=None,
29+
relation_requires=None, relation_provides=None):
2830
"""find queries the CharmHub store for available charms or bundles.
2931
3032
"""
33+
if charm_type is not None and charm_type not in ["charm", "bundle"]:
34+
raise JujuError("expected either charm or bundle for charm_type")
35+
3136
facade = self._facade()
32-
return await facade.Find(query=query)
37+
return await facade.Find(query=query, category=category, channel=channel,
38+
type_=charm_type, platforms=platforms, publisher=publisher,
39+
relation_provides=relation_provides, relation_requires=relation_requires)
3340

3441
def _facade(self):
3542
return client.CharmHubFacade.from_connection(self.model.connection())

tests/integration/test_charmhub.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ async def test_info_not_found(event_loop):
3030
try:
3131
await model.charmhub.info("badnameforapp")
3232
except JujuAPIError as e:
33-
assert e.message == "No charm or bundle with name 'badnameforapp'."
33+
assert e.message == "badnameforapp not found"
3434
else:
35-
raise
35+
assert False
3636

3737

3838
@base.bootstrapped
@@ -47,6 +47,18 @@ async def test_find(event_loop):
4747
assert resp.type_ in ["charm", "bundle"]
4848

4949

50+
@base.bootstrapped
51+
@pytest.mark.asyncio
52+
async def test_find_bundles(event_loop):
53+
async with base.CleanModel() as model:
54+
result = await model.charmhub.find("kube", charm_type="bundle")
55+
56+
assert len(result.result) > 0
57+
for resp in result.result:
58+
assert resp.name != ""
59+
assert resp.type_ in ["bundle"]
60+
61+
5062
@base.bootstrapped
5163
@pytest.mark.asyncio
5264
async def test_find_all(event_loop):

0 commit comments

Comments
 (0)