Skip to content

Commit 7a2a066

Browse files
test: Add comprehensive tests for user promo operations
This commit introduces a suite of tests for the user-facing promo code functionality, ensuring robustness and correctness. The new tests cover the following areas: - Promo Code Activation: - Verification of activation logic, including success and failure scenarios for common and unique promos. - Edge cases such as inactive promos, targeting mismatches, and exhausted activation limits (max_count). - Checks to prevent users who are blocked by the anti-fraud service from activating promos. - Promo Activation History: - Tests for the user's promo activation history endpoint. - Validation of the returned data and its order. - Pagination functionality (limit and offset). - Anti-Fraud Service Integration: - Unit tests for the AntiFraudService to verify its caching behavior and resilience to external service failures. - Integration tests to confirm that the promo activation process correctly respects the anti-fraud service's verdicts, including delayed updates from the cache.
1 parent c642efc commit 7a2a066

File tree

5 files changed

+934
-2
lines changed

5 files changed

+934
-2
lines changed

promo_code/user/tests/user/base.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
import django.conf
2+
import django.core.cache
13
import django.urls
4+
import django_redis
25
import rest_framework.test
36
import rest_framework_simplejwt.token_blacklist.models as tb_models
47

@@ -15,13 +18,21 @@ def setUpTestData(cls):
1518
cls.user_signin_url = django.urls.reverse('api-user:user-sign-in')
1619
cls.user_profile_url = django.urls.reverse('api-user:user-profile')
1720
cls.user_feed_url = django.urls.reverse('api-user:user-feed')
18-
21+
cls.user_promo_history_url = django.urls.reverse(
22+
'api-user:user-promo-history',
23+
)
1924
cls.company_signin_url = django.urls.reverse(
2025
'api-business:company-sign-in',
2126
)
2227
cls.promo_list_create_url = django.urls.reverse(
2328
'api-business:promo-list-create',
2429
)
30+
cls.antifraud_update_user_verdict_url = (
31+
django.conf.settings.ANTIFRAUD_UPDATE_USER_VERDICT_URL
32+
)
33+
cls.antifraud_set_delay_url = (
34+
django.conf.settings.ANTIFRAUD_SET_DELAY_URL
35+
)
2536

2637
company1_data = {
2738
'name': 'Digital Marketing Solutions Inc.',
@@ -68,11 +79,12 @@ def tearDown(self):
6879
business.models.Company.objects.all().delete()
6980
business.models.Promo.objects.all().delete()
7081
business.models.PromoCode.objects.all().delete()
82+
user.models.PromoActivationHistory.objects.all().delete()
7183
user.models.PromoComment.objects.all().delete()
7284
user.models.PromoLike.objects.all().delete()
7385
user.models.User.objects.all().delete()
7486
tb_models.BlacklistedToken.objects.all().delete()
75-
tb_models.OutstandingToken.objects.all().delete()
87+
django_redis.get_redis_connection('default').flushall()
7688
super().tearDown()
7789

7890
@classmethod
@@ -89,6 +101,13 @@ def get_user_promo_detail_url(cls, promo_id):
89101
kwargs={'id': promo_id},
90102
)
91103

104+
@classmethod
105+
def get_user_promo_activate_url(cls, promo_id):
106+
return django.urls.reverse(
107+
'api-user:user-promo-activate',
108+
kwargs={'id': promo_id},
109+
)
110+
92111
@classmethod
93112
def get_user_promo_like_url(cls, promo_id):
94113
return django.urls.reverse(

0 commit comments

Comments
 (0)