summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.in5
-rw-r--r--talersurvey/tests.conf6
-rw-r--r--talersurvey/tests.py37
3 files changed, 45 insertions, 3 deletions
diff --git a/Makefile.in b/Makefile.in
index eb34733..f0028d2 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -48,6 +48,5 @@ install: $(templates) install-data
# run testcases
.PHONY: check
check:
- @export TALER_CONFIG_FILE=./talersurvey/tests.conf; \
- export PYTHONPATH=@prefix@/lib/python3.5/site-packages; \
- python3 ./talersurvey/tests.py
+ @export TALER_CONFIG_FILE=@abs_srcdir@/talersurvey/tests.conf; \
+ python3 talersurvey/tests.py
diff --git a/talersurvey/tests.conf b/talersurvey/tests.conf
new file mode 100644
index 0000000..8c82598
--- /dev/null
+++ b/talersurvey/tests.conf
@@ -0,0 +1,6 @@
+[taler]
+currency = TESTKUDOS
+
+[frontends]
+BACKEND = http://backend.test.taler.net/
+FRACTION = 100000000
diff --git a/talersurvey/tests.py b/talersurvey/tests.py
new file mode 100644
index 0000000..2ad119a
--- /dev/null
+++ b/talersurvey/tests.py
@@ -0,0 +1,37 @@
+#!/usr/bin/env python3
+
+import unittest
+from talersurvey.survey import survey
+from mock import patch, MagicMock
+from talersurvey.talerconfig import TalerConfig
+
+TC = TalerConfig.from_env()
+CURRENCY = TC["taler"]["currency"].value_string(required=True)
+
+class SurveyTestCase(unittest.TestCase):
+ def setUp(self):
+ survey.app.testing = True
+ self.app = survey.app.test_client()
+
+ @patch("requests.post")
+ def test_authorize(self, mocked_post):
+ ret_post = MagicMock()
+ ret_post.status_code = 200
+ ret_post.json.return_value = {
+ "tip_id": "Jeppo02",
+ "exchange_uri": "http://exchange.example.com/",
+ "expiration": "/Date(2018)/"}
+ mocked_post.return_value = ret_post
+ # Actual preference's ignored.
+ self.app.post("/")
+ mocked_post.assert_called_with(
+ "http://backend.test.taler.net/tip-authorize", json={
+ "amount": {
+ "value": 1,
+ "fraction": 0,
+ "currency": CURRENCY},
+ "instance": "default",
+ "justification": "Payment methods survey"})
+
+if __name__ == "__main__":
+ unittest.main()