-
-
Notifications
You must be signed in to change notification settings - Fork 217
/
test_public_json.py
57 lines (42 loc) · 2.33 KB
/
test_public_json.py
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
import json
from liberapay.testing import EUR, Harness
class Tests(Harness):
def test_anonymous(self):
alice = self.make_participant('alice')
alice_card = self.upsert_route(alice, 'stripe-card')
bob = self.make_participant('bob')
self.add_payment_account(bob, 'stripe')
alice.set_tip_to(bob, EUR('1.00'))
self.make_payin_and_transfer(alice_card, bob, EUR('10'))
data = json.loads(self.client.GET('/bob/public.json').text)
assert data['receiving'] == {"amount": "1.00", "currency": "EUR"}
data = json.loads(self.client.GET('/alice/public.json').text)
assert data['giving'] == {"amount": "1.00", "currency": "EUR"}
def test_anonymous_gets_null_giving_if_user_anonymous(self):
alice = self.make_participant('alice', balance=EUR(100), hide_giving=True)
bob = self.make_participant('bob')
alice.set_tip_to(bob, EUR('1.00'))
data = json.loads(self.client.GET('/alice/public.json').text)
assert data['giving'] == None
def test_anonymous_gets_null_receiving_if_user_anonymous(self):
alice = self.make_participant('alice', balance=EUR(100), hide_receiving=True)
bob = self.make_participant('bob')
alice.set_tip_to(bob, EUR('1.00'))
data = json.loads(self.client.GET('/alice/public.json').text)
assert data['receiving'] == None
def test_anonymous_does_not_get_goal_if_user_regifts(self):
self.make_participant('alice', balance=EUR(100), goal=EUR(0))
data = json.loads(self.client.GET('/alice/public.json').text)
assert 'goal' not in data
def test_anonymous_gets_null_goal_if_user_has_no_goal(self):
self.make_participant('alice', balance=EUR(100))
data = json.loads(self.client.GET('/alice/public.json').text)
assert data['goal'] == None
def test_anonymous_gets_user_goal_if_set(self):
self.make_participant('alice', balance=EUR(100), goal=EUR('1.00'))
data = json.loads(self.client.GET('/alice/public.json').text)
assert data['goal'] == {"amount": "1.00", "currency": "EUR"}
def test_access_control_allow_origin_header_is_asterisk(self):
self.make_participant('alice', balance=EUR(100))
response = self.client.GET('/alice/public.json')
assert response.headers[b'Access-Control-Allow-Origin'] == b'*'