## # 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 # # @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()