def test_post_bad_platform(self):
        client = TestClient()

        now = datetime.datetime.now(pytz.utc)
        self.make_participant("test_tippee1", claimed_time=now)
        self.make_participant("test_tipper", claimed_time=now)

        api_key = json.loads(
            client.get('/test_tipper/api-key.json',
                       'test_tipper').body)['api_key']

        response = client.post('/test_tipper/tips.json',
                               json.dumps([{
                                   'username': '******',
                                   'platform': 'badname',
                                   'amount': '1.00'
                               }]),
                               user='******',
                               content_type='application/json',
                               HTTP_AUTHORIZATION='Basic ' +
                               base64.b64encode(api_key + ':'))

        assert response.code == 200

        resp = json.loads(response.body)

        for tip in resp:
            assert 'error' in tip
    def test_sandwiched_tipless_payday_comes_through(self):
        alice, bob = self.make_participants_and_tips()
        self.run_payday()  # zeroth, ignored
        self.run_payday()  # first

        # Oops! Sorry, Carl. :-(
        alice.set_tip_to('carl', '0.00')
        bob.set_tip_to('carl', '0.00')
        self.run_payday()  # second

        # Bouncing back ...
        alice.set_tip_to('carl', '5.00')
        self.run_payday()  # third

        expected = [
            {
                "date": datetime.date.today().strftime('%Y-%m-%d'),
                "npatrons": 1  # most recent first
                ,
                "receipts": 5.00
            },
            {
                "date": datetime.date.today().strftime('%Y-%m-%d'),
                "npatrons": 0,
                "receipts": 0.00
            },
            {
                "date": datetime.date.today().strftime('%Y-%m-%d'),
                "npatrons": 2,
                "receipts": 3.00
            }
        ]
        actual = json.loads(TestClient().get('/carl/charts.json').body)

        assert actual == expected
    def test_get_response_with_tips(self):
        client = TestClient()

        now = datetime.datetime.now(pytz.utc)
        self.make_participant("test_tippee1", claimed_time=now)
        self.make_participant("test_tipper", claimed_time=now)

        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        response1 = client.post('/test_tippee1/tip.json', {
            'amount': '1.00',
            'csrf_token': csrf_token
        },
                                user='******')

        response = client.get('/test_tipper/tips.json', 'test_tipper')

        assert response1.code == 200
        assert json.loads(response1.body)['amount'] == '1.00'

        data = json.loads(response.body)[0]

        assert response.code == 200
        assert data['username'] == 'test_tippee1'
        assert data['amount'] == '1.00'
Beispiel #4
0
    def test_get_amount_and_total_back_from_api(self):
        "Test that we get correct amounts and totals back on POSTs to tip.json"
        client = TestClient()

        # First, create some test data
        # We need accounts
        now = datetime.datetime.now(pytz.utc)
        self.make_participant("test_tippee1", claimed_time=now)
        self.make_participant("test_tippee2", claimed_time=now)
        self.make_participant("test_tipper")

        # We need to get ourselves a token!
        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        # Then, add a $1.50 and $3.00 tip
        response1 = client.post("/test_tippee1/tip.json", {
            'amount': "1.00",
            'csrf_token': csrf_token
        },
                                user='******')

        response2 = client.post("/test_tippee2/tip.json", {
            'amount': "3.00",
            'csrf_token': csrf_token
        },
                                user='******')

        # Confirm we get back the right amounts.
        first_data = json.loads(response1.body)
        second_data = json.loads(response2.body)
        assert_equal(first_data['amount'], "1.00")
        assert_equal(first_data['total_giving'], "1.00")
        assert_equal(second_data['amount'], "3.00")
        assert_equal(second_data['total_giving'], "4.00")
Beispiel #5
0
    def test_anonymous_gets_user_goal_if_set(self):
        alice = self.make_participant('alice', last_bill_result='')

        alice.goal = Decimal('1.00')

        data = json.loads(TestClient().get('/alice/public.json').body)

        assert_equal(data['goal'], '1.00')
Beispiel #6
0
    def test_anonymous_does_not_get_goal_if_user_regifts(self):
        alice = self.make_participant('alice', last_bill_result='')

        alice.goal = 0

        data = json.loads(TestClient().get('/alice/public.json').body)

        assert_equal(data.has_key('goal'), False)
Beispiel #7
0
    def setUp(self):
        self.client = TestClient()
        Harness.setUp(self)

        self._blech = (os.environ['CANONICAL_SCHEME'],
                       os.environ['CANONICAL_HOST'])
        os.environ['CANONICAL_SCHEME'] = 'https'
        os.environ['CANONICAL_HOST'] = 'www.gittip.com'
        wireup.canonical()
Beispiel #8
0
    def test_anonymous_does_not_get_my_tip(self):
        alice = self.make_participant('alice', last_bill_result='')
        self.make_participant('bob')

        alice.set_tip_to('bob', '1.00')

        data = json.loads(TestClient().get('/bob/public.json').body)

        assert_equal(data.has_key('my_tip'), False)
