diff --git a/apps/promotions/serializers.py b/apps/promotions/serializers.py index 1e1c8b9..3fd744d 100644 --- a/apps/promotions/serializers.py +++ b/apps/promotions/serializers.py @@ -3,22 +3,6 @@ from rest_framework import serializers from .models import Promotion, Plan, Event, Recipient -class PromotionSerializer(serializers.ModelSerializer): - # base_amount = serializers.IntegerField(required=True) - # promotion_amount = serializers.IntegerField(read_only=True) - user = serializers.UUIDField(source='user_uuid') - - class Meta: - model = Promotion - fields = ( - "uuid", - "base_amount", - "promotion_amount", - "state", - "user", - ) - - class EventSerializer(serializers.ModelSerializer): class Meta: model = Event @@ -31,6 +15,23 @@ class EventSerializer(serializers.ModelSerializer): read_only_fields = ('user', 'application') +class PromotionSerializer(serializers.ModelSerializer): + # base_amount = serializers.IntegerField(required=True) + # promotion_amount = serializers.IntegerField(read_only=True) + event = EventSerializer(read_only=True) + user = serializers.UUIDField(source='user_uuid') + + class Meta: + model = Promotion + fields = ( + "uuid", + "event", + "promotion_amount", + "state", + "user", + ) + + class PlanSerializer(serializers.ModelSerializer): base_amount = serializers.IntegerField(required=True) promotion_amount = serializers.IntegerField(read_only=True) diff --git a/apps/promotions/tests.py b/apps/promotions/tests.py index 5778446..68672a3 100644 --- a/apps/promotions/tests.py +++ b/apps/promotions/tests.py @@ -347,6 +347,9 @@ class ApplicationApiFlowsTests(APITestCase): def test_serial_ad_view_promotion_success(self): serial_id = 'b14e8b86-8f4a-44d9-b29d-badceb470053' + ad_1 = 'b14e8b86-8f4a-44d9-b29d-badceb470054' + ad_2 = 'b14e8b86-8f4a-44d9-b29d-badceb470055' + ad_3 = 'b14e8b86-8f4a-44d9-b29d-badceb470056' self.serial_ad_view_1_event_saver, _created = EventSaver.objects.get_or_create( title='serial_ad_view_1', event_label='serial_ad_view_1', @@ -411,29 +414,34 @@ class ApplicationApiFlowsTests(APITestCase): 'label': 'serial_ad_view_1', "data": { 'user': self.user_1_uuid, - 'serial': serial_id + 'serial': serial_id, + 'ad': ad_1 } } serial_ad_2_event_create_data = { 'label': 'serial_ad_view_2', "data": { 'user': self.user_1_uuid, - 'serial': serial_id + 'serial': serial_id, + 'ad': ad_2 } } serial_ad_3_event_create_data = { 'label': 'serial_ad_view_3', "data": { 'user': self.user_1_uuid, - 'serial': serial_id + 'serial': serial_id, + 'ad': ad_3 } } self.assertEqual(Event.objects.count(), 0) - response = self.client.post(reverse('promotions:promotion-create', kwargs={"plan":str(self.serial_promotion_plan.pk)}), serial_ad_1_event_create_data, HTTP_AUTHORIZATION=auth, format='json') + response = self.client.post(reverse('promotions:promotion-create', kwargs={"plan": str(self.serial_promotion_plan.pk)}), serial_ad_1_event_create_data, + HTTP_AUTHORIZATION=auth, format='json') print(response.json()) - response = self.client.post(reverse('promotions:promotion-create', kwargs={"plan":str(self.serial_promotion_plan.pk)}), serial_ad_2_event_create_data, HTTP_AUTHORIZATION=auth, format='json') + response = self.client.post(reverse('promotions:promotion-create', kwargs={"plan": str(self.serial_promotion_plan.pk)}), serial_ad_2_event_create_data, + HTTP_AUTHORIZATION=auth, format='json') # response = self.client.post(reverse('promotions:event-create'), serial_ad_2_event_create_data, HTTP_AUTHORIZATION=auth, format='json') print(response.json()) @@ -457,4 +465,3 @@ class ApplicationApiFlowsTests(APITestCase): self.assertEqual(self.serial_promotion_plan.balance, 100000) self.assertEqual(Event.objects.count(), 3) -