This repository was 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.
Delegate create/update to Celery on data import
- Loading branch information
Showing
4 changed files
with
60 additions
and
90 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from celery import shared_task | ||
|
||
from jarbas.core.models import Reimbursement | ||
|
||
|
||
@shared_task | ||
def create_or_update_reimbursement(data): | ||
""" | ||
:param data: (dict) reimbursement data (keys and data types must mach | ||
Reimbursement model) | ||
""" | ||
kwargs = dict(document_id=data['document_id'], defaults=data) | ||
Reimbursement.objects.update_or_create(**kwargs) |
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 django.forms.models import model_to_dict | ||
from django.test import TestCase | ||
from mixer.backend.django import mixer | ||
|
||
from jarbas.core.models import Reimbursement | ||
from jarbas.core.tasks import create_or_update_reimbursement | ||
|
||
|
||
class TestCreateOrUpdateTask(TestCase): | ||
|
||
def test_create(self): | ||
with mixer.ctx(commit=False): | ||
fixture = model_to_dict(mixer.blend(Reimbursement)) | ||
|
||
self.assertEqual(0, Reimbursement.objects.count()) | ||
create_or_update_reimbursement(fixture) | ||
self.assertEqual(1, Reimbursement.objects.count()) | ||
|
||
def test_update(self): | ||
self.assertEqual(0, Reimbursement.objects.count()) | ||
|
||
fixture = model_to_dict(mixer.blend(Reimbursement)) | ||
self.assertEqual(1, Reimbursement.objects.count()) | ||
|
||
create_or_update_reimbursement(fixture) | ||
self.assertEqual(1, Reimbursement.objects.count()) |
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