summaryrefslogtreecommitdiff
path: root/talersurvey/tests.py
blob: f244ae7072f7c5eb61b364ed26192a050a7170b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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()