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 (dbe8e1d -> c685201)


From: gnunet
Subject: [GNUnet-SVN] [taler-bank] branch master updated (dbe8e1d -> c685201)
Date: Fri, 03 Nov 2017 17:53:37 +0100

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

marcello pushed a change to branch master
in repository bank.

    from dbe8e1d  if then
     new 505cbc4  remove (dead) sample_donations and linting accounts generator
     new 5c876a2  pylint
     new f25b666  linting
     new c685201  linting

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 INCLUDE.APP                                        |   1 -
 talerbank/app/amount.py                            |  44 +--
 talerbank/app/checks.py                            |  11 +-
 talerbank/app/management/commands/Makefile.am      |   3 +-
 talerbank/app/management/commands/dump_talerdb.py  |  12 +-
 .../app/management/commands/sample_donations.py    |  71 -----
 talerbank/app/models.py                            |   9 +-
 talerbank/app/schemas.py                           |  22 +-
 talerbank/app/tests.py                             | 303 +++++++++++----------
 talerbank/app/tests_alt.py                         |  13 +-
 talerbank/app/urls.py                              |   4 +-
 talerbank/talerconfig.py                           |   4 +-
 12 files changed, 215 insertions(+), 282 deletions(-)
 delete mode 100644 talerbank/app/management/commands/sample_donations.py

diff --git a/INCLUDE.APP b/INCLUDE.APP
index c35d472..11f4a11 100644
--- a/INCLUDE.APP
+++ b/INCLUDE.APP
@@ -5,7 +5,6 @@ talerbank/app/funds_mgmt.py
 talerbank/app/history.py
 talerbank/app/lib.py
 talerbank/app/management/commands/pre_accounts.py
-talerbank/app/management/commands/sample_donations.py
 talerbank/app/models.py
 talerbank/app/my-static/style.css
 talerbank/app/privileged_accounts.py
diff --git a/talerbank/app/amount.py b/talerbank/app/amount.py
index 9a6318a..6c17610 100644
--- a/talerbank/app/amount.py
+++ b/talerbank/app/amount.py
@@ -42,12 +42,12 @@ class Amount:
 
     def __init__(self, currency, value=0, fraction=0):
         # type: (str, int, int) -> Amount
-        assert(value >= 0 and fraction >= 0)
+        assert value >= 0 and fraction >= 0
         self.value = value
         self.fraction = fraction
         self.currency = currency
         self.__normalize()
-        assert(self.value <= Amount.MAX_VALUE())
+        assert self.value <= Amount.MAX_VALUE()
 
     # Normalize amount
     def __normalize(self):
@@ -59,7 +59,7 @@ class Amount:
     # instantiating an amount object.
     @classmethod
     def parse(cls, amount_str):
-        exp = '^\s*([-_*A-Za-z0-9]+):([0-9]+)\.([0-9]+)\s*$'
+        exp = r'^\s*([-_*A-Za-z0-9]+):([0-9]+)\.([0-9]+)\s*$'
         import re
         parsed = re.search(exp, amount_str)
         if not parsed:
@@ -75,16 +75,16 @@ class Amount:
     # 0 if a == b
     # 1 if a > b
     @staticmethod
-    def cmp(a, b):
-        if a.currency != b.currency:
+    def cmp(am1, am2):
+        if am1.currency != am2.currency:
             raise CurrencyMismatch()
-        if a.value == b.value:
-            if a.fraction < b.fraction:
+        if am1.value == am2.value:
+            if am1.fraction < am2.fraction:
                 return -1
-            if a.fraction > b.fraction:
+            if am1.fraction > am2.fraction:
                 return 1
             return 0
-        if a.value < b.value:
+        if am1.value < am2.value:
             return -1
         return 1
 
@@ -94,34 +94,34 @@ class Amount:
         self.fraction = fraction
 
     # Add the given amount to this one
-    def add(self, a):
-        if self.currency != a.currency:
+    def add(self, amount):
+        if self.currency != amount.currency:
             raise CurrencyMismatch()
-        self.value += a.value
-        self.fraction += a.fraction
+        self.value += amount.value
+        self.fraction += amount.fraction
         self.__normalize()
 
     # Subtract passed amount from this one
-    def subtract(self, a):
-        if self.currency != a.currency:
+    def subtract(self, amount):
+        if self.currency != amount.currency:
             raise CurrencyMismatch()
-        if self.fraction < a.fraction:
+        if self.fraction < amount.fraction:
             self.fraction += Amount.FRACTION()
             self.value -= 1
-        if self.value < a.value:
+        if self.value < amount.value:
             raise ValueError('self is lesser than amount to be subtracted')
-        self.value -= a.value
-        self.fraction -= a.fraction
+        self.value -= amount.value
+        self.fraction -= amount.fraction
 
     # Dump string from this amount, will put 'ndigits' numbers
     # after the dot.
     def stringify(self, ndigits):
         assert ndigits > 0
         ret = '%s:%s.' % (self.currency, str(self.value))
