gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] [libeufin] branch master updated: convenient mocks


From: gnunet
Subject: [GNUnet-SVN] [libeufin] branch master updated: convenient mocks
Date: Wed, 02 Oct 2019 15:28:10 +0200

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

marcello pushed a commit to branch master
in repository libeufin.

The following commit(s) were added to refs/heads/master by this push:
     new 42a775d  convenient mocks
42a775d is described below

commit 42a775df83d45a48589c779819c3a252f9f37e44
Author: Marcello Stanisci <address@hidden>
AuthorDate: Wed Oct 2 15:28:02 2019 +0200

    convenient mocks
---
 src/main/python/libeufin-cli | 41 +++++++++++++++++++++++++++++++++++------
 1 file changed, 35 insertions(+), 6 deletions(-)

diff --git a/src/main/python/libeufin-cli b/src/main/python/libeufin-cli
index 721fd63..512ae4d 100755
--- a/src/main/python/libeufin-cli
+++ b/src/main/python/libeufin-cli
@@ -7,6 +7,7 @@ from datetime import datetime
 from requests import post, get
 from Crypto.PublicKey import RSA 
 from urllib.parse import urljoin
+from mock import MagicMock, patch
 
 CUSTOMERS_PATH = "/tmp/libeufindata/customers"
 RECIPIENT_BANK = "LibEuBank"
@@ -76,12 +77,34 @@ def customer_info(obj):
     "--customer-id", required=True,
     help="id of the customer at the bank (used to pick keyset on disk)"
 )
+@click.option(
+    "--mock-info",
+    is_flag=True,
+    help="Mocks customer details instead of requesting ebics-info")
 @click.pass_obj
-def keyletter(obj, customer_id):
+def keyletter(obj, customer_id, mock_info):
 
     # Get userId.
-    url = urljoin(obj["base_url"], "/admin/customers/{}".format(customer_id))
-    resp = get(url)
+    url = urljoin(
+        obj["base_url"], "/admin/customers/{}".format(customer_id)
+    )
+    
+    resp = MagicMock()
+    resp.status_code = 200
+    resp.json.return_value = dict(
+        name="Mock Name",
+        ebicsInfo=dict(userId=1)
+    )
+
+    if mock_info:
+        print("Mocking ebics-info")
+    else:
+        try:
+            resp = get(url)
+        except Exception:
+            print("Could not connect to the bank, aborting")
+            return
+
     assert(resp.status_code == 200)
     user_id = resp.json().get("ebicsInfo", {}).get("userId")
     name = resp.json().get("name")
@@ -109,8 +132,10 @@ def keyletter(obj, customer_id):
         )
 
     except FileNotFoundError:
-        print("Could not find all the keys")
-        assert(False)
+        print("Could not find all the keys; mocking them all now")
+        eskey = RSA.generate(RSA_LENGTH)
+        enckey = RSA.generate(RSA_LENGTH)
+        iakey = RSA.generate(RSA_LENGTH)
 
     es_exponent = format(eskey.e, "x")
     es_modulus = format(eskey.n, "x")
@@ -161,7 +186,11 @@ def keyletter(obj, customer_id):
         )
     )
 
-    resp = post(url, json=body)
+    try:
+        resp = post(url, json=body)
+    except Exception:
+        print("Could not reach the bank, aborting now")
+        return
 
     if resp.status_code != 200:
         print("Bank did not accept this letter.")

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



reply via email to

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