Skip to content

Commit

Permalink
marketplace: add a check for masterEndSystemName when fetching subscr…
Browse files Browse the repository at this point in the history
…iptions (PROJQUAY-6905) (quay#2775)

* add a check for masterEndSystemName when fetching subscriptions
* allow old SKUs to be used in org attachments
  • Loading branch information
Marcusk19 authored Mar 25, 2024
1 parent 09df48b commit 131d66d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 3 deletions.
4 changes: 1 addition & 3 deletions data/billing.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,9 +374,7 @@
},
]

RH_SKUS = [
plan["rh_sku"] for plan in PLANS if plan.get("rh_sku") is not None and plan.get("sku_billing")
]
RH_SKUS = [plan["rh_sku"] for plan in PLANS if plan.get("rh_sku") is not None]

RECONCILER_SKUS = [
plan["rh_sku"]
Expand Down
14 changes: 14 additions & 0 deletions test/test_api_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -5191,6 +5191,20 @@ def test_expired_attachment(self):
json = self.getJsonResponse(OrgPrivateRepositories, params=dict(orgname=SUBSCRIPTION_ORG))
self.assertEqual(json["privateAllowed"], False)

def test_reconciled_attachment(self):
self.login(SUBSCRIPTION_USER)
self.postResponse(
resource_name=OrganizationRhSku,
params=dict(orgname=SUBSCRIPTION_ORG),
data={"subscriptions": [{"subscription_id": 87654321, "quantity": 1}]},
expected_code=401,
)
json = self.getJsonResponse(
resource_name=OrganizationRhSku,
params=dict(orgname=SUBSCRIPTION_ORG),
)
self.assertEqual(len(json), 0)


class TestUserSku(ApiTestCase):
def test_get_user_skus(self):
Expand Down
25 changes: 25 additions & 0 deletions util/marketplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ def get_list_of_subscriptions(
if subscriptions:
for user_subscription in subscriptions:
if user_subscription is not None:
if user_subscription["masterEndSystemName"] == "SUBSCRIPTION":
continue

bound_to_org = organization_skus.subscription_bound_to_org(
user_subscription["id"]
)
Expand All @@ -250,6 +253,9 @@ def get_list_of_subscriptions(
return subscription_list


# Mocked classes for unit tests


TEST_USER = {
"account_number": 12345,
"email": "subscriptions@devtable.com",
Expand Down Expand Up @@ -286,6 +292,21 @@ def get_list_of_subscriptions(
"effectiveEndDate": 3813177600000,
},
],
"reconciled_subscription": {
"id": 87654321,
"masterEndSystemName": "SUBSCRIPTION",
"createdEndSystemName": "SUBSCRIPTION",
"createdDate": 1675957362000,
"lastUpdateEndSystemName": "SUBSCRIPTION",
"lastUpdateDate": 1675957362000,
"installBaseStartDate": 1707368400000,
"installBaseEndDate": 1707368399000,
"webCustomerId": 123456,
"subscriptionNumber": "12399889",
"quantity": 1,
"effectiveStartDate": 1707368400000,
"effectiveEndDate": 3813177600000,
},
}
STRIPE_USER = {"account_number": 11111, "email": "stripe_user@test.com", "username": "stripe_user"}
FREE_USER = {
Expand Down Expand Up @@ -322,6 +343,8 @@ def __init__(self):
def lookup_subscription(self, customer_id, sku_id):
if customer_id == TEST_USER["account_number"] and sku_id == "MW02701":
return TEST_USER["subscriptions"]
elif customer_id == TEST_USER["account_number"] and sku_id == "MW00584MO":
return [TEST_USER["reconciled_subscription"]]
return None

def create_entitlement(self, customer_id, sku_id):
Expand All @@ -336,6 +359,8 @@ def get_subscription_details(self, subscription_id):
return {"sku": "MW02701", "expiration_date": 3813177600000}
elif subscription_id == 80808080:
return {"sku": "MW02701", "expiration_date": 1645544830000}
elif subscription_id == 87654321:
return {"sku": "MW00584MO", "expiration_date": 3813177600000}
else:
return None

Expand Down

0 comments on commit 131d66d

Please sign in to comment.