summaryrefslogtreecommitdiff
path: root/talerblog/tests.py
blob: 36d27c5745ad2666ab23b8b298515811cb57b222 (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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/env python3

import unittest
from mock import patch, MagicMock
from talerblog.blog import blog
from talerblog.talerconfig import TalerConfig

tc = TalerConfig.from_env()
CURRENCY = tc["taler"]["currency"].value_string(required=True)

class BlogTestCase(unittest.TestCase):
    def setUp(self):
        blog.app.testing = True
        self.app = blog.app.test_client()

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