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
|
#!/usr/bin/env python3
import unittest
from mock import patch, MagicMock
from talerbackoffice.backoffice import backoffice
from taler.util.talerconfig import TalerConfig
from bs4 import BeautifulSoup
TC = TalerConfig.from_env()
CURRENCY = TC["taler"]["currency"].value_string(required=True)
class BackofficeTestCase(unittest.TestCase):
def setUp(self):
backoffice.app.testing = True
self.app = backoffice.app.test_client()
# Check whether the homepage UI shows the instances
# in the drop-down menu. Instances are read from the
# environment.
def test_instances_are_shown(self):
response = self.app.get("/")
soup = BeautifulSoup(response.data, "html.parser")
self.assertEqual("MusicShop", soup.find("select").option.contents[0])
self.assertEqual(response.status_code, 200)
@patch("requests.get")
def test_track_order(self, mocked_get):
ret = MagicMock()
ret.status_code = 200
ret.json.return_value = {}
mocked_get.return_value = ret
response = self.app.get("/track/order?para1=1¶2=2")
mocked_get.assert_called_with(
"http://backend.example.com/track/transaction",
params=dict(para1='1', para2='2'),
headers={"Authorization": "ApiKey sandbox"}
)
# check data is returned verbatim from the backend
self.assertEqual(response.data, b'{}\n')
@patch("requests.get")
def test_track_transfer(self, mocked_get):
ret = MagicMock()
ret.status_code = 200
ret.json.return_value = {}
mocked_get.return_value = ret
response = self.app.get("/track/transfer?para1=1¶2=2")
mocked_get.assert_called_with(
"http://backend.example.com/track/transfer",
params=dict(para1='1', para2='2'),
headers={"Authorization": "ApiKey sandbox"}
)
# check data is returned verbatim from the backend
self.assertEqual(response.data, b'{}\n')
@patch("requests.get")
def test_history(self, mocked_get):
ret = MagicMock()
ret.status_code = 200
ret.json.return_value = {}
mocked_get.return_value = ret
response = self.app.get("/history?para1=1¶2=2")
mocked_get.assert_called_with(
"http://backend.example.com/history",
params=dict(para1='1', para2='2'),
headers={"Authorization": "ApiKey sandbox"}
)
self.assertEqual(response.data, b'{}\n')
def test_javascript_license_page(self):
response = self.app.get("/javascript")
soup = BeautifulSoup(response.data, "html.parser")
self.assertEqual(soup.body.table["id"], "jslicense-labels1")
if __name__ == "__main__":
unittest.main()
|