This repository has been archived by the owner on Feb 28, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
68 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.core.management.base import BaseCommand | ||
|
||
from jarbas.core.models import Reimbursement | ||
|
||
|
||
class Command(BaseCommand): | ||
|
||
def handle(self, *args, **options): | ||
print('Loading…') | ||
queryset = Reimbursement.objects.filter(receipt_fetched=False) | ||
self.count = 0 | ||
|
||
for reimbursement in queryset: | ||
reimbursement.get_receipt_url() | ||
self.count += 1 | ||
self.print_count() | ||
|
||
self.print_count(permanent=True) | ||
print('Done!') | ||
|
||
def print_count(self, **kwargs): | ||
end = '\n' if kwargs.get('permanent') else '\r' | ||
print('{:,} receipt URLs fetched…'.format(self.count), end=end) |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from unittest.mock import call, patch | ||
|
||
from django.test import TestCase | ||
|
||
from jarbas.core.management.commands.receipts import Command | ||
from jarbas.core.models import Reimbursement | ||
from jarbas.core.tests import sample_reimbursement_data | ||
|
||
|
||
class TestCommand(TestCase): | ||
|
||
|
||
@patch.object(Reimbursement, 'get_receipt_url') | ||
@patch('jarbas.core.management.commands.receipts.print') | ||
def test_update(self, print_, get_receipt_url): | ||
Reimbursement.objects.create(**sample_reimbursement_data) | ||
command = Command() | ||
command.handle() | ||
self.assertEqual(1, get_receipt_url.call_count) | ||
self.assertEqual(1, command.count) | ||
print_.asset_has_calls([ | ||
call('Loading…'), | ||
call('1 receipt URLs fetched…', end='\r'), | ||
call('1 receipt URLs fetched…', end='\n'), | ||
call('Done!'), | ||
]) |
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