[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] [taler-merchant-frontends] branch master updated: (#5181)
From: |
gnunet |
Subject: |
[GNUnet-SVN] [taler-merchant-frontends] branch master updated: (#5181) |
Date: |
Thu, 23 Nov 2017 19:51:34 +0100 |
This is an automated email from the git hooks/post-receive script.
marcello pushed a commit to branch master
in repository merchant-frontends.
The following commit(s) were added to refs/heads/master by this push:
new 87716ca (#5181)
87716ca is described below
commit 87716ca730a530f6eba04a7881314b5778a88175
Author: Marcello Stanisci <address@hidden>
AuthorDate: Thu Nov 23 19:50:19 2017 +0100
(#5181)
---
Makefile.in | 6 +--
talerfrontends/helpers.py | 2 +-
talerfrontends/tests.py | 120 +++++++++++++++++++++++++++++++++++-----------
3 files changed, 95 insertions(+), 33 deletions(-)
diff --git a/Makefile.in b/Makefile.in
index 33a902c..00aabd8 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -52,6 +52,6 @@ install: $(templates) install-data
# run testcases
.PHONY: check
check:
- @export TALER_CONFIG_FILE=./talerfrontends/tests.conf; \
- export address@hidden@/lib/python3.5/site-packages; \
- python3 ./talerfrontends/tests.py
+ @export address@hidden@/talerfrontends/tests.conf; \
+ export address@hidden@/talerfrontends/; \
+ python3 @abs_srcdir@/talerfrontends/tests.py
diff --git a/talerfrontends/helpers.py b/talerfrontends/helpers.py
index c19890d..257192d 100644
--- a/talerfrontends/helpers.py
+++ b/talerfrontends/helpers.py
@@ -85,7 +85,7 @@ def make_url(page, *query_params):
def expect_parameter(name, alt=None):
value = request.args.get(name, None)
if value is None and alt is None:
- logger.error("Missing parameter '%s'." % name)
+ logger.error("Missing parameter '%s' from '%s'." % (name,
request.args))
raise MissingParameterException(name)
return value if value else alt
diff --git a/talerfrontends/tests.py b/talerfrontends/tests.py
index 5068694..19c94d8 100755
--- a/talerfrontends/tests.py
+++ b/talerfrontends/tests.py
@@ -6,52 +6,114 @@ a wallet (resume Python wallet?)!
"""
import unittest
+import logging
+from mock import patch, MagicMock
from donations import donations
from blog import blog
-import logging
+from talerconfig import TalerConfig
+from datetime import datetime
logger = logging.getLogger(__name__)
dapp = donations.app
-bapp = donations.app
+bapp = blog.app
+tc = TalerConfig.from_env()
+CURRENCY = tc["taler"]["currency"].value_string(required=True)
class DonationsTestCase(unittest.TestCase):
def setUp(self):
dapp.testing = True
self.app = dapp.test_client()
- def test_root(self):
- response = self.app.get("/")
- assert 200 == response.status_code
-
- def test_proposal_creation(self):
- qs = "/generate-contract?donation_receiver=Tor&donation_amount=1.0"
- bad_qs = "/generate-contract?buggy=qs"
- bad_receiver =
"/generate-contract?donation_receiver=Torrone&donation_amount=2"
- response = self.app.get(qs)
- assert 200 == response.status_code
- logger.info("Testing against bad query string")
- response = self.app.get(bad_qs)
- assert 400 == response.status_code
- logger.info("Testing against bad donation receiver")
- response = self.app.get(bad_receiver)
- assert 404 == response.status_code
-
- def test_donate(self):
- qs =
"/donate?donation_receiver=Tor&donation_amount=1&payment_system=taler"
- response = self.app.get(qs)
- print(response.status_code)
- assert 402 == response.status_code
+ @patch("requests.post")
+ @patch("random.randint")
+ @patch("datetime.datetime")
+ def test_proposal_creation(self, mocked_datetime,
+ mocked_random, mocked_post):
+ qs =
"/generate-contract?nonce=44&donation_receiver=Tor&donation_amount=1.0"
+ mocked_datetime.today.return_value = datetime.today()
+ mocked_random.return_value = 333
+ order_id = "donation-%s-%X-%s" % \
+ ("Tor", mocked_random(),
mocked_datetime.today().strftime("%H_%M_%S"))
+ ret_post = MagicMock()
+ ret_post.status_code = 200
+ ret_post.json.return_value = {}
+ mocked_post.return_value = ret_post
+ self.app.get(qs)
+ mocked_post.assert_called_with(
+ "http://backend.test.taler.net/proposal", json={
+ "order": {
+ "summary": "Donation!",
+ "order_id": order_id,
+ "nonce": "44",
+ "amount": {
+ "value": 1,
+ "fraction": 0,
+ "currency": CURRENCY},
+ "max_fee": {
+ "value": 1,
+ "fraction": 0,
+ "currency": CURRENCY},
+ "order_id": order_id,
+ "products": [{
+ "description": "Donation to Tor",
+ "quantity": 1,
+ "product_id": 0,
+ "price": {
+ "value": 1,
+ "fraction": 0,
+ "currency": CURRENCY}}],
+ "fulfillment_url":
+ "http://localhost/fulfillment?order_id=%s" % order_id,
+ "pay_url": "http://localhost/pay",
+ "merchant": {
+ "instance": "Tor",
+ "address": "nowhere",
+ "name": "Kudos Inc.",
+ "jurisdiction": "none"}
+ }})
class BlogTestCase(unittest.TestCase):
def setUp(self):
bapp.testing = True
self.app = bapp.test_client()
- def test_root(self):
- response = self.app.get("/")
- assert 200 == response.status_code
-
-
+ @patch("requests.post")
+ def test_proposal_creation(self, mocked_post):
+ ret_post = MagicMock()
+ ret_post.status_code = 200
+ ret_post.json.return_value = {}
+ mocked_post.return_value = ret_post
+ self.app.get("/generate-contract?nonce=55&article_name=Check_Me")
+ mocked_post.assert_called_with(
+ "http://backend.test.taler.net/proposal",
+ json={
+ "order": {
+ "summary": "Check Me",
+ "nonce": "55",
+ "amount": {
+ "value": 1,
+ "fraction": 0,
+ "currency": CURRENCY},
+ "max_fee": {
+ "value": 1,
+ "fraction": 0,
+ "currency": CURRENCY},
+ "products": [{
+ "description": "Essay: Check Me",
+ "quantity": 1,
+ "product_id": 0,
+ "price": {
+ "value": 1,
+ "fraction": 0,
+ "currency": CURRENCY}}],
+ "fulfillment_url": "http://localhost/essay/Check_Me",
+ "pay_url": "http://localhost/pay",
+ "merchant": {
+ "instance":
tc["blog"]["instance"].value_string(required=True),
+ "address": "nowhere",
+ "name": "Kudos Inc.",
+ "jurisdiction": "none"},
+ "extra": {"article_name": "Check_Me"}}})
if "__main__" == __name__:
unittest.main()
--
To stop receiving notification emails like this one, please contact
address@hidden
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] [taler-merchant-frontends] branch master updated: (#5181),
gnunet <=