Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
ENT-1052 Rename enterprise customer catalog uuid in queryparam to cat…
Browse files Browse the repository at this point in the history
…alog
  • Loading branch information
zubair-arbi authored and georgebabey committed Jul 3, 2018
1 parent 2b64948 commit 58174a6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 20 deletions.
24 changes: 11 additions & 13 deletions ecommerce/enterprise/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -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
)
Expand All @@ -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
6 changes: 3 additions & 3 deletions ecommerce/enterprise/tests/test_conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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

Expand Down
2 changes: 1 addition & 1 deletion ecommerce/extensions/basket/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions ecommerce/extensions/basket/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 58174a6

Please sign in to comment.