-        f = self.fraction
+        fraction = self.fraction
         for i in range(0, ndigits):
-            ret += str(int(f / (Amount.FRACTION() / 10)))
-            f = (f * 10) % (Amount.FRACTION())
+            ret += str(int(fraction / (Amount.FRACTION() / 10)))
+            fraction = (fraction * 10) % (Amount.FRACTION())
         return ret
 
     # Dump the Taler-compliant 'dict' amount
diff --git a/talerbank/app/checks.py b/talerbank/app/checks.py
index 6734d3a..7d50adb 100644
--- a/talerbank/app/checks.py
+++ b/talerbank/app/checks.py
@@ -1,4 +1,4 @@
-from django.core.checks import register, Warning
+from django.core.checks import register
 from django.db.utils import OperationalError
 
 
@@ -16,9 +16,8 @@ def example_check(app_configs, **kwargs):
                 id='talerbank.E001'
             ))
     except OperationalError:
-            errors.append(Warning(
-                'Presumably non existent database',
-                hint="create a database for the application",
-                id='talerbank.E002'
-            ))
+        errors.append(Warning(
+            'Presumably non existent database',
+            hint="create a database for the application",
+            id='talerbank.E002'))
     return errors
diff --git a/talerbank/app/management/commands/Makefile.am 
b/talerbank/app/management/commands/Makefile.am
index 3fc6f2d..cec82a7 100644
--- a/talerbank/app/management/commands/Makefile.am
+++ b/talerbank/app/management/commands/Makefile.am
@@ -3,5 +3,4 @@ SUBDIRS = .
 EXTRA_DIST = \
   dump_talerdb.py \
   __init__.py \
-  provide_accounts.py \
-  sample_donations.py
+  provide_accounts.py
diff --git a/talerbank/app/management/commands/dump_talerdb.py 
b/talerbank/app/management/commands/dump_talerdb.py
index dc6d81f..5685da1 100644
--- a/talerbank/app/management/commands/dump_talerdb.py
+++ b/talerbank/app/management/commands/dump_talerdb.py
@@ -14,13 +14,13 @@
 #
 #  @author Marcello Stanisci
 
+import sys
+import logging
 from django.core.management.base import BaseCommand
-from ...models import BankAccount, BankTransaction
 from django.db.utils import OperationalError, ProgrammingError
-import logging
-import sys
+from ...models import BankAccount, BankTransaction
 
-logger = logging.getLogger(__name__)
+LOGGER = logging.getLogger(__name__)
 
 def dump_accounts():
     try:
@@ -31,7 +31,7 @@ def dump_accounts():
         for acc in accounts:
             print(acc.user.username + " has account number " + 
str(acc.account_no))
     except (OperationalError, ProgrammingError):
-        logger.error("likely causes: non existent DB or unmigrated project\n"
+        LOGGER.error("likely causes: non existent DB or unmigrated project\n"
                      "(try 'taler-bank-manage django migrate' in the latter 
case)",
                      stack_info=False,
                      exc_info=True)
@@ -51,7 +51,7 @@ def dump_history():
             msg.append(item.subject)
             print(''.join(msg))
     except (OperationalError, ProgrammingError):
-        logger.error("likely causes: non existent DB or unmigrated project\n"
+        LOGGER.error("likely causes: non existent DB or unmigrated project\n"
                      "(try 'taler-bank-manage django migrate' in the latter 
case)",
                      stack_info=False,
                      exc_info=True)
