This repository has been archived by the owner on Nov 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 254
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: unenroll refunded android users daily (#4015)
* feat: unenroll refunded android users daily Django management command to un-enroll refunded android users. This command will be run by Jenkins job daily.
- Loading branch information
1 parent
3b1fcb0
commit e233314
Showing
2 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
ecommerce/core/management/commands/tests/test_unenroll_refunded_android_users.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
""" | ||
Tests for Django management command to un-enroll refunded android users. | ||
""" | ||
from django.core.management import call_command | ||
from mock import patch | ||
from testfixtures import LogCapture | ||
|
||
from ecommerce.tests.testcases import TestCase | ||
|
||
|
||
class TestUnenrollRefundedAndroidUsersCommand(TestCase): | ||
|
||
LOGGER_NAME = 'ecommerce.core.management.commands.unenroll_refunded_android_users' | ||
|
||
@patch('requests.get') | ||
def test_handle_pass(self, mock_response): | ||
""" Test using mock response from setup, using threshold it will clear""" | ||
|
||
mock_response.return_value.status_code = 200 | ||
|
||
with LogCapture(self.LOGGER_NAME) as log: | ||
call_command('unenroll_refunded_android_users') | ||
|
||
log.check( | ||
( | ||
self.LOGGER_NAME, | ||
'INFO', | ||
'Sending request to un-enroll refunded android users' | ||
) | ||
) | ||
|
||
@patch('requests.get') | ||
def test_handle_fail(self, mock_response): | ||
""" Test using mock response from setup, using threshold it will clear""" | ||
|
||
mock_response.return_value.status_code = 400 | ||
|
||
with LogCapture(self.LOGGER_NAME) as log: | ||
call_command('unenroll_refunded_android_users') | ||
|
||
log.check( | ||
( | ||
self.LOGGER_NAME, | ||
'INFO', | ||
'Sending request to un-enroll refunded android users' | ||
), | ||
( | ||
self.LOGGER_NAME, | ||
'ERROR', | ||
'Failed to refund android users with status code 400' | ||
) | ||
) |
27 changes: 27 additions & 0 deletions
27
ecommerce/core/management/commands/unenroll_refunded_android_users.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
""" | ||
Django management command to un-enroll refunded android users. | ||
Command is run by Jenkins job daily. | ||
""" | ||
import logging | ||
|
||
import requests | ||
from django.core.management.base import BaseCommand | ||
from rest_framework import status | ||
|
||
from ecommerce.core.models import SiteConfiguration | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
help = 'Management command to un-enroll refunded android users.' | ||
|
||
def handle(self, *args, **options): | ||
site = SiteConfiguration.objects.first() | ||
refund_api_url = '{}/api/iap/v1/android/refund/'.format(site.build_ecommerce_url()) | ||
logger.info("Sending request to un-enroll refunded android users") | ||
response = requests.get(refund_api_url) | ||
|
||
if response.status_code != status.HTTP_200_OK: | ||
logger.error("Failed to refund android users with status code %s", response.status_code) |