-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding google sheets deferrals library (#1604)
- Loading branch information
Showing
7 changed files
with
100 additions
and
17 deletions.
There are no files selected for viewing
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
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
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
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
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
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 |
---|---|---|
@@ -1,18 +1,21 @@ | ||
import logging | ||
from mitol.google_sheets_refunds.api import RefundRequestHandler | ||
from mitol.google_sheets_deferrals.api import DeferralRequestHandler | ||
|
||
from main.celery import app | ||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
@app.task | ||
def process_refund_requests(): | ||
def process_google_sheets_requests(): | ||
""" | ||
Task to process refund requests from Google sheets | ||
Task to process refund and deferral requests from Google sheets | ||
""" | ||
refund_request_handler = RefundRequestHandler() | ||
if not refund_request_handler.is_configured(): | ||
log.warning("MITOL_GOOGLE_SHEETS_* are not set") | ||
return | ||
refund_request_handler.process_sheet() | ||
deferral_request_handler = DeferralRequestHandler() | ||
if refund_request_handler.is_configured(): | ||
refund_request_handler.process_sheet() | ||
|
||
if deferral_request_handler.is_configured(): | ||
deferral_request_handler.process_sheet() |
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 |
---|---|---|
@@ -1,34 +1,52 @@ | ||
import pytest | ||
|
||
from mitol.google_sheets_refunds.api import RefundRequestHandler | ||
from mitol.google_sheets_deferrals.api import DeferralRequestHandler | ||
|
||
from sheets.tasks import process_refund_requests | ||
from sheets.tasks import process_google_sheets_requests | ||
|
||
|
||
@pytest.mark.django_db | ||
@pytest.mark.parametrize( | ||
"is_configured", | ||
[True, False], | ||
"refunds_is_configured, deferrals_is_configured", | ||
[(True, True), (False, False)], | ||
) | ||
def test_process_refund_requests(mocker, user, is_configured): | ||
def test_process_google_sheets_requests( | ||
mocker, user, refunds_is_configured, deferrals_is_configured | ||
): | ||
""" | ||
Test that process_refund_requests calls process_sheet only if it is properly configured | ||
Test that process_google_sheets_requests calls process_sheet only if it is properly configured | ||
""" | ||
Mock = mocker.Mock | ||
MagicMock = mocker.MagicMock | ||
refund_req_handler = MagicMock( | ||
spec=RefundRequestHandler, process_sheet=Mock(), is_configured=Mock() | ||
) | ||
deferral_req_handler = MagicMock( | ||
spec=DeferralRequestHandler, process_sheet=Mock(), is_configured=Mock() | ||
) | ||
refund_req_handler_mock = mocker.patch( | ||
"sheets.tasks.RefundRequestHandler", | ||
return_value=refund_req_handler, | ||
) | ||
refund_req_handler.is_configured.return_value = is_configured | ||
deferral_req_handler_mock = mocker.patch( | ||
"sheets.tasks.DeferralRequestHandler", | ||
return_value=deferral_req_handler, | ||
) | ||
refund_req_handler.is_configured.return_value = refunds_is_configured | ||
deferral_req_handler.is_configured.return_value = deferrals_is_configured | ||
|
||
process_refund_requests.delay() | ||
process_google_sheets_requests.delay() | ||
refund_req_handler_mock.assert_called() | ||
refund_req_handler.is_configured.assert_called() | ||
if is_configured: | ||
deferral_req_handler_mock.assert_called() | ||
deferral_req_handler.is_configured.assert_called() | ||
if refunds_is_configured: | ||
refund_req_handler.process_sheet.assert_called() | ||
else: | ||
assert not refund_req_handler.process_sheet.called | ||
|
||
if deferrals_is_configured: | ||
deferral_req_handler.process_sheet.assert_called() | ||
else: | ||
assert not deferral_req_handler.process_sheet.called |