-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1864 from unicef/staging
Staging
- Loading branch information
Showing
83 changed files
with
1,338 additions
and
874 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from celery.utils.log import get_task_logger | ||
|
||
# Not scheduled by any code in this repo, but by other means, so keep it around. | ||
# Continues on to the next country on any VisionException, so no need to have | ||
# celery retry it in that case. | ||
from etools.applications.audit.purchase_order.synchronizers import POSynchronizer | ||
from etools.applications.users.models import Country | ||
from etools.applications.vision.exceptions import VisionException | ||
from etools.config.celery import app | ||
|
||
logger = get_task_logger(__name__) | ||
|
||
|
||
@app.task | ||
def update_purchase_orders(country_name=None): | ||
logger.info(u'Starting update values for purchase order') | ||
countries = Country.objects.filter(vision_sync_enabled=True) | ||
processed = [] | ||
if country_name is not None: | ||
countries = countries.filter(name=country_name) | ||
for country in countries: | ||
try: | ||
logger.info(u'Starting purchase order update for country {}'.format( | ||
country.name | ||
)) | ||
POSynchronizer(country).sync() | ||
processed.append(country.name) | ||
logger.info(u"Update finished successfully for {}".format(country.name)) | ||
except VisionException: | ||
logger.exception(u"{} sync failed".format(POSynchronizer.__name__)) | ||
# Keep going to the next country | ||
logger.info(u'Purchase orders synced successfully for {}.'.format(u', '.join(processed))) |
File renamed without changes.
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
14 changes: 14 additions & 0 deletions
14
src/etools/applications/audit/purchase_order/tests/test_tasks.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,14 @@ | ||
from unittest.mock import patch | ||
|
||
from etools.applications.EquiTrack.tests.cases import BaseTenantTestCase | ||
from etools.applications.audit.purchase_order.tasks import update_purchase_orders | ||
|
||
|
||
class TestUpdatePurchaseOrders(BaseTenantTestCase): | ||
|
||
@patch("etools.applications.audit.purchase_order.synchronizers.POSynchronizer.sync") | ||
@patch('etools.applications.audit.purchase_order.tasks.logger', spec=['info', 'error']) | ||
def test_update_purchase_orders(self, logger, mock_send): | ||
update_purchase_orders() | ||
self.assertEqual(mock_send.call_count, 1) | ||
self.assertEqual(logger.info.call_count, 4) |
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
Oops, something went wrong.