This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 254
feat: add additional fields to EnterpriseLearnerOfferApiSerializer #3963
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
69830e5
feat: add additional fields to EnterpriseLearnerOfferApiSerializer
adamstankiewicz 68fc826
chore: tests
adamstankiewicz 80063b7
chore: quality
adamstankiewicz 990090d
chore: updates
adamstankiewicz 5acf7cf
chore: quality
adamstankiewicz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,18 +17,19 @@ | |
class EnterpriseLearnerOfferApiSerializerTests(TestCase): | ||
|
||
@ddt.data( | ||
(100, '74.5'), | ||
(None, None) | ||
(100, 25.5, '74.5'), | ||
(None, None, None) | ||
) | ||
@ddt.unpack | ||
@mock.patch('ecommerce.extensions.api.serializers.sum_user_discounts_for_offer') | ||
def test_serialize_remaining_balance_for_user( | ||
self, | ||
max_user_discount, | ||
expected_remaining_balance, | ||
existing_user_spend, | ||
expected_remaining_balance_for_user, | ||
mock_sum_user_discounts_for_offer | ||
): | ||
mock_sum_user_discounts_for_offer.return_value = 25.5 | ||
mock_sum_user_discounts_for_offer.return_value = existing_user_spend | ||
enterprise_customer_uuid = str(uuid4()) | ||
condition = extended_factories.EnterpriseCustomerConditionFactory( | ||
enterprise_customer_uuid=enterprise_customer_uuid | ||
|
@@ -45,4 +46,90 @@ def test_serialize_remaining_balance_for_user( | |
} | ||
) | ||
data = serializer.to_representation(enterprise_offer) | ||
assert data['remaining_balance_for_user'] == expected_remaining_balance | ||
assert data['remaining_balance_for_user'] == expected_remaining_balance_for_user | ||
|
||
@ddt.data( | ||
(5250, '5250'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question unrelated to your change: why are we returning a string-ified number in this serializer? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the answer to this might be covered in the response to your other comment? |
||
(None, None) | ||
) | ||
@ddt.unpack | ||
@mock.patch('ecommerce.extensions.api.serializers.calculate_remaining_offer_balance') | ||
def test_serialize_remaining_balance( | ||
self, | ||
max_discount, | ||
expected_remaining_balance, | ||
mock_calculate_remaining_offer_balance | ||
): | ||
mock_calculate_remaining_offer_balance.return_value = max_discount | ||
enterprise_customer_uuid = str(uuid4()) | ||
condition = extended_factories.EnterpriseCustomerConditionFactory( | ||
enterprise_customer_uuid=enterprise_customer_uuid | ||
) | ||
enterprise_offer = extended_factories.EnterpriseOfferFactory.create( | ||
partner=self.partner, | ||
condition=condition, | ||
) | ||
serializer = EnterpriseLearnerOfferApiSerializer( | ||
data=enterprise_offer, | ||
context={ | ||
'request': mock.MagicMock(user=UserFactory()) | ||
} | ||
) | ||
data = serializer.to_representation(enterprise_offer) | ||
assert data['remaining_balance'] == expected_remaining_balance | ||
|
||
@ddt.data( | ||
(1000, 1000), | ||
(None, None) | ||
) | ||
@ddt.unpack | ||
def test_serialize_remaining_applications_for_user( | ||
self, | ||
max_user_applications, | ||
expected_remaining_applications_for_user, | ||
): | ||
enterprise_customer_uuid = str(uuid4()) | ||
condition = extended_factories.EnterpriseCustomerConditionFactory( | ||
enterprise_customer_uuid=enterprise_customer_uuid | ||
) | ||
enterprise_offer = extended_factories.EnterpriseOfferFactory.create( | ||
partner=self.partner, | ||
condition=condition, | ||
max_user_applications=max_user_applications, | ||
) | ||
serializer = EnterpriseLearnerOfferApiSerializer( | ||
data=enterprise_offer, | ||
context={ | ||
'request': mock.MagicMock(user=UserFactory()) | ||
} | ||
) | ||
data = serializer.to_representation(enterprise_offer) | ||
assert data['remaining_applications_for_user'] == expected_remaining_applications_for_user | ||
|
||
@ddt.data( | ||
(2, 2), | ||
(None, None) | ||
) | ||
@ddt.unpack | ||
def test_serialize_remaining_applications( | ||
self, | ||
max_global_applications, | ||
expected_remaining_applications, | ||
): | ||
enterprise_customer_uuid = str(uuid4()) | ||
condition = extended_factories.EnterpriseCustomerConditionFactory( | ||
enterprise_customer_uuid=enterprise_customer_uuid | ||
) | ||
enterprise_offer = extended_factories.EnterpriseOfferFactory.create( | ||
partner=self.partner, | ||
condition=condition, | ||
max_global_applications=max_global_applications, | ||
) | ||
serializer = EnterpriseLearnerOfferApiSerializer( | ||
data=enterprise_offer, | ||
context={ | ||
'request': mock.MagicMock(user=UserFactory()) | ||
} | ||
) | ||
data = serializer.to_representation(enterprise_offer) | ||
assert data['remaining_applications'] == expected_remaining_applications |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is balance
str()-ed
but applications are (presumably) ints?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@iloveagent57 I think the current state of the
enterprise-learner-offers
endpoint returns the balance as astr()
because course-discovery also returns price as a string, presumably so that clients don't have to format the returned value to have the 2 decimals. If returning a float with the UI wanted to display the price as$199.00
, would need to transform199
or199.0
to199.00
for display purposes, where if its given by the API as a string, the client can just render it as is.For this purpose of this PR, I'm just following convention with what already exists. That said, I'm not sure what the "standard"/"correct" way of returning price should be. I could see some tradeoffs with both approaches.
I kept applications as ints because there's no chance for them to be floats; the decimal formatting is a non-issue for applications.