<s> from __future__ import print_function , unicode_literals <EOL> import json <EOL> from liberapay . testing import Harness <EOL> class Tests ( Harness ) : <EOL> def test_anonymous ( self ) : <EOL> alice = self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> ) <EOL> bob = self . make_participant ( '<STR_LIT>' ) <EOL> alice . set_tip_to ( bob , '<STR_LIT>' ) <EOL> data = json . loads ( self . client . GET ( '<STR_LIT>' ) . body ) <EOL> assert data [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> assert '<STR_LIT>' not in data <EOL> data = json . loads ( self . client . GET ( '<STR_LIT>' ) . body ) <EOL> assert data [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> def test_anonymous_gets_null_giving_if_user_anonymous ( self ) : <EOL> alice = self . make_participant ( '<STR_LIT>' <EOL> , balance = <NUM_LIT:100> <EOL> , hide_giving = True <EOL> ) <EOL> bob = self . make_participant ( '<STR_LIT>' ) <EOL> alice . set_tip_to ( bob , '<STR_LIT>' ) <EOL> data = json . loads ( self . client . GET ( '<STR_LIT>' ) . body ) <EOL> assert data [ '<STR_LIT>' ] == None <EOL> def test_anonymous_gets_null_receiving_if_user_anonymous ( self ) : <EOL> alice = self . make_participant ( '<STR_LIT>' <EOL> , balance = <NUM_LIT:100> <EOL> , hide_receiving = True <EOL> ) <EOL> bob = self . make_participant ( '<STR_LIT>' ) <EOL> alice . set_tip_to ( bob , '<STR_LIT>' ) <EOL> data = json . loads ( self . client . GET ( '<STR_LIT>' ) . body ) <EOL> assert data [ '<STR_LIT>' ] == None <EOL> def test_anonymous_does_not_get_goal_if_user_regifts ( self ) : <EOL> self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> , goal = <NUM_LIT:0> ) <EOL> data = json . loads ( self . client . GET ( '<STR_LIT>' ) . body ) <EOL> assert '<STR_LIT>' not in data <EOL> def test_anonymous_gets_null_goal_if_user_has_no_goal ( self ) : <EOL> self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> ) <EOL> data = json . loads ( self . client . GET ( '<STR_LIT>' ) . body ) <EOL> assert data [ '<STR_LIT>' ] == None <EOL> def test_anonymous_gets_user_goal_if_set ( self ) : <EOL> self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> , goal = <NUM_LIT:1> ) <EOL> data = json . loads ( self . client . GET ( '<STR_LIT>' ) . body ) <EOL> assert data [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> def test_authenticated_user_gets_their_tip ( self ) : <EOL> alice = self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> ) <EOL> bob = self . make_participant ( '<STR_LIT>' ) <EOL> alice . set_tip_to ( bob , '<STR_LIT>' ) <EOL> raw = self . client . GET ( '<STR_LIT>' , auth_as = alice ) . body <EOL> data = json . loads ( raw ) <EOL> assert data [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> assert data [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> def test_authenticated_user_doesnt_get_other_peoples_tips ( self ) : <EOL> alice = self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> ) <EOL> bob = self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> ) <EOL> carl = self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> ) <EOL> dana = self . make_participant ( '<STR_LIT>' ) <EOL> alice . set_tip_to ( dana , '<STR_LIT>' ) <EOL> bob . set_tip_to ( dana , '<STR_LIT>' ) <EOL> carl . set_tip_to ( dana , '<STR_LIT>' ) <EOL> raw = self . client . GET ( '<STR_LIT>' , auth_as = alice ) . body <EOL> data = json . loads ( raw ) <EOL> assert data [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> assert data [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> def test_authenticated_user_gets_zero_if_they_dont_tip ( self ) : <EOL> alice = self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> ) <EOL> bob = self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> ) <EOL> carl = self . make_participant ( '<STR_LIT>' ) <EOL> bob . set_tip_to ( carl , '<STR_LIT>' ) <EOL> raw = self . client . GET ( '<STR_LIT>' , auth_as = alice ) . body <EOL> data = json . loads ( raw ) <EOL> assert data [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> assert data [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> def test_authenticated_user_gets_self_for_self ( self ) : <EOL> alice = self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> ) <EOL> bob = self . make_participant ( '<STR_LIT>' ) <EOL> alice . set_tip_to ( bob , '<STR_LIT>' ) <EOL> raw = self . client . GET ( '<STR_LIT>' , auth_as = bob ) . body <EOL> data = json . loads ( raw ) <EOL> assert data [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> assert data [ '<STR_LIT>' ] == '<STR_LIT>' <EOL> def test_access_control_allow_origin_header_is_asterisk ( self ) : <EOL> self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> ) <EOL> response = self . client . GET ( '<STR_LIT>' ) <EOL> assert response . headers [ '<STR_LIT>' ] == '<STR_LIT:*>' <EOL> def test_jsonp_works ( self ) : <EOL> alice = self . make_participant ( '<STR_LIT>' , balance = <NUM_LIT:100> ) <EOL> bob = self . make_participant ( '<STR_LIT>' ) <EOL> alice . set_tip_to ( bob , '<STR_LIT>' ) <EOL> raw = self . client . GET ( '<STR_LIT>' , auth_as = bob ) . body <EOL> assert raw == '''<STR_LIT>''' % dict ( user_id = bob . id , elsewhere_id = bob . get_accounts_elsewhere ( ) [ '<STR_LIT>' ] . id ) </s>
