aboutsummaryrefslogtreecommitdiff
path: root/talerbank/app/tests.py
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2017-11-09 19:30:18 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2017-11-15 12:19:51 +0100
commit89a3315ca49be01357ad8987ab7e561e623fae97 (patch)
treebbfd8b7671eb7b0d35aa95f064d6c6fec3bc0100 /talerbank/app/tests.py
parentc68833bffd00e89873d9619422973025576e44b1 (diff)
downloadbank-89a3315ca49be01357ad8987ab7e561e623fae97.tar.gz
bank-89a3315ca49be01357ad8987ab7e561e623fae97.tar.bz2
bank-89a3315ca49be01357ad8987ab7e561e623fae97.zip
withdraw testcase -- missing exchange interaction mocking
Diffstat (limited to 'talerbank/app/tests.py')
-rw-r--r--talerbank/app/tests.py37
1 files changed, 28 insertions, 9 deletions
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 84ab430..2a76f62 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -15,10 +15,12 @@
# @author Marcello Stanisci
import json
+import hashlib
from django.test import TestCase, Client
from django.core.urlresolvers import reverse
from django.conf import settings
from django.contrib.auth.models import User
+from mock import patch, MagicMock, Mock
from .models import BankAccount, BankTransaction
from . import urls
from .views import wire_transfer
@@ -30,28 +32,36 @@ def clear_db():
BankTransaction.objects.all().delete()
class WithdrawTestCase(TestCase):
- # FIXME tbd
def setUp(self):
user_bankaccount = BankAccount(
user=User.objects.create_user(username="test_user",
password="test_password"))
user_bankaccount.save()
+
+ exchange_bankaccount = BankAccount(
+ user=User.objects.create_user(username="test_exchange",
+ password=""),
+ account_no=99)
+ exchange_bankaccount.save()
- def test_withdraw(self):
+ @patch('hashlib.new') # Need to patch update() and hexdigest() methods.
+ def test_withdraw(self, mocked_hashlib):
client = Client()
+ wire_details = '''{
+ "test": {
+ "type":"test",
+ "account_number":99,
+ "bank_uri":"http://bank.example/",
+ "name":"example"
+ }
+ }'''
params = {
"amount_value": "0",
"amount_fraction": "1",
"amount_currency": settings.TALER_CURRENCY,
"exchange": "http://exchange.example/",
"reserve_pub": "UVZ789",
- "wire_details": '''{
- "test":
- {"type":"test"},
- {"account_number":"99"},
- {"bank_uri":"http://bank.example/"},
- {"name":"example"}
- }'''
+ "wire_details": wire_details.replace("\n", "").replace(" ", "")
}
client.post(reverse("login", urlconf=urls),
{"username": "test_user",
@@ -59,6 +69,15 @@ class WithdrawTestCase(TestCase):
response = client.get(reverse("pin-question", urlconf=urls),
params)
+ # We mock hashlib in order to fake the CAPTCHA.
+ hasher = MagicMock()
+ hasher.hexdigest = MagicMock()
+ hasher.hexdigest.return_value = "0"
+ mocked_hashlib.return_value = hasher
+
+ response = client.post(reverse("pin-verify", urlconf=urls),
+ {"pin_1": "0"})
+ print(response.content)
class RegisterTestCase(TestCase):
"""User registration"""