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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
##
# This file is part of GNU TALER.
# Copyright (C) 2014-2017 INRIA
#
# TALER is free software; you can redistribute it and/or modify it under the
# terms of the GNU Lesser General Public License as published by the Free Software
# Foundation; either version 2.1, 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 Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License along with
# GNU TALER; see the file COPYING. If not, see <http://www.gnu.org/licenses/>
#
# @author Marcello Stanisci
# @brief Test cases for the blog.
#!/usr/bin/env python3
import unittest
import logging
from mock import patch, MagicMock
from .blog import blog
from taler.util.talerconfig import TalerConfig
TC = TalerConfig.from_env()
CURRENCY = TC["taler"]["currency"].value_string(required=True)
LOGGER = logging.getLogger(__name__)
##
# Main class that gathers all the tests.
class BlogTestCase(unittest.TestCase):
def setUp(self):
blog.app.testing = True
self.app = blog.app.test_client()
self.instance = TC["blog"]["instance"].value_string(required=True)
##
# Test the refund logic.
#
# @param self the object itself.
# @param mocked_session mock object pretending to be the flask session.
# @param mocked_post mock function pretending to be 'requests.post'
# @param mocked_get mock function pretending to be 'requests.get'
@patch("requests.get")
@patch("requests.post")
@patch("flask.session")
@unittest.skip("API changed")
def test_refund(self, mocked_session, mocked_post, mocked_get):
# Test GET
ret_get = MagicMock()
ret_get.status_code = 200
ret_get.json.return_value = {"error": "mocckky error"}
mocked_get.return_value = ret_get
response = self.app.get("/refund?order_id=99")
mocked_get.assert_called_with(
"http://backend.test.taler.net/refund",
params={
"order_id": "99",
"instance": self.instance
}
)
# Test POST
mocked_session.get.return_value = {"mocckky": 99}
ret_post = MagicMock()
ret_post.status_code = 200
mocked_post.return_value = ret_post
response = self.app.post("/refund", data={"article_name": "mocckky"})
mocked_post.assert_called_with(
"http://backend.test.taler.net/refund",
json={
"order_id": 99,
"refund": {
"value": 0,
"fraction": 50000000,
"currency": CURRENCY
},
"reason": "Demo reimbursement",
"instance": self.instance
}
)
if __name__ == "__main__":
unittest.main()
|