From f19b0749271bde0c68b9af5f11c34ab3877f9218 Mon Sep 17 00:00:00 2001 From: muhammad-ammar Date: Wed, 2 Dec 2020 18:21:16 +0500 Subject: [PATCH] try to get learner's enterprise information from DB if there is no enterprise customer associated with sso provider id ENT-3670 --- openedx/features/enterprise_support/api.py | 2 +- .../features/enterprise_support/tests/test_api.py | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/openedx/features/enterprise_support/api.py b/openedx/features/enterprise_support/api.py index bb5931e927..568b31026e 100644 --- a/openedx/features/enterprise_support/api.py +++ b/openedx/features/enterprise_support/api.py @@ -481,7 +481,7 @@ def enterprise_customer_uuid_for_request(request): else: enterprise_customer_uuid = _customer_uuid_from_query_param_cookies_or_session(request) - if enterprise_customer_uuid is _CACHE_MISS: + if enterprise_customer_uuid is _CACHE_MISS or enterprise_customer_uuid is None: if not request.user.is_authenticated: return None diff --git a/openedx/features/enterprise_support/tests/test_api.py b/openedx/features/enterprise_support/tests/test_api.py index 77bb24c2c5..fc57271bf3 100644 --- a/openedx/features/enterprise_support/tests/test_api.py +++ b/openedx/features/enterprise_support/tests/test_api.py @@ -866,19 +866,28 @@ class TestEnterpriseApi(EnterpriseServiceMockMixin, CacheIsolationTestCase): mock_partial_pipeline.assert_called_once_with(mock_request) self.assertNotIn(ENTERPRISE_CUSTOMER_KEY_NAME, mock_request.session) + @mock.patch('openedx.features.enterprise_support.api.get_enterprise_learner_data_from_db') @mock.patch('openedx.features.enterprise_support.api.get_partial_pipeline', return_value=None) - def test_customer_uuid_for_request_sso_provider_id_customer_non_existent(self, mock_partial_pipeline): + def test_customer_uuid_for_request_sso_provider_id_customer_non_existent_but_exist_in_db( + self, + mock_partial_pipeline, + mock_data_from_db, + ): + enterprise_customer_uuid = 'adab9a14-f263-42e6-a234-db707026c4a6' mock_request = mock.Mock( GET={'tpa_hint': 'my-third-party-auth'}, COOKIES={}, session={}, ) + mock_data_from_db.return_value = [ + {'enterprise_customer': {'uuid': enterprise_customer_uuid}}, + ] actual_uuid = enterprise_customer_uuid_for_request(mock_request) - self.assertIsNone(actual_uuid) + self.assertEqual(actual_uuid, enterprise_customer_uuid) mock_partial_pipeline.assert_called_once_with(mock_request) - self.assertNotIn(ENTERPRISE_CUSTOMER_KEY_NAME, mock_request.session) + self.assertIn(ENTERPRISE_CUSTOMER_KEY_NAME, mock_request.session) @mock.patch('openedx.features.enterprise_support.api.get_partial_pipeline', return_value=None) def test_enterprise_uuid_for_request_from_query_params(self, mock_partial_pipeline):