diff --git a/talerbank/app/management/commands/sample_donations.py 
b/talerbank/app/management/commands/sample_donations.py
deleted file mode 100644
index 35749a6..0000000
--- a/talerbank/app/management/commands/sample_donations.py
+++ /dev/null
@@ -1,71 +0,0 @@
-#  This file is part of TALER
-#  (C) 2014, 2015, 2106 INRIA
-#
-#  TALER is free software; you can redistribute it and/or modify it under the
-#  terms of the GNU General Public License as published by the Free Software
-#  Foundation; either version 3, or (at your option) any later version.
-#
-#  TALER is distributed in the hope that it will be useful, but WITHOUT ANY
-#  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
FOR
-#  A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
-#
-#  You should have received a copy of the GNU General Public License along with
-#  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
-#
-#  @author Marcello Stanisci
-
-from random import randint
-from django.core.management.base import BaseCommand
-from ...funds import wire_transfer_in_out
-from django.conf import settings
-from django.db.utils import OperationalError, ProgrammingError
-from ...models import BankAccount
-import logging
-import sys
-
-logger = logging.getLogger(__name__)
-
-public_accounts = []
-def sample_donations():
-    counter = -1
-    try:
-        public_accounts = BankAccount.objects.filter(is_public=True)
-        if len(public_accounts) is 0:
-            logger.warning("No public accounts still activated. Run 
'taler-bank-manage"
-                           " django provide_accounts' first")            
-        for account in public_accounts:
-            logger.debug("*")
-            for i in range(0, 9):
-                counter += 1
-                if account.user.username in settings.TALER_EXPECTS_DONATIONS:
-                    value = randint(1, 100)
-                    try:
-                        # 1st take money from bank and give to exchange
-                        wire_transfer_in_out({'value': value,
-                                              'fraction': 0,
-                                              'currency': 
settings.TALER_CURRENCY},
-                                             1,
-                                             2,
-                                             "Test-withdrawal-%d" % counter)
-    
-                        # 2nd take money from exchange and give to donation 
receiver
-                        wire_transfer_in_out({'value': value,
-                                              'fraction': 0,
-                                              'currency': 
settings.TALER_CURRENCY},
-                                             2,
-                                             account.account_no,
-                                             "Test-donation-%d" % counter)
-                    except BankAccount.DoesNotExist:
-                        logger.error("(At least) one account is not found. Run 
"
-                                     "'taler-bank-manage django 
provide_accounts' beforehand")
-                        sys.exit(1)
-    except (ProgrammingError, OperationalError):
-        logger.error("likely causes: non existent DB or unmigrated project\n"
-                     "(try 'taler-bank-manage django migrate' in the latter 
case)",
-                     stack_info=False,
-                     exc_info=True)
-        sys.exit(1)
-
-class Command(BaseCommand):
-    def handle(self, *args, **options):
-        sample_donations()
diff --git a/talerbank/app/models.py b/talerbank/app/models.py
index ebbb9f0..064dbed 100644
--- a/talerbank/app/models.py
+++ b/talerbank/app/models.py
@@ -19,12 +19,13 @@ from __future__ import unicode_literals
 from django.contrib.auth.models import User
 from django.db import models
 from django.conf import settings
+from django.core.exceptions import ValidationError
 from . import amount
 
 class AmountField(models.Field):
-    
+
     description = 'Amount object in Taler style'
-    
+
     def __init__(self, *args, **kwargs):
         super(AmountField, self).__init__(*args, **kwargs)
 
@@ -53,8 +54,8 @@ class AmountField(models.Field):
             if None is value:
                 return amount.Amount.parse(settings.TALER_CURRENCY)
             return amount.Amount.parse(value)
-        except amount.BadAmount:
-            raise models.ValidationError()
+        except amount.BadFormatAmount:
+            raise ValidationError("Invalid input for an amount string: %s" % 
value)
 
 def get_zero_amount():
     return amount.Amount(settings.TALER_CURRENCY)