Beispiel #9
0
    def test_anonymous_gets_giving(self):
        alice = self.make_participant('alice', last_bill_result='')
        self.make_participant('bob')

        alice.set_tip_to('bob', '1.00')

        data = json.loads(TestClient().get('/alice/public.json').body)

        assert_equal(data['giving'], '1.00')
    def test_anonymous_gets_null_giving_if_user_anonymous(self):
        alice = self.make_participant( 'alice'
                                     , last_bill_result=''
                                     , anonymous=True
                                      )
        self.make_participant('bob')
        alice.set_tip_to('bob', '1.00')
        data = json.loads(TestClient().get('/alice/public.json').body)

        assert data['giving'] == None
    def test_get_response(self):
        client = TestClient()

        now = datetime.datetime.now(pytz.utc)
        self.make_participant("test_tipper", claimed_time=now)

        response = client.get('/test_tipper/tips.json', 'test_tipper')

        assert response.code == 200
        assert len(json.loads(response.body)) == 0  # empty array
    def test_never_received_gives_empty_array(self):
        alice, bob = self.make_participants_and_tips()
        self.run_payday()  # zeroeth, ignored
        self.run_payday()  # first
        self.run_payday()  # second
        self.run_payday()  # third

        expected = []
        actual = json.loads(TestClient().get('/alice/charts.json').body)

        assert actual == expected
Beispiel #13
0
    def test_authenticated_user_gets_their_tip(self):
        alice = self.make_participant('alice', last_bill_result='')
        self.make_participant('bob')

        alice.set_tip_to('bob', '1.00')

        raw = TestClient().get('/bob/public.json', user='******').body

        data = json.loads(raw)

        assert_equal(data['receiving'], '1.00')
        assert_equal(data['my_tip'], '1.00')
Beispiel #14
0
    def test_github_user_info_status_handling(self, requests):
        client = TestClient()
        # Check that different possible github statuses are handled correctly
        for (github_status, github_content), expected_gittip_response in [
            ((200, DUMMY_GITHUB_JSON), 200), ((404, ""), 404),
            ((500, ""), 502), ((777, ""), 502)
        ]:

            requests.get().status_code = github_status
            requests.get().text = github_content
            response = client.get('/on/github/not-in-the-db/')
            assert response.code == expected_gittip_response
    def test_authenticated_user_gets_self_for_self(self):
        alice = self.make_participant('alice', last_bill_result='')
        self.make_participant('bob')

        alice.set_tip_to('bob', '3.00')

        raw = TestClient().get('/bob/public.json', user='******').body

        data = json.loads(raw)

        assert data['receiving'] == '3.00'
        assert data['my_tip'] == 'self'
Beispiel #16
0
    def change_username(self, new_username, user='******'):
        self.make_participant('alice')

        client = TestClient()
        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        response = client.post("/alice/username.json", {
            'username': new_username,
            'csrf_token': csrf_token
        },
                               user=user)
        return response
Beispiel #17
0
    def change_bitcoin_address(self, address, user='******'):
        self.make_participant('alice')

        client = TestClient()
        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        response = client.post("/alice/bitcoin.json", {
            'bitcoin_address': address,
            'csrf_token': csrf_token
        },
                               user=user)
        return response
Beispiel #18
0
    def test_authenticated_user_gets_zero_if_they_dont_tip(self):
        self.make_participant('alice', last_bill_result='')
        bob = self.make_participant('bob', last_bill_result='')
        self.make_participant('carl')

        bob.set_tip_to('carl', '3.00')

        raw = TestClient().get('/carl/public.json', user='******').body

        data = json.loads(raw)

        assert_equal(data['receiving'], '3.00')
        assert_equal(data['my_tip'], '0.00')
    def test_first_payday_comes_through(self):
        alice, bob = self.make_participants_and_tips()
        self.run_payday()  # zeroeth, ignored
        self.run_payday()  # first

        expected = [{
            "date": datetime.date.today().strftime('%Y-%m-%d'),
            "npatrons": 2,
            "receipts": 3.00
        }]
        actual = json.loads(TestClient().get('/carl/charts.json').body)

        assert actual == expected
Beispiel #20
0
    def change_statement(self, statement, number='singular', user='******'):
        self.make_participant('alice')

        client = TestClient()
        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        response = client.post("/alice/statement.json", {
            'statement': statement,
            'number': number,
            'csrf_token': csrf_token
        },
                               user=user)
        return response
    def also_prune_variant(self, also_prune, tippees=1):
        client = TestClient()

        now = datetime.datetime.now(pytz.utc)
        self.make_participant("test_tippee1", claimed_time=now)
        self.make_participant("test_tippee2", claimed_time=now)
        self.make_participant("test_tipper", claimed_time=now)

        api_key = json.loads(
            client.get('/test_tipper/api-key.json',
                       'test_tipper').body)['api_key']

        data = [{
            'username': '******',
            'platform': 'gittip',
            'amount': '1.00'
        }, {
            'username': '******',
            'platform': 'gittip',
            'amount': '2.00'
        }]

        response = client.post('/test_tipper/tips.json',
                               json.dumps(data),
                               user='******',
                               content_type='application/json',
                               HTTP_AUTHORIZATION='Basic ' +
                               base64.b64encode(api_key + ':'))

        assert response.code == 200
        assert len(json.loads(response.body)) == 2

        response = client.post(
            '/test_tipper/tips.json?also_prune=' + also_prune,
            json.dumps([{
                'username': '******',
                'platform': 'gittip',
                'amount': '1.00'
            }]),
            user='******',
            content_type='application/json',
            HTTP_AUTHORIZATION='Basic ' + base64.b64encode(api_key + ':'))

        assert response.code == 200

        response = client.get('/test_tipper/tips.json', 'test_tipper')
        assert response.code == 200
        assert len(json.loads(response.body)) == tippees
