Skip to content

Commit

Permalink
Fixes (#145)
Browse files Browse the repository at this point in the history
* linter fixes

* passing tests

* moving aks offer test data to test/data, standardizing for all tests

* removing TODOs from setup

* removing method to implement offer plan update since there's nothing to update on it, currently (only its listing)

* fix call inside package
  • Loading branch information
kevinhillinger committed Dec 7, 2022
1 parent 136fd90 commit 0db3dac
Show file tree
Hide file tree
Showing 36 changed files with 391 additions and 481 deletions.
20 changes: 10 additions & 10 deletions partnercenter/azext_partnercenter/clients/offer_listing_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,17 @@ def get_plan_listing(self, offer_external_id, plan_external_id):
resource=Resource(id=listing.id, type=listing.resource_type)
)

def create_or_update(self, offer_id, listing_model: Listing, plan_external_id=None):
offer = self._offer_client.get(offer_id)
def create_or_update(self, offer_external_id, listing_model: Listing, plan_external_id=None):
offer = self._offer_client.get(offer_external_id)
if offer is None:
return None
product_id = offer._resource.durable_id

listing = None
if plan_external_id is None:
listing = self._offer_client.get_listing(offer_id)
listing = self._offer_client.get_listing(offer_external_id)
else:
listing = self.get_plan_listing(offer_id, plan_external_id)
listing = self.get_plan_listing(offer_external_id, plan_external_id)

if listing is None:
return None
Expand Down Expand Up @@ -106,21 +106,21 @@ def create_or_update(self, offer_id, listing_model: Listing, plan_external_id=No
)

def get_contacts(self, offer_external_id):
listing = self.get_listing(offer_external_id)
listing = self.get(offer_external_id)
return listing.contacts

def update_contacts(self, offer_external_id, parameters=list[ListingContact]):
listing = self.get_listing(offer_external_id)
listing = self.get(offer_external_id)
listing.contacts = parameters
result = self.create_or_update(offer_external_id, listing)
return result.contacts

def get_uris(self, offer_external_id):
listing = self.get_listing(offer_external_id)
listing = self.get(offer_external_id)
return listing.uris

def update_uris(self, offer_external_id, parameters=list[ListingUri]):
listing = self.get_listing(offer_external_id)
listing = self.get(offer_external_id)
listing.uris = parameters
result = self.create_or_update(offer_external_id, listing)
return result.uris
Expand Down Expand Up @@ -178,8 +178,8 @@ def delete_latest_listing_uri(self, product_external_id):
del listing.uris[0]
return self.create_or_update(product_external_id, listing)

def get_listing(self, product_external_id):
return self._offer_client.get_listing(product_external_id)
def get(self, offer_external_id):
return self._offer_client.get_listing(offer_external_id)

