gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] [taler-bank] branch master updated: Closing #5149.


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated: Closing #5149.
Date: Fri, 12 Jan 2018 16:18:34 +0100

This is an automated email from the git hooks/post-receive script.

marcello pushed a commit to branch master
in repository bank.

The following commit(s) were added to refs/heads/master by this push:
     new acdef0d  Closing #5149.
acdef0d is described below

commit acdef0d40a355fbccf89317a3084d4a2a94ef920
Author: Marcello Stanisci <address@hidden>
AuthorDate: Fri Jan 12 16:18:12 2018 +0100

    Closing #5149.
---
 talerbank/app/tests.py | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 97 insertions(+)

diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 8f5fd56..e7f830b 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -613,3 +613,100 @@ class MeasureHistory(TestCase):
         allowed_time_per_record = 0.003
         self.assertLess(
             total_time, self.ntransfers*allowed_time_per_record)
+
+class BalanceTestCase(TestCase):
+    
+    def setUp(self):
+        self.the_bank = BankAccount(
+            user=User.objects.create_user(
+                username='U0', password='U0PASS'),
+            amount=Amount(settings.TALER_CURRENCY, 3))
+        self.the_bank.save()
+
+        user = BankAccount(
+            user=User.objects.create_user(username='U'),
+            amount=Amount(settings.TALER_CURRENCY, 10))
+        user.save()
+
+        # bank: 3, user: 10 (START).
+
+        # bank: 2, user: 11
+        wire_transfer(Amount(settings.TALER_CURRENCY, 1),
+                      self.the_bank,
+                      user,
+                      "mock")
+
+        # bank: 4, user: 9 
+        wire_transfer(Amount(settings.TALER_CURRENCY, 2),
+                      user,
+                      self.the_bank,
+                      "mock")
+
+        # bank: -1, user: 14
+        wire_transfer(Amount(settings.TALER_CURRENCY, 5),
+                      self.the_bank,
+                      user,
+                      "mock")
+
+        # bank: 7, user: 6 (END)
+        wire_transfer(Amount(settings.TALER_CURRENCY, 8),
+                      user,
+                      self.the_bank,
+                      "mock")
+
+        # bank: -3, user: 16 (END)
+        wire_transfer(Amount(settings.TALER_CURRENCY, 10),
+                      user,
+                      self.the_bank,
+                      "mock")
+
+
+        self.client = Client()
+
+    def tearDown(self):
+        clear_db()
+
+    def test_balance(self):
+        self.client.login(username="U0",
+                          password="U0PASS")
+        response = self.client.get(
+            reverse("history", urlconf=urls),
+            {"auth": "basic",
+             "delta": 30,
+             "direction": "both",
+             "account_number": 55}, # unused
+            **{"HTTP_X_TALER_BANK_USERNAME": "U0",
+               "HTTP_X_TALER_BANK_PASSWORD": "U0PASS"})
+        data = response.content.decode("utf-8")
+        self.assertEqual(response.status_code, 200)
+        entries = json.loads(data)
+
+
+        acc_in = Amount(settings.TALER_CURRENCY)
+        acc_out = Amount(settings.TALER_CURRENCY)
+
+        for entry in entries["data"]:
+            if entry["sign"] == "+":
+                acc_in.add(Amount(**entry["amount"]))
+            if entry["sign"] == "-":
+                acc_out.add(Amount(**entry["amount"]))
+
+        expected_amount = Amount(settings.TALER_CURRENCY, 3)
+        try:
+            debit = False
+            acc_in.subtract(acc_out)
+            expected_amount.add(acc_in)
+        except ValueError:
+            # "out" is bigger than "in"
+            LOGGER.info("out > in")
+            acc_out.subtract(acc_in)
+            try:
+                expected_amount.subtract(acc_out)
+            except ValueError:
+                # initial amount wasn't enough to cover expenses
+                debit = True
+                acc_out.subtract(expected_amount)
+                expected_amount = acc_out
+
+        self.assertEqual(
+            Amount.cmp(expected_amount, self.the_bank.amount), 0)

-- 
To stop receiving notification emails like this one, please contact
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]