From ef127eed23264363279a83ba3099285b4e780864 Mon Sep 17 00:00:00 2001 From: Alexander Dusenbery Date: Fri, 5 Dec 2025 10:08:24 -0500 Subject: [PATCH] fix: correct update subs plan URL and payload and unittest --- .../apps/api_client/license_manager_client.py | 6 ++-- .../tests/test_license_manager_client.py | 28 +++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/enterprise_access/apps/api_client/license_manager_client.py b/enterprise_access/apps/api_client/license_manager_client.py index 49c96ae5..68b27d55 100644 --- a/enterprise_access/apps/api_client/license_manager_client.py +++ b/enterprise_access/apps/api_client/license_manager_client.py @@ -14,6 +14,7 @@ NEW_SUBSCRIPTION_CHANGE_REASON = 'new' +OTHER_SUBSCRIPTION_CHANGE_REASON = 'other' class LicenseManagerApiClient(BaseOAuthClient): @@ -226,9 +227,10 @@ def update_subscription_plan(self, subscription_uuid, salesforce_opportunity_lin Raises: APIClientException: If the API call fails """ - endpoint = f"{self.subscriptions_endpoint}{subscription_uuid}/" + endpoint = f"{self.subscription_provisioning_endpoint}{subscription_uuid}/" payload = { - 'salesforce_opportunity_line_item': salesforce_opportunity_line_item + 'salesforce_opportunity_line_item': salesforce_opportunity_line_item, + 'change_reason': OTHER_SUBSCRIPTION_CHANGE_REASON, } try: diff --git a/enterprise_access/apps/api_client/tests/test_license_manager_client.py b/enterprise_access/apps/api_client/tests/test_license_manager_client.py index 83224730..b6c06714 100644 --- a/enterprise_access/apps/api_client/tests/test_license_manager_client.py +++ b/enterprise_access/apps/api_client/tests/test_license_manager_client.py @@ -12,6 +12,7 @@ from enterprise_access.apps.api_client.exceptions import APIClientException from enterprise_access.apps.api_client.license_manager_client import ( NEW_SUBSCRIPTION_CHANGE_REASON, + OTHER_SUBSCRIPTION_CHANGE_REASON, LicenseManagerApiClient, LicenseManagerUserApiClient ) @@ -133,6 +134,33 @@ def test_create_subscription_plan(self, mock_oauth_client): json=expected_payload, ) + @mock.patch('enterprise_access.apps.api_client.base_oauth.OAuthAPIClient', autospec=True) + def test_update_subscription_plan(self, mock_oauth_client): + mock_patch = mock_oauth_client.return_value.patch + subs_plan_uuid = uuid.uuid4() + new_oli_value = '1234512345' + + lm_client = LicenseManagerApiClient() + + result = lm_client.update_subscription_plan( + subs_plan_uuid, new_oli_value, + ) + + self.assertEqual(result, mock_patch.return_value.json.return_value) + expected_url = ( + 'http://license-manager.example.com' + f'/api/v1/provisioning-admins/subscriptions/{subs_plan_uuid}/' + ) + expected_payload = { + 'salesforce_opportunity_line_item': new_oli_value, + 'change_reason': OTHER_SUBSCRIPTION_CHANGE_REASON, + } + mock_patch.assert_called_once_with( + expected_url, + json=expected_payload, + timeout=settings.LICENSE_MANAGER_CLIENT_TIMEOUT, + ) + class TestLicenseManagerUserApiClient(MockLicenseManagerMetadataMixin): """