def _get_product_listing_branches(self, product_external_id):
offer = self._offer_client.get(product_external_id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@

def load_arguments(commands_loader, _):
with commands_loader.argument_context('partnercenter marketplace offer listing') as c:
c.argument('offer_id', options_list=['--offer-id'], help='The offer ID of the Offer.')
c.argument('offer_id', options_list=['--offer-id'], help='The offer ID.')

with commands_loader.argument_context('partnercenter marketplace offer listing update') as c:
c.argument('offer_external_id', options_list=['--offer-id'], help='The offer ID.')
c.argument('summary', options_list=['--summary'], help='The summary that appears in search results.')
c.argument('short_description', options_list=['--short-description'], help='The short description of the listing.')
c.argument('description', options_list=['--description'], help='The description of the listing.')
c.argument('description', options_list=['--description'], help='The description of the listing.')
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,9 @@


def load_command_table(commands_loader, _):
command_type = CliCommandType(operations_tmpl='azext_partnercenter.clients#OfferListingClient.{}', client_factory=cf_offer_listing)
custom_command_type = CliCommandType(operations_tmpl='azext_partnercenter.operations.marketplace_offer_listing.custom#{}', client_factory=cf_offer_listing)

with commands_loader.command_group('partnercenter marketplace offer listing', custom_command_type=custom_command_type, is_preview=True) as g:
g.custom_show_command('show', table_transformer=None)
g.custom_command('delete', 'offer_listing_delete', confirmation=True)
g.generic_update_command('update',
getter_name='_update_get',
setter_name='_update_set',
setter_type=custom_command_type,
getter_type=custom_command_type,
custom_func_name='update_listing',
custom_func_type=custom_command_type,
client_factory=cf_offer_listing)
with commands_loader.command_group('partnercenter marketplace offer listing', command_type=command_type, custom_command_type=custom_command_type, is_preview=True) as g:
g.custom_show_command('show', 'get_listing', table_transformer=None)
g.generic_update_command('update', custom_func_name='update_listing', getter_name='get', setter_name='create_or_update', setter_arg_name='listing_model')
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------
# pylint: disable=line-too-long

from azext_partnercenter.models.listing import Listing


def get(client, offer_id):
return client.get_listing(offer_id)
def get_listing(client, offer_id):
return client.get(offer_id)


def update_listing(instance, summary=None, short_description=None, description=None):
Expand All @@ -21,28 +18,3 @@ def update_listing(instance, summary=None, short_description=None, description=N
if description is not None:
instance.description = description
return instance


def marketplace_offer_listing_delete(client, offer_id):
return client.delete_offer_listing(offer_id)


def _update_get(client, offer_id):
return client.get_listing(offer_id)


def _update_set(client, offer_id, parameters):
listing = Listing(
offer_id=offer_id,
title=parameters.title,
summary=parameters.summary,
description=parameters.description,
short_description=parameters.short_description,
language_code=parameters.language_code,
odata_etag=parameters.odata_etag,
contacts=parameters.contacts,
uris=parameters.uris
)

result = client.create_or_update(offer_id, listing)
return result
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def add_contact(instance, contact_type, email=None, name=None, phone=None, uri=N


def list_contact(client, offer_id):
listing = client.get_listing(offer_id)
listing = client.get(offer_id)
if listing is None:
raise ResourceNotFoundError('An Offer was not found with that ID.', 'Please check the value set for parameter --offer-id.')
return listing.contacts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ def add_uri(instance, uri_type, subtype, display_text, uri):


def list_uri(client, offer_id):
plan_listing = client.get_listing(offer_id)
if not plan_listing:
listing = client.get(offer_id)
if not listing:
raise CLIError(f'Offer \'{offer_id}\' not found.')
return plan_listing.uris
return listing.uris


def delete_uri(client, offer_id, uri_type=None, subtype=None, display_text=None, uri=None):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _run_container(container_name, mount_path):


def _get_mount_path(manifest_file):
return os.path.dirname(manifest_file)
return os.path.abspath(os.path.dirname(manifest_file))


def _get_acr_name(manifest_file):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ def _execute_action_by_offer_type(client, offer_id, action):

offer_type = offer.type

if offer_type == OfferType.AZUREAPPLICATION:
if offer_type == OfferType.AZURECONTAINER:
offer_setup = client.get_setup(offer_id)
# if the offer type is "AzureApplication" AND the offer is setup to sell through Microsoft, we can build a CNAB bundle for it
if offer_setup.sell_through_microsoft:
action()
return
else:
raise InvalidArgumentValueError(f'{offer_id} offer is not setup to support a CNAB bundle. The offer type must be {OfferType.AZUREAPPLICATION} and setup to sell through Microsoft',
f'Update the offer\'s setup to sell through Microsoft.\n\n az partercenter marketplace offer setup --offer-id {offer_id} --sell-through-microsoft')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,6 @@ def create_plan(client, offer_id, plan_id, friendly_name):
return result


def update_plan(instance):
# TODO: Implement partnercenter marketplace offer update
return instance


def delete_plan(client, offer_id, plan_id):
return client.delete(offer_id, plan_id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def load_command_table(commands_loader, _):
custom_command_type = CliCommandType(operations_tmpl='azext_partnercenter.operations.marketplace_offer_plan_listing.custom#{}', client_factory=cf_offer_listing)

with commands_loader.command_group('partnercenter marketplace offer plan listing', custom_command_type=custom_command_type, is_preview=True) as g:
g.custom_command('show', 'get_listing')
g.custom_show_command('show', 'get_listing')
g.generic_update_command('update',
getter_name='_listing_update_get',
setter_name='_listing_update_set',
Expand Down
2 changes: 1 addition & 1 deletion partnercenter/azext_partnercenter/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class TestData:
TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))
"""The root test directory path"""

def __init__(self, test_data_dir='latest/data'):
def __init__(self, test_data_dir='data'):
self.test_data_dir = os.path.join(self.TEST_DIR, test_data_dir).replace('\\', '\\\\')
self._ensure_dir(self.test_data_dir)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 0db3dac

Please sign in to comment.