diff --git a/talerbank/app/schemas.py b/talerbank/app/schemas.py
index 91771d1..e43947d 100644
--- a/talerbank/app/schemas.py
+++ b/talerbank/app/schemas.py
@@ -20,9 +20,8 @@ definitions of JSON schemas for validating data
 """
 
 import validictory
-from django.core.exceptions import ValidationError
 
-wiredetails_schema = {
+WIREDETAILS_SCHEMA = {
     "type": "object",
     "properties": {
         "test": {
@@ -37,7 +36,7 @@ wiredetails_schema = {
     }
 }
 
-auth_schema = {
+AUTH_SCHEMA = {
     "type": "object",
     "properties": {
         "type": {"type": "string"},
@@ -45,7 +44,7 @@ auth_schema = {
     }
 }
 
-amount_schema = {
+AMOUNT_SCHEMA = {
     "type": "object",
     "properties": {
         "value": {"type": "integer"},
@@ -54,25 +53,22 @@ amount_schema = {
     }
 }
 
-incoming_request_schema = {
+INCOMING_REQUEST_SCHEMA = {
     "type": "object",
     "properties": {
-        "amount": {"type": amount_schema},
+        "amount": {"type": AMOUNT_SCHEMA},
         "wtid": {"type": "string"},
         "exchange_url": {"type": "string"},
         "credit_account": {"type": "integer"},
-        "auth": auth_schema
+        "auth": AUTH_SCHEMA
     }
 }
 
 def validate_amount(amount):
-    validictory.validate(amount, amount_schema)
+    validictory.validate(amount, AMOUNT_SCHEMA)
 
 def validate_wiredetails(wiredetails):
-    validictory.validate(wiredetails, wiredetails_schema)
+    validictory.validate(wiredetails, WIREDETAILS_SCHEMA)
 
 def validate_incoming_request(incoming_request):
-    validictory.validate(incoming_request, incoming_request_schema)
-
-def validate_auth_basic(auth_basic):
-    validictory.validate(auth_basic, auth_basic_schema)
+    validictory.validate(incoming_request, INCOMING_REQUEST_SCHEMA)
diff --git a/talerbank/app/tests.py b/talerbank/app/tests.py
index 435fd7d..2e5a83b 100644
--- a/talerbank/app/tests.py
+++ b/talerbank/app/tests.py
@@ -14,6 +14,7 @@
 #
 #  @author Marcello Stanisci
 
+import json
 from django.test import TestCase, Client
 from django.core.urlresolvers import reverse
 from django.conf import settings
@@ -21,14 +22,9 @@ from django.contrib.auth.models import User
 from .models import BankAccount, BankTransaction
 from . import urls
 from .views import wire_transfer
-import json
 from .amount import Amount, CurrencyMismatch, BadFormatAmount
 
-import logging
-
-logger = logging.getLogger(__name__)
-
-def clearDb():
+def clear_db():
     User.objects.all().delete()
     BankAccount.objects.all().delete()
     BankTransaction.objects.all().delete()
@@ -39,19 +35,19 @@ class RegisterTestCase(TestCase):
 
     def setUp(self):
         bank = User.objects.create_user(username='Bank')
-        ba = BankAccount(user=bank)
-        ba.account_no = 1
-        ba.save() 
+        bank_bankaccount = BankAccount(user=bank)
+        bank_bankaccount.account_no = 1
+        bank_bankaccount.save()
 
     def tearDown(self):
-        clearDb()
+        clear_db()
 
     def test_register(self):
-        c = Client()
-        response = c.post(reverse("register", urlconf=urls),
-                          {"username": "test_register",
-                           "password": "test_register"},
-                           follow=True)
+        client = Client()
+        response = client.post(reverse("register", urlconf=urls),
+                               {"username": "test_register",
+                                "password": "test_register"},
+                               follow=True)
         self.assertIn(("/profile", 302), response.redirect_chain)
         # this assertion tests "/profile""s view
         self.assertEqual(200, response.status_code)
@@ -62,20 +58,20 @@ class RegisterWrongCurrencyTestCase(TestCase):
 
     # Activating this user with a faulty currency.
     def setUp(self):
-        ba = BankAccount(user=User.objects.create_user(username='Bank'),
-            amount=Amount('WRONGCURRENCY'))
-        ba.account_no = 1
-        ba.save() 
+        user_bankaccount = 
BankAccount(user=User.objects.create_user(username='Bank'),
+                                       amount=Amount('WRONGCURRENCY'))
+        user_bankaccount.account_no = 1
+        user_bankaccount.save()
 
     def tearDown(self):
-        clearDb()
+        clear_db()
 
     def test_register(self):
-        c = Client()
-        response = c.post(reverse("register", urlconf=urls),
-                          {"username": "test_register",
-                           "password": "test_register"},
-                           follow=True)
+        client = Client()
+        response = client.post(reverse("register", urlconf=urls),
+                               {"username": "test_register",
+                                "password": "test_register"},
+                               follow=True)
         # A currency mismatch is expected when the 100 KUDOS will be
         # attempted to be given to the new user.
         # This scenario expects a 500 Internal server error response to
@@ -88,47 +84,47 @@ class LoginTestCase(TestCase):
     def setUp(self):
         user = User.objects.create_user(username="test_user",
                                         password="test_password")
-        user_account = BankAccount(user=user)
-        user_account.save()
+        user_bankaccount = BankAccount(user=user)
+        user_bankaccount.save()
 
     def tearDown(self):
-        clearDb()
-    
+        clear_db()
+
     def test_login(self):
-        c = Client()
-        response = c.post(reverse("login", urlconf=urls),
-                          {"username": "test_user",
-                           "password": "test_password"},
-                           follow=True)
+        client = Client()
+        response = client.post(reverse("login", urlconf=urls),
+                               {"username": "test_user",
+                                "password": "test_password"},
+                               follow=True)
         self.assertIn(("/profile", 302), response.redirect_chain)
 
         # Send wrong password
-        response = c.post(reverse("login", urlconf=urls),
-                          {"username": "test_user",
-                           "password": "test_passwordoo"},
-                           follow=True)
+        response = client.post(reverse("login", urlconf=urls),
+                               {"username": "test_user",
+                                "password": "test_passwordoo"},
+                               follow=True)
         # The current logic -- django's default -- returns 200 OK
         # even when the login didn't succeed.
         # So the test here ensures that the bank just doesn't crash.
         self.assertEqual(200, response.status_code)
 
 class AmountTestCase(TestCase):
-    
+
     def test_cmp(self):
-        a1 = Amount("X", 1)
-        _a1 = Amount("X", 1)
-        a2 = Amount("X", 2)
-        
-        self.assertEqual(-1, Amount.cmp(a1, a2))
-        self.assertEqual(1, Amount.cmp(a2, a1))
-        self.assertEqual(0, Amount.cmp(a1, _a1))
+        amount1 = Amount("X", 1)
+        _amount1 = Amount("X", 1)
+        amount2 = Amount("X", 2)
+
+        self.assertEqual(-1, Amount.cmp(amount1, amount2))
+        self.assertEqual(1, Amount.cmp(amount2, amount1))
+        self.assertEqual(0, Amount.cmp(amount1, _amount1))
 
     # Trying to compare amount of different currencies
     def test_cmp_diff_curr(self):
-        a1 = Amount("X", 1)
-        a2 = Amount("Y", 2)
+        amount1 = Amount("X", 1)
+        amount2 = Amount("Y", 2)
         try:
-            Amount.cmp(a1, a2)
+            Amount.cmp(amount1, amount2)
         except CurrencyMismatch:
             self.assertTrue(True)
             return
@@ -150,10 +146,10 @@ class AddIncomingTestCase(TestCase):
         user_account.save()
 
     def tearDown(self):
-        clearDb()
+        clear_db()
 
     def test_add_incoming(self):
-        c = Client()
+        client = Client()
         data = '{"auth": {"type": "basic"}, \
                  "credit_account": 1, \
                  "wtid": "TESTWTID", \
@@ -163,10 +159,11 @@ class AddIncomingTestCase(TestCase):
                     "fraction": 0, \
                     "currency": "%s"}}' \
                % settings.TALER_CURRENCY
-        response = c.post(reverse("add-incoming", urlconf=urls),
-                          data=data,
-                          content_type="application/json",
-                          follow=True, **{"HTTP_X_TALER_BANK_USERNAME": 
"user_user", "HTTP_X_TALER_BANK_PASSWORD": "user_password"})
+        response = client.post(reverse("add-incoming", urlconf=urls),
+                               data=data,
+                               content_type="application/json",
+                               follow=True, **{"HTTP_X_TALER_BANK_USERNAME": 
"user_user",
+                                               "HTTP_X_TALER_BANK_PASSWORD": 
"user_password"})
         self.assertEqual(200, response.status_code)
         data = '{"auth": {"type": "basic"}, \
                  "credit_account": 1, \
@@ -177,10 +174,11 @@ class AddIncomingTestCase(TestCase):
                     "fraction": 0, \
                     "currency": "%s"}}' \
                % "WRONGCURRENCY"
-        response = c.post(reverse("add-incoming", urlconf=urls),
-                          data=data,
-                          content_type="application/json",
-                          follow=True, **{"HTTP_X_TALER_BANK_USERNAME": 
"user_user", "HTTP_X_TALER_BANK_PASSWORD": "user_password"})
+        response = client.post(reverse("add-incoming", urlconf=urls),
+                               data=data,
+                               content_type="application/json",
+                               follow=True, **{"HTTP_X_TALER_BANK_USERNAME": 
"user_user",
+                                               "HTTP_X_TALER_BANK_PASSWORD": 
"user_password"})
         self.assertEqual(406, response.status_code)
 
         # Try to go debit
@@ -193,149 +191,168 @@ class AddIncomingTestCase(TestCase):
                     "fraction": 1, \
                     "currency": "%s"}}' \
                % settings.TALER_CURRENCY
-        response = c.post(reverse("add-incoming", urlconf=urls),
-                          data=data,
-                          content_type="application/json",
-                          follow=True, **{"HTTP_X_TALER_BANK_USERNAME": 
"user_user", "HTTP_X_TALER_BANK_PASSWORD": "user_password"})
+        response = client.post(reverse("add-incoming", urlconf=urls),
+                               data=data,
+                               content_type="application/json",
+                               follow=True, **{"HTTP_X_TALER_BANK_USERNAME": 
"user_user",
+                                               "HTTP_X_TALER_BANK_PASSWORD": 
"user_password"})
         self.assertEqual(403, response.status_code)
 
 
 class HistoryTestCase(TestCase):
 
     def setUp(self):
-        user = User.objects.create_user(username='User', password="Password")
-        ub = BankAccount(user=user, amount=Amount(settings.TALER_CURRENCY, 
100))
-        ub.account_no = 1
-        ub.save() 
-        user_passive = User.objects.create_user(username='UserP', 
password="PasswordP")
-        ub_p = BankAccount(user=user_passive)
-        ub_p.account_no = 2
-        ub_p.save() 
+        user = User.objects.create_user(username='User',
+                                        password="Password")
+        user_bankaccount = BankAccount(user=user,
+                                       amount=Amount(settings.TALER_CURRENCY, 
100))
+        user_bankaccount.account_no = 1
+        user_bankaccount.save()
+        user_passive = User.objects.create_user(username='UserP',
+                                                password="PasswordP")
+        user_bankaccount_p = BankAccount(user=user_passive)
+        user_bankaccount_p.account_no = 2
+        user_bankaccount_p.save()
         one = Amount(settings.TALER_CURRENCY, 1)
-        wire_transfer(one, ub, ub_p, subject="a")
-        wire_transfer(one, ub, ub_p, subject="b")
-        wire_transfer(one, ub, ub_p, subject="c")
-        wire_transfer(one, ub, ub_p, subject="d")
-        wire_transfer(one, ub, ub_p, subject="e")
-        wire_transfer(one, ub, ub_p, subject="f")
-        wire_transfer(one, ub, ub_p, subject="g")
-        wire_transfer(one, ub, ub_p, subject="h")
+        wire_transfer(one, user_bankaccount, user_bankaccount_p, subject="a")
+        wire_transfer(one, user_bankaccount, user_bankaccount_p, subject="b")
+        wire_transfer(one, user_bankaccount, user_bankaccount_p, subject="c")
+        wire_transfer(one, user_bankaccount, user_bankaccount_p, subject="d")
+        wire_transfer(one, user_bankaccount, user_bankaccount_p, subject="e")
+        wire_transfer(one, user_bankaccount, user_bankaccount_p, subject="f")
+        wire_transfer(one, user_bankaccount, user_bankaccount_p, subject="g")
+        wire_transfer(one, user_bankaccount, user_bankaccount_p, subject="h")
 
     def tearDown(self):
-        clearDb()
+        clear_db()
 
     def test_history(self):
-        c = Client()
+        client = Client()
 
-        response = c.get(reverse("history", urlconf=urls), {"auth": "basic", 
"delta": "+4"},
-                         **{"HTTP_X_TALER_BANK_USERNAME": "User", 
"HTTP_X_TALER_BANK_PASSWORD": "Password"})
+        response = client.get(reverse("history", urlconf=urls), {"auth": 
"basic", "delta": "+4"},
+                              **{"HTTP_X_TALER_BANK_USERNAME": "User",
+                                 "HTTP_X_TALER_BANK_PASSWORD": "Password"})
         self.assertEqual(200, response.status_code)
 
         # Get a delta=+1 record in the middle of the list
-        response = c.get(reverse("history", urlconf=urls), {"auth": "basic", 
"delta": "+1", "start": "5"},
-                         **{"HTTP_X_TALER_BANK_USERNAME": "User", 
"HTTP_X_TALER_BANK_PASSWORD": "Password"})
+        response = client.get(reverse("history", urlconf=urls),
+                              {"auth": "basic", "delta": "+1", "start": "5"},
+                              **{"HTTP_X_TALER_BANK_USERNAME": "User",
+                                 "HTTP_X_TALER_BANK_PASSWORD": "Password"})
         data = response.content.decode("utf-8")
         data = json.loads(data)
         self.assertEqual(data["data"][0]["row_id"], 6)
         # Get latest record
-        response = c.get(reverse("history", urlconf=urls), {"auth": "basic", 
"delta": "-1"},
-                         **{"HTTP_X_TALER_BANK_USERNAME": "User", 
"HTTP_X_TALER_BANK_PASSWORD": "Password"})
+        response = client.get(reverse("history", urlconf=urls),
+                              {"auth": "basic", "delta": "-1"},
+                              **{"HTTP_X_TALER_BANK_USERNAME": "User",
+                                 "HTTP_X_TALER_BANK_PASSWORD": "Password"})
         data = response.content.decode("utf-8")
         data = json.loads(data)
         self.assertEqual(data["data"][0]["wt_subject"], "h")
-        # Get non-existent record: the latest plus one in the future: 
transaction "h" takes row_id 11
-        response = c.get(reverse("history", urlconf=urls), {"auth": "basic", 
"delta": "1", "start": "11"},
-                         **{"HTTP_X_TALER_BANK_USERNAME": "User", 
"HTTP_X_TALER_BANK_PASSWORD": "Password"})
-        response_txt = response.content.decode("utf-8")
+        # Get non-existent record: the latest plus one in the future:
+        # transaction "h" takes row_id 11
+        response = client.get(reverse("history", urlconf=urls),
+                              {"auth": "basic", "delta": "1", "start": "11"},
+                              **{"HTTP_X_TALER_BANK_USERNAME": "User",
+                                 "HTTP_X_TALER_BANK_PASSWORD": "Password"})
         self.assertEqual(204, response.status_code)
         # Get credit records
-        response = c.get(reverse("history", urlconf=urls), {"auth": "basic", 
"delta": "+1", "direction": "credit"},
-                         **{"HTTP_X_TALER_BANK_USERNAME": "User", 
"HTTP_X_TALER_BANK_PASSWORD": "Password"})
+        response = client.get(reverse("history", urlconf=urls),
+                              {"auth": "basic", "delta": "+1", "direction": 
"credit"},
+                              **{"HTTP_X_TALER_BANK_USERNAME": "User",
+                                 "HTTP_X_TALER_BANK_PASSWORD": "Password"})
         self.assertEqual(204, response.status_code)
         # Get debit records
-        response = c.get(reverse("history", urlconf=urls), {"auth": "basic", 
"delta": "+1", "direction": "debit"},
-                         **{"HTTP_X_TALER_BANK_USERNAME": "User", 
"HTTP_X_TALER_BANK_PASSWORD": "Password"})
+        response = client.get(reverse("history", urlconf=urls),
+                              {"auth": "basic", "delta": "+1", "direction": 
"debit"},
+                              **{"HTTP_X_TALER_BANK_USERNAME": "User",
+                                 "HTTP_X_TALER_BANK_PASSWORD": "Password"})
         self.assertNotEqual(204, response.status_code)
         # Query about non-owned account
-        response = c.get(reverse("history", urlconf=urls), {"auth": "basic", 
"delta": "+1", "account_number": 2},
-                         **{"HTTP_X_TALER_BANK_USERNAME": "User", 
"HTTP_X_TALER_BANK_PASSWORD": "Password"})
+        response = client.get(reverse("history", urlconf=urls),
+                              {"auth": "basic", "delta": "+1", 
"account_number": 2},
+                              **{"HTTP_X_TALER_BANK_USERNAME": "User",
+                                 "HTTP_X_TALER_BANK_PASSWORD": "Password"})
         self.assertEqual(403, response.status_code)
         # Query about non-existent account
-        response = c.get(reverse("history", urlconf=urls), {"auth": "basic", 
"delta": "-1", "account_number": 9},
-                         **{"HTTP_X_TALER_BANK_USERNAME": "User", 
"HTTP_X_TALER_BANK_PASSWORD": "Password"})
+        response = client.get(reverse("history", urlconf=urls),
+                              {"auth": "basic", "delta": "-1", 
"account_number": 9},
+                              **{"HTTP_X_TALER_BANK_USERNAME": "User",
+                                 "HTTP_X_TALER_BANK_PASSWORD": "Password"})
         self.assertEqual(404, response.status_code)
 
 class DBAmountSubtraction(TestCase):
     def setUp(self):
-        a = BankAccount(user=User.objects.create_user(username='U'),
-            amount=Amount(settings.TALER_CURRENCY, 3))
-        a.save()
-    
+        user_bankaccount = 
BankAccount(user=User.objects.create_user(username='U'),
+                                       amount=Amount(settings.TALER_CURRENCY, 
3))
+        user_bankaccount.save()
+
     def test_subtraction(self):
-        a = BankAccount.objects.get(user=User.objects.get(username='U'))
-        a.amount.subtract(Amount(settings.TALER_CURRENCY, 2))
-        self.assertEqual(0, Amount.cmp(Amount(settings.TALER_CURRENCY, 1), 
a.amount))
+        user_bankaccount = 
BankAccount.objects.get(user=User.objects.get(username='U'))
+        user_bankaccount.amount.subtract(Amount(settings.TALER_CURRENCY, 2))
+        self.assertEqual(0, Amount.cmp(Amount(settings.TALER_CURRENCY, 1),
+                                       user_bankaccount.amount))
 
 
 class DBCustomColumnTestCase(TestCase):
 
-    def setUp(TestCase):
-        a = BankAccount(user=User.objects.create_user(username='U'))
-        a.save()
+    def setUp(self):
+        user_bankaccount = 
BankAccount(user=User.objects.create_user(username='U'))
+        user_bankaccount.save()
 
     def test_exists(self):
-        a = BankAccount.objects.get(user=User.objects.get(username='U'))
-        self.assertTrue(isinstance(a.amount, Amount))
+        user_bankaccount = 
BankAccount.objects.get(user=User.objects.get(username='U'))
+        self.assertTrue(isinstance(user_bankaccount.amount, Amount))
 
 # This tests whether a bank account goes debit and then goes >=0  again
 class DebitTestCase(TestCase):
 
     def setUp(self):
-        ua = BankAccount(user=User.objects.create_user(username='U'))
-        u0a = BankAccount(user=User.objects.create_user(username='U0'))
-        ua.save()
-        u0a.save()
+        user_bankaccount = 
BankAccount(user=User.objects.create_user(username='U'))
+        user_bankaccount0 = 
BankAccount(user=User.objects.create_user(username='U0'))
+        user_bankaccount.save()
+        user_bankaccount0.save()
 
     def test_green(self):
-        u = User.objects.get(username='U')
-        ub = BankAccount.objects.get(user=u)
-        self.assertEqual(False, ub.debit)
+        user_bankaccount = 
BankAccount.objects.get(user=User.objects.get(username='U'))
+        self.assertEqual(False, user_bankaccount.debit)
 
     def test_red(self):
-        ub = BankAccount.objects.get(user=User.objects.get(username='U'))
-        ub0 = BankAccount.objects.get(user=User.objects.get(username='U0'))
+        user_bankaccount = 
BankAccount.objects.get(user=User.objects.get(username='U'))
+        user_bankaccount0 = 
BankAccount.objects.get(user=User.objects.get(username='U0'))
 
         wire_transfer(Amount(settings.TALER_CURRENCY, 10, 0),
-                      ub0,
-                      ub,
+                      user_bankaccount0,
+                      user_bankaccount,
                       "Go green")
         tmp = Amount(settings.TALER_CURRENCY, 10)
-        self.assertEqual(0, Amount.cmp(ub.amount, tmp))
-        self.assertEqual(0, Amount.cmp(ub0.amount, tmp))
-        self.assertFalse(ub.debit)
+        self.assertEqual(0, Amount.cmp(user_bankaccount.amount, tmp))
+        self.assertEqual(0, Amount.cmp(user_bankaccount0.amount, tmp))
+        self.assertFalse(user_bankaccount.debit)
 
-        self.assertTrue(ub0.debit)
+        self.assertTrue(user_bankaccount0.debit)
 
         wire_transfer(Amount(settings.TALER_CURRENCY, 11),
-                      ub,
-                      ub0,
+                      user_bankaccount,
+                      user_bankaccount0,
                       "Go red")
 
         tmp.value = 1
-        self.assertTrue(ub.debit)
-        self.assertFalse(ub0.debit)
-        self.assertEqual(0, Amount.cmp(ub.amount, tmp))
-        self.assertEqual(0, Amount.cmp(ub0.amount, tmp))
+        self.assertTrue(user_bankaccount.debit)
+        self.assertFalse(user_bankaccount0.debit)
+        self.assertEqual(0, Amount.cmp(user_bankaccount.amount, tmp))
+        self.assertEqual(0, Amount.cmp(user_bankaccount0.amount, tmp))
 
 class ParseAmountTestCase(TestCase):
-     def test_parse_amount(self):
-         ret = Amount.parse("KUDOS:4.0")
-         self.assertJSONEqual('{"value": 4, "fraction": 0, "currency": 
"KUDOS"}', ret.dump())
-         ret = Amount.parse("KUDOS:4.3")
-         self.assertJSONEqual('{"value": 4, "fraction": 30000000, "currency": 
"KUDOS"}', ret.dump())
-         try:
-             Amount.parse("Buggy")
-         except BadFormatAmount:
-             return
-         # make sure the control doesn't get here
-         self.assertEqual(True, False)
+    def test_parse_amount(self):
+        ret = Amount.parse("KUDOS:4.0")
+        self.assertJSONEqual('{"value": 4, "fraction": 0, "currency": 
"KUDOS"}', ret.dump())
+        ret = Amount.parse("KUDOS:4.3")
+        self.assertJSONEqual('{"value": 4, "fraction": 30000000, "currency": 
"KUDOS"}', ret.dump())
+        try:
+            Amount.parse("Buggy")
+        except BadFormatAmount:
+            return
+        # make sure the control doesn't get here
+        self.assertEqual(True, False)
diff --git a/talerbank/app/tests_alt.py b/talerbank/app/tests_alt.py
index 4ab9b65..7d37586 100644
--- a/talerbank/app/tests_alt.py
+++ b/talerbank/app/tests_alt.py
@@ -13,20 +13,9 @@
 #  TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
 #
 #  @author Marcello Stanisci
-
-from django.test import TestCase, Client
-from django.core.urlresolvers import reverse
+from django.test import TestCase
 from django.conf import settings
-from django.contrib.auth.models import User
-from .models import BankAccount, BankTransaction
-from . import urls
 from .amount import Amount, BadFormatAmount
-from .views import wire_transfer
-import json
-
-import logging
-
-logger = logging.getLogger(__name__)
 
 class BadDatabaseStringTestCase(TestCase):
     def test_baddbstring(self):
diff --git a/talerbank/app/urls.py b/talerbank/app/urls.py
index 667366c..7578d81 100644
--- a/talerbank/app/urls.py
+++ b/talerbank/app/urls.py
@@ -31,7 +31,9 @@ urlpatterns = [
     url(r'^history$', views.history, name="history"),
     url(r'^withdraw$', views.withdraw_nojs, name="withdraw-nojs"),
     url(r'^public-accounts$', views.public_accounts, name="public-accounts"),
-    url(r'^public-accounts/(?P<name>[a-zA-Z0-9 ]+)$', views.public_accounts, 
name="public-accounts"),
+    url(r'^public-accounts/(?P<name>[a-zA-Z0-9 ]+)$',
+        views.public_accounts,
+        name="public-accounts"),
     url(r'^pin/question$', views.pin_tan_question, name="pin-question"),
     url(r'^pin/verify$', views.pin_tan_verify, name="pin-verify"),
     url(r'^javascript$', views.javascript_licensing)
diff --git a/talerbank/talerconfig.py b/talerbank/talerconfig.py
index b686240..f9157f0 100644
--- a/talerbank/talerconfig.py
+++ b/talerbank/talerconfig.py
@@ -191,6 +191,8 @@ class TalerConfig:
         """
         self.sections = SectionDict()
 
+    # defaults != config file: the first is the 'base'
+    # whereas the second overrides things from the first.
     @staticmethod
     def from_file(filename=None, load_defaults=True):
         cfg = TalerConfig()
@@ -199,7 +201,7 @@ class TalerConfig:
             if xdg:
                 filename = os.path.join(xdg, "taler.conf")
             else:
-                filename = os.path.expanduser("~/.config/taler.conf")
+                filename = os.path.expanduser("~/.config/taler.conf") # <- 
what if you aren't there!?
         if load_defaults:
             cfg.load_defaults()
         cfg.load_file(filename)

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



reply via email to

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