Skip to content

Commit a549926

Browse files
committed
Fix positional args + add get shim
1 parent 49c5554 commit a549926

7 files changed

Lines changed: 20 additions & 10 deletions

File tree

juju/client/facade.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,16 @@ def __setitem__(self, key, value):
654654
attr = self._toPy[key]
655655
setattr(self, attr, value)
656656

657+
# legacy: generated definitions used to not correctly
658+
# create typed objects and would use dict instead (from JSON)
659+
# so we emulate some dict methods.
660+
def get(self, key, default=None):
661+
try:
662+
attr = self._toPy[key]
663+
except KeyError:
664+
return default
665+
return getattr(self, attr, default)
666+
657667

658668
class Schema(dict):
659669
def __init__(self, schema):

juju/controller.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ async def reset_user_password(self, username):
447447
user_facade = client.UserManagerFacade.from_connection(
448448
self.connection())
449449
entity = client.Entity(tag.user(username))
450-
results = await user_facade.ResetPassword([entity])
450+
results = await user_facade.ResetPassword(entities=[entity])
451451
secret_key = results.results[0].secret_key
452452
return await self.get_user(username, secret_key=secret_key)
453453

@@ -755,7 +755,7 @@ async def create_offer(self, model_uuid, endpoint, offer_name=None, application_
755755
params.model_tag = tag.model(model_uuid)
756756

757757
facade = client.ApplicationOffersFacade.from_connection(self.connection())
758-
return await facade.Offer([params])
758+
return await facade.Offer(offers=[params])
759759

760760
async def list_offers(self, model_name):
761761
"""
@@ -766,7 +766,7 @@ async def list_offers(self, model_name):
766766
params.model_name = model_name
767767

768768
facade = client.ApplicationOffersFacade.from_connection(self.connection())
769-
return await facade.ListApplicationOffers([params])
769+
return await facade.ListApplicationOffers(filters=[params])
770770

771771
async def remove_offer(self, model_uuid, offer, force=False):
772772
"""
@@ -791,15 +791,15 @@ async def remove_offer(self, model_uuid, offer, force=False):
791791
raise RemoveError("removing offer will also remove relations, use force and try again.")
792792

793793
facade = client.ApplicationOffersFacade.from_connection(self.connection())
794-
return await facade.DestroyOffers(force, [url.string()])
794+
return await facade.DestroyOffers(force=force, offer_urls=[url.string()])
795795

796796
async def get_consume_details(self, endpoint):
797797
"""
798798
get_consume_details returns the details necessary to pass to another
799799
model to consume the specified offers represented by the urls.
800800
"""
801801
facade = client.ApplicationOffersFacade.from_connection(self.connection())
802-
offers = await facade.GetConsumeDetails([endpoint])
802+
offers = await facade.GetConsumeDetails(offer_urls=[endpoint])
803803
if len(offers.results) != 1:
804804
raise JujuAPIError("expected to find one result")
805805
result = offers.results[0]

juju/unit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ async def destroy(self):
9999
log.debug(
100100
'Destroying %s', self.name)
101101

102-
return await app_facade.DestroyUnits([self.name])
102+
return await app_facade.DestroyUnits(unit_names=[self.name])
103103
remove = destroy
104104

105105
def get_resources(self, details=False):

tests/integration/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ async def test_user_info(event_loop):
1313

1414
um = client.UserManagerFacade.from_connection(controller_conn)
1515
result = await um.UserInfo(
16-
[client.Entity('user-admin')], True)
16+
entities=[client.Entity('user-admin')], include_disabled=True)
1717
await controller_conn.close()
1818

1919
assert isinstance(result, client.UserInfoResults)

tests/integration/test_connection.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def test_full_status(event_loop):
6666

6767
c = client.ClientFacade.from_connection(model.connection())
6868

69-
await c.FullStatus(None)
69+
await c.FullStatus(patterns=None)
7070

7171

7272
@base.bootstrapped

tests/integration/test_errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ async def test_juju_error_in_result(event_loop):
6565
app_facade = client.ApplicationFacade.from_connection(model.connection())
6666

6767
with pytest.raises(JujuError):
68-
return await app_facade.GetCharmURL('foo')
68+
return await app_facade.GetCharmURL(application='foo')

tests/unit/test_definitions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,5 +68,5 @@ def test_parse(self):
6868
raise Exception("status relation is not a RelationStatus")
6969
if not isinstance(status.relations[0].endpoints[0], client.EndpointStatus):
7070
raise Exception("status relation endpoint is not a EndpointStatus")
71-
if not isinstance(status.applications['app'], client.ApplicationStatus):
71+
if not isinstance(status.get('applications')['app'], client.ApplicationStatus):
7272
raise Exception("status application is not a ApplicationStatus")

0 commit comments

Comments
 (0)