From b1ebc3d071f6ce2035cf229cb64f734fe4d49757 Mon Sep 17 00:00:00 2001 From: Chad Whitacre Date: Sat, 8 Dec 2012 00:46:07 -0500 Subject: [PATCH] Fix #413 --- gittip/testing.py | 8 ++++++-- tests/test_billing.py | 4 ++-- tests/test_is_suspicious.py | 10 +++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/gittip/testing.py b/gittip/testing.py index 5297469721..a6f50eb461 100644 --- a/gittip/testing.py +++ b/gittip/testing.py @@ -187,7 +187,11 @@ def _diff(self, a, b, compact): updates = [] deletes = [] - for key, row in b_table.items(): + # Be sure to sort {a,b}_table.items() so we can depend on the sort + # order of the inserts, updates, and deletes lists. + # See https://github.com/whit537/www.gittip.com/issues/413. + + for key, row in sorted(b_table.items()): if key not in a_table: inserts.append(row) else: @@ -200,7 +204,7 @@ def _diff(self, a, b, compact): update[pkey] = row[pkey] # include primary key updates.append(update) - for key, row in a_table.items(): + for key, row in sorted(a_table.items()): if key not in b_table: deletes.append(row) diff --git a/tests/test_billing.py b/tests/test_billing.py index a4f7a7557d..8a6f780853 100644 --- a/tests/test_billing.py +++ b/tests/test_billing.py @@ -414,8 +414,8 @@ def test_payday_moves_money(charge_on_balanced): tips = testing.setup_tips(('buz', 'bar', '6.00', True)) # under $10! with testing.load(*tips) as context: Payday(context.db).run() - expected = [ {"id": "buz", "balance": Decimal('3.32')} - , {"id": "bar", "balance": Decimal('6.00')} + expected = [ {"id": "bar", "balance": Decimal('6.00')} + , {"id": "buz", "balance": Decimal('3.32')} ] actual = context.diff()['participants']['updates'] assert actual == expected, actual diff --git a/tests/test_is_suspicious.py b/tests/test_is_suspicious.py index 9e458ae86d..a5a864e3fb 100644 --- a/tests/test_is_suspicious.py +++ b/tests/test_is_suspicious.py @@ -23,7 +23,7 @@ def test_participants_start_out_with_is_suspicious_None(): def test_toggling_NULL_gives_true(): with participants() as context: toggle_is_suspicious() - actual = context.diff()['participants']['updates'][0]['is_suspicious'] + actual = context.diff()['participants']['updates'][1]['is_suspicious'] assert actual is True, actual def test_toggling_changes_two_things(): @@ -32,22 +32,22 @@ def test_toggling_changes_two_things(): actual = context.diff(compact=True) assert actual == {'participants': [0,2,0]}, actual -def test_but_the_second_thing_is_just_bars_session(): +def test_but_the_first_thing_is_just_bars_session(): with participants() as context: toggle_is_suspicious() expected = ('bar', ['id', 'session_expires', 'session_token']) - second = context.diff()['participants']['updates'][1] + second = context.diff()['participants']['updates'][0] actual = (second['id'], sorted(second.keys())) assert actual == expected, actual def test_toggling_true_gives_false(): with participants(True) as context: toggle_is_suspicious() - actual = context.diff()['participants']['updates'][0]['is_suspicious'] + actual = context.diff()['participants']['updates'][1]['is_suspicious'] assert actual is False, actual def test_toggling_false_gives_true(): with participants(False) as context: toggle_is_suspicious() - actual = context.diff()['participants']['updates'][0]['is_suspicious'] + actual = context.diff()['participants']['updates'][1]['is_suspicious'] assert actual is True, actual