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
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroAlipov committed Jul 13, 2023
1 parent 3b1fcb0 commit 2583b6e
Show file tree
Hide file tree
Showing 2 changed files with 24 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 @@ -943,6 +943,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
23 changes: 23 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,29 @@ 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 2583b6e

Please sign in to comment.