Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LITE-28328: Handling cases in which the distributor doesn't have acce… #81

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions connect_ext_ppr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,11 @@ def get_all_listing_info(client, status='listed'):
for list_ in listings:
mkp_id = list_['contract']['marketplace']['id']
prd_id = list_['product']['id']
list_['contract']['marketplace'] = filter_object_list_by_id(marketplaces, mkp_id)
list_['product'] = filter_object_list_by_id(products, prd_id)
try:
Copy link
Contributor

@Hairash Hairash Aug 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[COD-C] Don't we want to add a comment here to explain the business cases, what do you think?

list_['contract']['marketplace'] = filter_object_list_by_id(marketplaces, mkp_id)
list_['product'] = filter_object_list_by_id(products, prd_id)
except KeyError:
pass
listings = [li for li in listings if li['contract']['marketplace'].get('hubs')]
return listings

Expand Down
52 changes: 51 additions & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,54 @@ def test_get_all_info_wo_any_unlisted_listing(connect_client, client_mocker_fact

client_mocker.listings.filter(R().status.eq('unlisted')).mock(return_value=[])

assert get_all_listing_info(connect_client) == []
assert get_all_listing_info(connect_client, status='unlisted') == []


def test_get_all_info_w_product_not_available(
connect_client,
client_mocker_factory,
listing,
marketplace,
):
client_mocker = client_mocker_factory(base_url=connect_client.endpoint)
client_mocker.marketplaces.filter(R().id.in_([marketplace['id']])).mock(
return_value=[marketplace],
)
rql = R().visibility.listing.eq(True)
rql |= R().visibility.syndication.eq(True)
rql &= R().id.in_([listing['product']['id']])
client_mocker.products.filter(rql).mock(return_value=[])

client_mocker.listings.filter(R().status.eq("unlisted")).mock(
return_value=[listing],
)

expected_response = copy.deepcopy(listing)
expected_response['contract']['marketplace'] = marketplace
assert get_all_listing_info(connect_client, status='unlisted') == [expected_response]


def test_get_all_info_w_marketplace_not_available(
connect_client,
client_mocker_factory,
listing,
product,
):
"""
get_all_listing_info filters listings wo hubs, so if we cannot return the marketplaces,
we are not going to have hubs, then we'll return an empty list in this case with only one item.
"""
client_mocker = client_mocker_factory(base_url=connect_client.endpoint)
client_mocker.marketplaces.filter(R().id.in_([listing['contract']['marketplace']['id']])).mock(
return_value=[],
)
rql = R().visibility.listing.eq(True)
rql |= R().visibility.syndication.eq(True)
rql &= R().id.in_([listing['product']['id']])
client_mocker.products.filter(rql).mock(return_value=[product])

client_mocker.listings.filter(R().status.eq('unlisted')).mock(
return_value=[listing],
)

assert get_all_listing_info(connect_client, status='unlisted') == []