diff --git a/ecommerce/enterprise/conditions.py b/ecommerce/enterprise/conditions.py index a4fa456e535..2b5d6fa26ae 100644 --- a/ecommerce/enterprise/conditions.py +++ b/ecommerce/enterprise/conditions.py @@ -33,7 +33,7 @@ def is_satisfied(self, offer, basket): # pylint: disable=unused-argument Determines if a user is eligible for an enterprise customer offer based on their association with the enterprise customer. - It also verifies the catalog `enterprise_customer_catalog_uuid` on the + It also verifies the catalog `catalog` on the offer with the catalog on the basket when provided. Args: @@ -74,9 +74,9 @@ def is_satisfied(self, offer, basket): # pylint: disable=unused-argument # Verify that the current conditional offer is related to the provided # enterprise catalog - enterprise_customer_catalog_uuid = self._get_enterprise_catalog_uuid_from_basket(basket) - if enterprise_customer_catalog_uuid: - if str(offer.condition.enterprise_customer_catalog_uuid) != enterprise_customer_catalog_uuid: + catalog = self._get_enterprise_catalog_uuid_from_basket(basket) + if catalog: + if str(offer.condition.enterprise_customer_catalog_uuid) != catalog: return False if not catalog_contains_course_runs(basket.site, course_run_ids, self.enterprise_customer_uuid, @@ -96,15 +96,13 @@ def _get_enterprise_catalog_uuid_from_basket(basket): basket (Basket): The provided basket can be either temporary (just for calculating discounts) or an actual one to buy a product. """ - # For temporary basket try to get `enterprise_customer_catalog_uuid` - # from request - enterprise_customer_catalog_uuid = basket.strategy.request.GET.get( - 'enterprise_customer_catalog_uuid' + # For temporary basket try to get `catalog` from request + catalog = basket.strategy.request.GET.get( + 'catalog' ) if basket.strategy.request else None - if not enterprise_customer_catalog_uuid: - # For actual baskets get `enterprise_customer_catalog_uuid` from - # basket attribute + if not catalog: + # For actual baskets get `catalog` from basket attribute enterprise_catalog_attribute, __ = BasketAttributeType.objects.get_or_create( name=ENTERPRISE_CATALOG_ATTRIBUTE_TYPE ) @@ -113,6 +111,6 @@ def _get_enterprise_catalog_uuid_from_basket(basket): attribute_type=enterprise_catalog_attribute, ).first() if enterprise_customer_catalog: - enterprise_customer_catalog_uuid = enterprise_customer_catalog.value_text + catalog = enterprise_customer_catalog.value_text - return enterprise_customer_catalog_uuid + return catalog diff --git a/ecommerce/enterprise/tests/test_conditions.py b/ecommerce/enterprise/tests/test_conditions.py index 91fcdd7bd78..755d0c54356 100644 --- a/ecommerce/enterprise/tests/test_conditions.py +++ b/ecommerce/enterprise/tests/test_conditions.py @@ -78,7 +78,7 @@ def test_is_satisfied_true_for_enterprise_catalog_in_get_request(self): enterprise_catalog_uuid = str(self.condition.enterprise_customer_catalog_uuid) basket = factories.BasketFactory(site=self.site, owner=self.user) basket.strategy.request = self.request - basket.strategy.request.GET = {'enterprise_customer_catalog_uuid': enterprise_catalog_uuid} + basket.strategy.request.GET = {'catalog': enterprise_catalog_uuid} self._check_condition_is_satisfied(offer, basket, is_satisfied=True) @httpretty.activate @@ -89,7 +89,7 @@ def test_is_satisfied_true_for_enterprise_catalog_in_basket_attribute(self): offer = factories.EnterpriseOfferFactory(site=self.site, condition=self.condition) enterprise_catalog_uuid = str(self.condition.enterprise_customer_catalog_uuid) basket = factories.BasketFactory(site=self.site, owner=self.user) - request_data = {'enterprise_customer_catalog_uuid': enterprise_catalog_uuid} + request_data = {'catalog': enterprise_catalog_uuid} basket_add_enterprise_catalog_attribute(basket, request_data) self._check_condition_is_satisfied(offer, basket, is_satisfied=True) @@ -103,7 +103,7 @@ def test_is_satisfied_false_for_invalid_enterprise_catalog(self): invalid_enterprise_catalog_uuid = str(uuid4()) basket = factories.BasketFactory(site=self.site, owner=self.user) basket.strategy.request = self.request - basket.strategy.request.GET = {'enterprise_customer_catalog_uuid': invalid_enterprise_catalog_uuid} + basket.strategy.request.GET = {'catalog': invalid_enterprise_catalog_uuid} self._check_condition_is_satisfied(offer, basket, is_satisfied=False) assert invalid_enterprise_catalog_uuid != offer.condition.enterprise_customer_catalog_uuid diff --git a/ecommerce/extensions/basket/tests/test_utils.py b/ecommerce/extensions/basket/tests/test_utils.py index ac19f760836..273ae056364 100644 --- a/ecommerce/extensions/basket/tests/test_utils.py +++ b/ecommerce/extensions/basket/tests/test_utils.py @@ -426,7 +426,7 @@ def test_prepare_basket_with_enterprise_catalog(self): product = ProductFactory() request = self.request expected_enterprise_catalog_uuid = str(uuid4()) - request.GET = {'enterprise_customer_catalog_uuid': expected_enterprise_catalog_uuid} + request.GET = {'catalog': expected_enterprise_catalog_uuid} basket = prepare_basket(request, [product]) # Verify that the enterprise catalog attribute exists for the basket diff --git a/ecommerce/extensions/basket/utils.py b/ecommerce/extensions/basket/utils.py index 468a9d3f35e..6738a7ddc0f 100644 --- a/ecommerce/extensions/basket/utils.py +++ b/ecommerce/extensions/basket/utils.py @@ -281,9 +281,9 @@ def basket_add_enterprise_catalog_attribute(basket, request_data): request_data (dict): HttpRequest data """ - # Value of enterprise catalog UUID is being passed as - # `enterprise_customer_catalog_uuid` from basket page - enterprise_catalog_uuid = request_data.get('enterprise_customer_catalog_uuid') if request_data else None + # Value of enterprise catalog UUID is being passed as `catalog` from + # basket page + enterprise_catalog_uuid = request_data.get('catalog') if request_data else None if enterprise_catalog_uuid: enterprise_catalog_attribute, __ = BasketAttributeType.objects.get_or_create(