Skip to content
This repository has been archived by the owner on Feb 28, 2018. It is now read-only.

Commit

Permalink
Use concrete sample api response to test content
Browse files Browse the repository at this point in the history
  • Loading branch information
caiocarrara committed May 28, 2017
1 parent 8028754 commit 11560ff
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
39 changes: 39 additions & 0 deletions jarbas/api/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
def get_sample_reimbursement_api_response(obj):
return dict(
applicant_id=obj.applicant_id,
batch_number=obj.batch_number,
cnpj_cpf=obj.cnpj_cpf,
congressperson_document=obj.congressperson_document,
congressperson_id=obj.congressperson_id,
congressperson_name=obj.congressperson_name,
document_id=obj.document_id,
document_number=obj.document_number,
document_type=obj.document_type,
document_value=float(obj.document_value),
installment=obj.installment,
issue_date=obj.issue_date.strftime('%Y-%m-%d'),
leg_of_the_trip=obj.leg_of_the_trip,
month=obj.month,
party=obj.party,
passenger=obj.passenger,
all_reimbursement_numbers=obj.all_reimbursement_numbers,
all_reimbursement_values=obj.all_reimbursement_values,
all_net_values=obj.all_net_values,
remark_value=obj.remark_value,
state=obj.state,
subquota_description=obj.subquota_description,
subquota_group_description=obj.subquota_group_description,
subquota_group_id=obj.subquota_group_id,
subquota_id=obj.subquota_id,
supplier=obj.supplier,
term=obj.term,
term_id=obj.term_id,
total_net_value=float(obj.total_net_value),
total_reimbursement_value=obj.total_reimbursement_value,
year=obj.year,
probability=obj.probability,
suspicions=obj.suspicions,
last_update=obj.last_update.strftime('%Y-%m-%dT%H:%M:%SZ'),
available_in_latest_dataset=obj.available_in_latest_dataset,
receipt=dict(fetched=obj.receipt_fetched, url=obj.receipt_url)
)
10 changes: 5 additions & 5 deletions jarbas/api/tests/test_reimbursement_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from mixer.backend.django import mixer

from jarbas.core.models import Reimbursement
from jarbas.api.tests import get_sample_reimbursement_api_response


def get_reimbursement(**kwargs):
Expand Down Expand Up @@ -86,6 +87,9 @@ class TestRetrieveApi(TestCase):

def setUp(self):
self.reimbursement = get_reimbursement()
self.sample_response = get_sample_reimbursement_api_response(
self.reimbursement
)
url = resolve_url('api:reimbursement-detail',
document_id=self.reimbursement.document_id)
self.resp = self.client.get(url)
Expand All @@ -96,11 +100,7 @@ def test_status(self):

def test_contents(self):
contents = loads(self.resp.content.decode('utf-8'))
for result_attr, result_value in contents.items():
if not hasattr(self.reimbursement, result_attr):
continue
expected_value = getattr(self.reimbursement, result_attr)
self.assertEqual(str(result_value), str(expected_value))
self.assertEqual(self.sample_response, contents)


class TestReceiptApi(TestCase):
Expand Down

0 comments on commit 11560ff

Please sign in to comment.