def test_charge_success_returns_True(hb): data = ("participants", {"id": "foo", "last_bill_result": "failure"}) with testing.start_payday(*data) as context: hb.return_value = (Decimal('10.00'), Decimal('0.68'), None) actual = context.payday.charge( 'foo' , balanced_account_uri , STRIPE_CUSTOMER_ID , Decimal('1.00') ) assert actual is True, actual
def test_charge_failure_returns_False(cob): data = ("participants", {"id": "foo", "last_bill_result": "failure"}) with testing.start_payday(*data) as context: cob.return_value = (Decimal('10.00'), Decimal('0.68'), 'FAILED') actual = context.payday.charge('foo' , balanced_account_uri , STRIPE_CUSTOMER_ID , Decimal('1.00') ) assert actual is False, actual
def test_charge_success_returns_None(hb): data = ("participants", { "id": "foo" , "last_bill_result": "failure" , "balanced_account_uri": balanced_account_uri , "stripe_customer_id": STRIPE_CUSTOMER_ID , "is_suspicious": False }) with testing.start_payday(*data) as context: participant = context.db.fetchone("SELECT * FROM participants") hb.return_value = (Decimal('10.00'), Decimal('0.68'), None) actual = context.payday.charge(participant, Decimal('1.00')) assert actual is None, actual
def test_charge_success_touches_a_few_tables(hb): data = ("participants", {"id": "foo", "last_bill_result": "failure"}) with testing.start_payday(*data) as context: hb.return_value = (Decimal('10.00'), Decimal('0.68'), None) context.payday.charge( 'foo' , balanced_account_uri , STRIPE_CUSTOMER_ID , Decimal('1.00') ) expected = { "exchanges": [1,0,0] , "participants": [0,1,0] , "paydays": [1,0,0] } actual = context.diff(compact=True) assert actual == expected, actual
def test_charge_success_updates_participant(hb): data = ("participants", {"id": "foo", "last_bill_result": "failure"}) with testing.start_payday(*data) as context: hb.return_value = (Decimal('10.00'), Decimal('0.68'), None) context.payday.charge( 'foo' , balanced_account_uri , STRIPE_CUSTOMER_ID , Decimal('1.00') ) expected = [{ 'id': 'foo' , 'balance': Decimal('9.32') , 'last_bill_result': '' }] actual = context.diff()['participants']['updates'] assert actual == expected, actual
def test_charge_success_touches_a_few_tables(charge_on_balanced): charge_on_balanced.return_value = (Decimal('10.00'), Decimal('0.68'), None) data = ("participants", { "id": "foo" , "balanced_account_uri": balanced_account_uri , "last_bill_result": "failure" , "is_suspicious": False }) with testing.start_payday(*data) as context: participant = context.db.fetchone("SELECT * FROM participants") context.payday.charge(participant, Decimal('1.00')) expected = { "exchanges": [1,0,0] , "participants": [0,1,0] , "paydays": [1,0,0] } actual = context.diff(compact=True) assert actual == expected, actual
def test_charge_success_updates_participant(charge_on_balanced): charge_on_balanced.return_value = (Decimal('10.00'), Decimal('0.68'), None) data = ("participants", { "id": "foo" , "balanced_account_uri": balanced_account_uri , "last_bill_result": "failure" , "is_suspicious": False }) with testing.start_payday(*data) as context: participant = context.db.fetchone("SELECT * FROM participants") context.payday.charge(participant, Decimal('1.00')) expected = [{ 'id': 'foo' , 'balance': Decimal('9.32') , 'last_bill_result': '' }] actual = context.diff()['participants']['updates'] assert actual == expected, actual
def test_charge_without_cc_marked_as_failure(): with testing.start_payday("participants", ("foo",)) as context: context.payday.charge('foo', None, None, Decimal('1.00')) actual = get_numbers(context) assert actual == [0, 0, 1, 0, 0, 0, 0, 0], actual
def test_charge_without_cc_details_returns_False(): with testing.start_payday("participants", ("foo",)) as context: assert not context.payday.charge('foo', None, None, Decimal('1.00'))
def test_charge_without_cc_marked_as_failure(): with testing.start_payday("participants", ("foo",)) as context: participant = context.db.fetchone("SELECT * FROM participants") context.payday.charge(participant, Decimal('1.00')) actual = get_numbers(context) assert actual == [0, 0, 0, 1, 0, 0, 0, 0, 0], actual
def test_charge_without_cc_details_returns_None(): with testing.start_payday("participants", ("foo",)) as context: participant = context.db.fetchone("SELECT * FROM participants") actual = context.payday.charge(participant, Decimal('1.00')) assert actual is None, actual
def test_charge_without_cc_marked_as_failure(): with testing.start_payday("participants", ("foo",)) as context: participant = context.db.fetchone("SELECT * FROM participants") context.payday.charge(participant, Decimal('1.00')) actual = get_numbers(context) assert actual == [0, 0, 1, 0, 0, 0, 0, 0], actual