summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Boulanger <christophe.boulanger@imio.be>2018-03-07 15:35:48 (GMT)
committerChristophe Boulanger <christophe.boulanger@imio.be>2018-03-07 15:35:48 (GMT)
commit3511f0100b4a952473729cc538f1446afd09edb3 (patch)
tree41dfaac1fe73a6d8a861723f37846118f5d7f946
parent16c3a201fd44ceef23702bea6f37ad0a46d51eb6 (diff)
downloadpasserelle-imio-extra-fees-3511f0100b4a952473729cc538f1446afd09edb3.zip
passerelle-imio-extra-fees-3511f0100b4a952473729cc538f1446afd09edb3.tar.gz
passerelle-imio-extra-fees-3511f0100b4a952473729cc538f1446afd09edb3.tar.bz2
Add some unit tests : method compute.
-rw-r--r--passerelle_imio_extra_fees/tests/test_extra_fees.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/passerelle_imio_extra_fees/tests/test_extra_fees.py b/passerelle_imio_extra_fees/tests/test_extra_fees.py
new file mode 100644
index 0000000..b9c0a3c
--- /dev/null
+++ b/passerelle_imio_extra_fees/tests/test_extra_fees.py
@@ -0,0 +1,41 @@
+# DJANGO_SETTINGS_MODULE=passerelle.settings PASSERELLE_SETTINGS_FILE=tests/settings.py py.test --pdb
+
+import pytest
+import django_webtest
+
+from django.contrib.contenttypes.models import ContentType
+from passerelle_imio_extra_fees.models import ExtraFees
+from passerelle.base.models import ApiUser, AccessRight
+
+@pytest.fixture
+def app(request):
+ # creation de l'application Django
+ wtm = django_webtest.WebTestMixin()
+ wtm._patch_settings()
+ request.addfinalizer(wtm._unpatch_settings)
+ return django_webtest.DjangoTestApp()
+
+@pytest.fixture
+def connector(db):
+ # creation du connecteur et ouverture de la permission "can_access" sans authentification.
+ connector = ExtraFees.objects.create(slug='test')
+ api = ApiUser.objects.create(username='all', keytype='', key='')
+ obj_type = ContentType.objects.get_for_model(connector)
+ AccessRight.objects.create(
+ codename='can_access', apiuser=api,
+ resource_type=obj_type, resource_pk=connector.pk)
+ return connector
+
+def test_zero_fees_compute(app, connector):
+ dic ={'data':[]}
+ resp = app.post_json('/extra-fees/test/compute', params=dic)
+ assert resp.json.get('data')[0].get('amount') == '0.00'
+
+def test_fees_compute(app, connector):
+ connector.max_doc_in_letter = 5
+ connector.belgium_postage_fee = '0.5'
+ connector.save()
+ nb_document = 18
+ dic ={'data':[{'request_data':{'nb_documents':nb_document,'postage_fee':connector.belgium_postage_fee}}]}
+ resp = app.post_json('/extra-fees/test/compute', params=dic)
+ assert resp.json.get('data')[0].get('amount') == '2.00'