Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
Add testing.tip_graph convenience (#406)
Browse files Browse the repository at this point in the history
  • Loading branch information
chadwhitacre committed Dec 7, 2012
1 parent b46b705 commit b21e3a5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 4 additions & 0 deletions gittip/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,10 @@ def setup_tips(*recs):
return ["participants"] + participants + ["tips"] + tips


def tip_graph(*a, **kw):
return load(*setup_tips(*a, **kw))


# Helpers for testing simplates.
# ==============================

Expand Down
6 changes: 3 additions & 3 deletions tests/test_pages.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from gittip.testing import serve_request, load, setup_tips
from gittip.testing import serve_request, tip_graph


def test_homepage():
Expand All @@ -7,13 +7,13 @@ def test_homepage():
assert expected in actual, actual

def test_profile():
with load(*setup_tips(("cheese", "puffs", 0))):
with tip_graph(("cheese", "puffs", 0)):
expected = "I’m grateful for tips"
actual = serve_request('/cheese/').body
assert expected in actual, actual

def test_widget():
with load(*setup_tips(("cheese", "puffs", 0))):
with tip_graph(("cheese", "puffs", 0)):
expected = "javascript: window.open"
actual = serve_request('/cheese/widget.html').body
assert expected in actual, actual
Expand Down
28 changes: 12 additions & 16 deletions tests/test_stats.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
from datetime import datetime
from decimal import Decimal

import gittip
from gittip import testing, wireup
from gittip import wireup
from gittip.testing import load, load_simplate, serve_request, tip_graph
from gittip.billing.payday import Payday
from gittip.participant import Participant
from mock import patch


# commaize

simplate = testing.load_simplate('/about/stats.html')
simplate = load_simplate('/about/stats.html')
commaize = simplate.pages[0]['commaize']

def test_commaize_commaizes():
Expand All @@ -28,16 +28,12 @@ def check_chart_of_receiving(participant_id):
return Participant(participant_id).get_chart_of_receiving()


def setup(*a):
return testing.load(*testing.setup_tips(*a))


def test_get_chart_of_receiving_handles_a_tip():
tip = ("foo", "bar", "3.00", True)
expected = ( [[Decimal('3.00'), 1, Decimal('3.00'), 1.0, Decimal('1')]]
, 1.0, Decimal('3.00')
)
with setup(tip):
with tip_graph(tip):
actual = check_chart_of_receiving(u'bar')
assert actual == expected, actual

Expand All @@ -46,13 +42,13 @@ def test_get_chart_of_receiving_handles_a_non_standard_amount():
expected = ( [[-1, 1, Decimal('5.37'), 1.0, Decimal('1')]]
, 1.0, Decimal('5.37')
)
with setup(tip):
with tip_graph(tip):
actual = check_chart_of_receiving(u'bar')
assert actual == expected, actual

def test_get_chart_of_receiving_handles_no_tips():
expected = ([], 0.0, Decimal('0.00'))
with setup():
with tip_graph():
actual = check_chart_of_receiving(u'foo')
assert actual == expected, actual

Expand All @@ -65,7 +61,7 @@ def test_get_chart_of_receiving_handles_multiple_tips():
]
, 2.0, Decimal('4.00')
)
with setup(*tips):
with tip_graph(*tips):
actual = check_chart_of_receiving(u'bar')
assert actual == expected, actual

Expand All @@ -76,7 +72,7 @@ def test_get_chart_of_receiving_ignores_bad_cc():
expected = ( [[Decimal('1.00'), 1L, Decimal('1.00'), 1, Decimal('1')]]
, 1.0, Decimal('1.00')
)
with setup(*tips):
with tip_graph(*tips):
actual = check_chart_of_receiving(u'bar')
assert actual == expected, actual

Expand All @@ -87,15 +83,15 @@ def test_get_chart_of_receiving_ignores_missing_cc():
expected = ( [[Decimal('1.00'), 1L, Decimal('1.00'), 1, Decimal('1')]]
, 1.0, Decimal('1.00')
)
with setup(*tips):
with tip_graph(*tips):
actual = check_chart_of_receiving(u'bar')
assert actual == expected, actual


# rendering

def get_stats_page():
response = testing.serve_request('/about/stats.html')
response = serve_request('/about/stats.html')
return response.body


Expand All @@ -106,7 +102,7 @@ def test_stats_description_accurate_during_payday_run(mock_datetime):
This test was originally written to expose the fix required for
https://github.com/whit537/www.gittip.com/issues/92.
"""
with testing.load() as context:
with load() as context:
a_thursday = datetime(2012, 8, 9, 12, 00, 01)
mock_datetime.utcnow.return_value = a_thursday

Expand All @@ -121,7 +117,7 @@ def test_stats_description_accurate_during_payday_run(mock_datetime):
@patch('datetime.datetime')
def test_stats_description_accurate_outside_of_payday(mock_datetime):
"""Test stats page outside of the payday running"""
with testing.load() as context:
with load() as context:
a_monday = datetime(2012, 8, 6, 12, 00, 01)
mock_datetime.utcnow.return_value = a_monday

Expand Down

0 comments on commit b21e3a5

Please sign in to comment.