Skip to content

Commit

Permalink
marketplace: make sure customer id from api is returned as an int (PR…
Browse files Browse the repository at this point in the history
…OJQUAY-233) (quay#2590)

* make sure customer id from api is returned as an int
  • Loading branch information
Marcusk19 authored Jan 8, 2024
1 parent 1c893ba commit 2645176
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 3 additions & 0 deletions util/marketplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ def lookup_customer_id(self, email):
for account in info:
if account["accountRelationships"][0]["account"]["type"] == "person":
customer_id = account["accountRelationships"][0]["account"].get("id")
# convert str response from api to int value
if customer_id.isdigit():
customer_id = int(customer_id)
return customer_id
return None

Expand Down
2 changes: 1 addition & 1 deletion util/test/test_marketplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def test_user_lookup(self, requests_mock):
requests_mock.return_value.content = json.dumps(mocked_user_service_response)

customer_id = user_api.lookup_customer_id("[email protected]")
assert customer_id == "000000000"
assert customer_id == 000000000

requests_mock.return_value.content = json.dumps(mocked_organization_only_response)
customer_id = user_api.lookup_customer_id("[email protected]")
Expand Down
12 changes: 12 additions & 0 deletions workers/test/test_reconciliationworker.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,15 @@ def test_reconcile_different_ids(initialized_db):
mock.return_value = None
worker._perform_reconciliation(marketplace_users, marketplace_subscriptions)
assert model.entitlements.get_web_customer_id(test_user.id) is None


def test_update_same_id(initialized_db):
test_user = model.user.create_user("stripe_user", "password", "[email protected]")
test_user.stripe_id = "cus_" + "".join(random.choices(string.ascii_lowercase, k=14))
test_user.save()
model.entitlements.save_web_customer_id(test_user, 11111)

with patch.object(model.entitlements, "update_web_customer_id") as mock:
worker._perform_reconciliation(marketplace_users, marketplace_subscriptions)

mock.assert_not_called()

0 comments on commit 2645176

Please sign in to comment.