From b21e3a5e3ce452d79bd8f1bc7690b895ac86de89 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Fri, 7 Dec 2012 15:04:26 -0500 Subject: [PATCH] Add testing.tip_graph convenience (#406) --- gittip/testing.py | 4 ++++ tests/test_pages.py | 6 +++--- tests/test_stats.py | 28 ++++++++++++---------------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/gittip/testing.py b/gittip/testing.py index e89220ae9d..5297469721 100644 --- a/gittip/testing.py +++ b/gittip/testing.py @@ -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. # ============================== diff --git a/tests/test_pages.py b/tests/test_pages.py index 9fdc01038e..0a1bfaa9de 100644 --- a/tests/test_pages.py +++ b/tests/test_pages.py @@ -1,4 +1,4 @@ -from gittip.testing import serve_request, load, setup_tips +from gittip.testing import serve_request, tip_graph def test_homepage(): @@ -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 diff --git a/tests/test_stats.py b/tests/test_stats.py index 39cdd038ca..02ee5656af 100644 --- a/tests/test_stats.py +++ b/tests/test_stats.py @@ -1,8 +1,8 @@ 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 @@ -10,7 +10,7 @@ # commaize -simplate = testing.load_simplate('/about/stats.html') +simplate = load_simplate('/about/stats.html') commaize = simplate.pages[0]['commaize'] def test_commaize_commaizes(): @@ -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 @@ -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 @@ -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 @@ -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 @@ -87,7 +83,7 @@ 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 @@ -95,7 +91,7 @@ def test_get_chart_of_receiving_ignores_missing_cc(): # rendering def get_stats_page(): - response = testing.serve_request('/about/stats.html') + response = serve_request('/about/stats.html') return response.body @@ -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 @@ -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