Beispiel #22
0
    def test_authenticated_user_doesnt_get_other_peoples_tips(self):
        alice = self.make_participant('alice', last_bill_result='')
        bob = self.make_participant('bob', last_bill_result='')
        carl = self.make_participant('carl', last_bill_result='')
        self.make_participant('dana')

        alice.set_tip_to('dana', '1.00')
        bob.set_tip_to('dana', '3.00')
        carl.set_tip_to('dana', '12.00')

        raw = TestClient().get('/dana/public.json', user='******').body

        data = json.loads(raw)

        assert_equal(data['receiving'], '16.00')
        assert_equal(data['my_tip'], '1.00')
    def hit_anonymous(self, method='GET', expected_code=200):
        user, ignored = TwitterAccount('alice', {}).opt_in('alice')

        client = TestClient()
        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        if method == 'GET':
            response = client.get("/alice/anonymous.json", user='******')
        else:
            assert method == 'POST'
            response = client.post("/alice/anonymous.json",
                                   {'csrf_token': csrf_token},
                                   user='******')
        if response.code != expected_code:
            print(response.body)
        return response
Beispiel #24
0
    def change_goal(self, goal, goal_custom="", username="******"):
        if isinstance(username, Participant):
            username = username.username
        elif username == 'alice':
            self.make_alice()

        client = TestClient()
        response = client.get('/')
        csrf_token = response.request.context['csrf_token']

        response = client.post("/alice/goal.json", {
            'goal': goal,
            'goal_custom': goal_custom,
            'csrf_token': csrf_token
        },
                               user=username)
        return response
    def test_out_of_band_transfer_gets_included_with_prior_payday(self):
        alice, bob = self.make_participants_and_tips()
        self.run_payday()  # zeroth, ignored
        self.run_payday()  # first
        self.run_payday()  # second

        # Do an out-of-band transfer.
        self.db.run(
            "UPDATE participants SET balance=balance - 4 WHERE username='******'"
        )
        self.db.run(
            "UPDATE participants SET balance=balance + 4 WHERE username='******'"
        )
        self.db.run(
            "INSERT INTO transfers (tipper, tippee, amount) VALUES ('alice', 'carl', 4)"
        )

        self.run_payday()  # third

        expected = [
            {
                "date": datetime.date.today().strftime('%Y-%m-%d'),
                "npatrons": 2  # most recent first
                ,
                "receipts": 3.00
            },
            {
                "date": datetime.date.today().strftime('%Y-%m-%d'),
                "npatrons":
                3  # Since this is rare, don't worry that we double-count alice.
                ,
                "receipts": 7.00
            },
            {
                "date": datetime.date.today().strftime('%Y-%m-%d'),
                "npatrons": 2,
                "receipts": 3.00
            }
        ]
        actual = json.loads(TestClient().get('/carl/charts.json').body)

        assert actual == expected
Beispiel #26
0
    def test_set_tip_out_of_range(self):
        client = TestClient()
        now = datetime.datetime.now(pytz.utc)
        self.make_participant("alice", claimed_time=now)
        self.make_participant("bob", claimed_time=now)

        response = client.get('/')
        csrf_token = response.request.context['csrf_token']
        response = client.post("/alice/tip.json", {
            'amount': "110.00",
            'csrf_token': csrf_token
        },
                               user='******')
        assert "bad amount" in response.body
        assert response.code == 400

        response = client.post("/alice/tip.json", {
            'amount': "-1.00",
            'csrf_token': csrf_token
        },
                               user='******')
        assert "bad amount" in response.body
        assert response.code == 400
Beispiel #27
0
 def get_stats_page(self):
     return TestClient().get('/about/stats.html').body
Beispiel #28
0
 def test_redirect_redirects(self):
     self.make_participant('alice')
     actual = TestClient().get('/on/bountysource/redirect', user='******').code
     assert actual == 302
Beispiel #29
0
    def test_anonymous_gets_null_goal_if_user_has_no_goal(self):
        alice = self.make_participant('alice', last_bill_result='')

        data = json.loads(TestClient().get('/alice/public.json').body)

        assert_equal(data['goal'], None)
Beispiel #30
0
 def setUp(self):
     super(Harness, self).setUp()
     self.client = TestClient()