aboutsummaryrefslogtreecommitdiff
path: root/talerbank/app/tests.py
diff options
context:
space:
mode:
authorMarcello Stanisci <stanisci.m@gmail.com>2017-11-15 12:18:02 +0100
committerMarcello Stanisci <stanisci.m@gmail.com>2017-11-15 12:19:51 +0100
commit477f3bcf115abb84fbe6e5a27b8845da6a5ff6ab (patch)
tree485f2605796c739e3e15548a02602e7a6648447e /talerbank/app/tests.py
parent89a3315ca49be01357ad8987ab7e561e623fae97 (diff)
downloadbank-477f3bcf115abb84fbe6e5a27b8845da6a5ff6ab.tar.gz
bank-477f3bcf115abb84fbe6e5a27b8845da6a5ff6ab.tar.bz2
bank-477f3bcf115abb84fbe6e5a27b8845da6a5ff6ab.zip
check withdrawing POSTs the expected data to exchange
Diffstat (limited to 'talerbank/app/tests.py')
-rw-r--r--talerbank/app/tests.py30
1 files changed, 25 insertions, 5 deletions
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 2a76f62..55bea32 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -15,7 +15,6 @@
# @author Marcello Stanisci
import json
-import hashlib
from django.test import TestCase, Client
from django.core.urlresolvers import reverse
from django.conf import settings
@@ -35,7 +34,8 @@ class WithdrawTestCase(TestCase):
def setUp(self):
user_bankaccount = BankAccount(
user=User.objects.create_user(username="test_user",
- password="test_password"))
+ password="test_password"),
+ account_no=100)
user_bankaccount.save()
exchange_bankaccount = BankAccount(
@@ -45,7 +45,9 @@ class WithdrawTestCase(TestCase):
exchange_bankaccount.save()
@patch('hashlib.new') # Need to patch update() and hexdigest() methods.
- def test_withdraw(self, mocked_hashlib):
+ @patch('requests.post')
+ @patch('time.time')
+ def test_withdraw(self, mocked_time, mocked_post, mocked_hashlib):
client = Client()
wire_details = '''{
"test": {
@@ -74,10 +76,28 @@ class WithdrawTestCase(TestCase):
hasher.hexdigest = MagicMock()
hasher.hexdigest.return_value = "0"
mocked_hashlib.return_value = hasher
-
+ post = MagicMock()
+ post.status_code = 200
+ mocked_post.return_value = post
+ mocked_time.return_value = 0
response = client.post(reverse("pin-verify", urlconf=urls),
{"pin_1": "0"})
- print(response.content)
+ expected_json = {
+ "reserve_pub": "UVZ789",
+ "execution_date": "/Date(0)/",
+ "sender_account_details": {
+ "type": "test",
+ "bank_uri": "http://testserver/",
+ "account_number": 100
+ },
+ "transfer_details": {"timestamp": 0},
+ "amount": {
+ "value": 0,
+ "fraction": 1,
+ "currency": settings.TALER_CURRENCY}
+ }
+ mocked_post.assert_called_with("http://exchange.example/admin/add/incoming",
+ json=expected_json)
class RegisterTestCase(TestCase):
"""User registration"""