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

Commit

Permalink
fix: error 500 dashboard after applying ecommerse coupon (#4003)
Browse files Browse the repository at this point in the history
Co-authored-by: Muhammad Zubair <[email protected]>
  • Loading branch information
DmytroAlipov and zubair-ce07 authored Apr 8, 2024
1 parent 6fb6893 commit fe47e90
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
1 change: 1 addition & 0 deletions ecommerce/extensions/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,7 @@ class VoucherSerializer(serializers.ModelSerializer):
is_available_to_user = serializers.SerializerMethodField()
benefit = serializers.SerializerMethodField()
redeem_url = serializers.SerializerMethodField()
end_datetime = serializers.DateTimeField(format=ISO_8601_FORMAT)

def get_is_available_to_user(self, obj):
request = self.context.get('request')
Expand Down
24 changes: 24 additions & 0 deletions ecommerce/extensions/api/v2/tests/views/test_vouchers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,30 @@ def create_vouchers(self, partner=None, count=1):
coupon_vouchers.vouchers.add(voucher)
return vouchers

def test_generate_correct_end_datetime(self):
"""
Test that the 'end_datetime' parameter is generated in the correct format.
The 'end_datetime' parameter should be generated as a string in the
format '%Y-%m-%dT%H:%M:%SZ', representing the end date and time.
The created voucher's 'end_datetime' has the milliseconds part if to
retrieve it directly from the DB.
"""
self.create_vouchers()
response = self.client.get(self.path)
response_data = response.json()
result = response_data['results'][0]
end_datetime = result['end_datetime']
is_valid_format = False

try:
datetime.datetime.strptime(end_datetime, '%Y-%m-%dT%H:%M:%SZ')
is_valid_format = True
except ValueError:
pass

self.assertTrue(is_valid_format)

def test_list(self):
""" Verify the endpoint lists all vouchers. """
vouchers = self.create_vouchers(count=3)
Expand Down

0 comments on commit fe47e90

Please sign in to comment.