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

fix: error 500 lms/dashboard after applying ecommerse coupon #4003

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading