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

Commit

Permalink
feat: unenroll refunded android users daily (#4015)
Browse files Browse the repository at this point in the history
* 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
jawad-khan authored Aug 3, 2023
1 parent 3b1fcb0 commit e233314
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 0 deletions.
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'
)
)
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)

0 comments on commit e233314

Please sign in to comment.