Skip to content

Commit

Permalink
Expand integration tests to include "money out" functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
countvajhula committed Jul 12, 2024
1 parent c174d89 commit f17c187
Showing 1 changed file with 98 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,37 @@
from oldabe.money_in import (
process_payments_and_record_updates,
)
from oldabe.money_out import (
compile_outstanding_balances,
)
from .fixtures import abe_fs
import os


class TestNoPayments:

@patch('oldabe.money_in.get_git_revision_short_hash', return_value='abcd123')
def test_no_transactions_generated(self, mock_git_rev, abe_fs):
with open('abe/price.txt') as f:
assert f.read() == "10"
process_payments_and_record_updates()
with open('./abe/transactions.txt') as f:
assert f.read() == ""

@patch('oldabe.money_in.get_git_revision_short_hash', return_value='abcd123')
def test_compiled_outstanding_balances(self, mock_git_rev, abe_fs):
process_payments_and_record_updates()
message = compile_outstanding_balances()
assert "There are no outstanding (payable) balances." in message
assert "There are no outstanding (unpayable) debts." in message
assert "There are no advances." in message

# TODO: in some cases even though the value is e.g. 1,
# it's writing out 3 decimal places, like 1.000. We should
# figure out why this is happening (and whether it's OK)
# and decide on appropriate handling


class TestPaymentAbovePrice:

@time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False)
@patch('oldabe.money_in.get_git_revision_short_hash', return_value='abcd123')
def test_generates_transactions(self, mock_git_rev, abe_fs):
Expand Down Expand Up @@ -61,8 +72,25 @@ def test_dilutes_attributions(self, mock_git_rev, abe_fs):
"sam,8.5\n"
)

@time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False)
@patch('oldabe.money_in.get_git_revision_short_hash', return_value='abcd123')
def test_compiled_outstanding_balances(self, mock_git_rev, abe_fs):
with localcontext() as context:
context.prec = 2
amount = 100
abe_fs.create_file("./abe/payments/1.txt",
contents=f"sam,036eaf6,{amount},dummydate")
process_payments_and_record_updates()

message = compile_outstanding_balances()

assert ("| Name | Balance |\r\n"
"| ---- | --- |\r\n"
"old abe | 1.00\r\n") in message


class TestPaymentBelowPrice:

@time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False)
@patch('oldabe.money_in.get_git_revision_short_hash', return_value='abcd123')
def test_generates_transactions(self, mock_git_rev, abe_fs):
Expand All @@ -81,14 +109,30 @@ def test_generates_transactions(self, mock_git_rev, abe_fs):
"ariana,0.19,1.txt,abcd123,1985-10-26 01:24:00\n"
)

@time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False)
@patch('oldabe.money_in.get_git_revision_short_hash', return_value='abcd123')
def test_compiled_outstanding_balances(self, mock_git_rev, abe_fs):
with localcontext() as context:
context.prec = 2
amount = 1
abe_fs.create_file("./abe/payments/1.txt",
contents=f"sam,036eaf6,{amount},dummydate")
process_payments_and_record_updates()
message = compile_outstanding_balances()

assert ("| Name | Balance |\r\n"
"| ---- | --- |\r\n"
"old abe | 0.01\r\n") in message


class TestNonAttributablePayment:

@time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False)
@patch('oldabe.money_in.get_git_revision_short_hash', return_value='abcd123')
def test_does_not_dilute_attributions(self, mock_git_rev, abe_fs):
with localcontext() as context:
context.prec = 2
amount = 10000
amount = 100
abe_fs.create_file("./abe/payments/nonattributable/1.txt",
contents=f"sam,036eaf6,{amount},dummydate")
process_payments_and_record_updates()
Expand All @@ -99,6 +143,39 @@ def test_does_not_dilute_attributions(self, mock_git_rev, abe_fs):
"ariana,20\n"
)

@time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False)
@patch('oldabe.money_in.get_git_revision_short_hash', return_value='abcd123')
def test_generates_transactions(self, mock_git_rev, abe_fs):
with localcontext() as context:
context.prec = 2
amount = 100
abe_fs.create_file("./abe/payments/1.txt",
contents=f"sam,036eaf6,{amount},dummydate")
process_payments_and_record_updates()
with open('./abe/transactions.txt') as f:
assert f.read() == (
"old abe,1.0,1.txt,abcd123,1985-10-26 01:24:00\n"
"DIA,5.0,1.txt,abcd123,1985-10-26 01:24:00\n"
"sid,47,1.txt,abcd123,1985-10-26 01:24:00\n"
"jair,28,1.txt,abcd123,1985-10-26 01:24:00\n"
"ariana,19,1.txt,abcd123,1985-10-26 01:24:00\n"
)

@time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False)
@patch('oldabe.money_in.get_git_revision_short_hash', return_value='abcd123')
def test_compiled_outstanding_balances(self, mock_git_rev, abe_fs):
with localcontext() as context:
context.prec = 2
amount = 100
abe_fs.create_file("./abe/payments/nonattributable/1.txt",
contents=f"sam,036eaf6,{amount},dummydate")
process_payments_and_record_updates()
message = compile_outstanding_balances()

assert ("| Name | Balance |\r\n"
"| ---- | --- |\r\n"
"old abe | 1.00\r\n") in message


class TestUnpayableContributor:

Expand Down Expand Up @@ -145,6 +222,15 @@ def test_records_advances(self, mock_git_rev, abe_fs):
"jair,6.8,1.txt,abcd123,1985-10-26 01:24:00\n"
)

@time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False)
@patch('oldabe.money_in.get_git_revision_short_hash', return_value='abcd123')
def test_compiled_outstanding_balances(self, mock_git_rev, abe_fs):
self._call(abe_fs)
message = compile_outstanding_balances()
assert ("| Name | Debt |\r\n"
"| ---- | --- |\r\n"
"ariana | 19.00\r\n") in message


class TestUnpayableContributorBecomesPayable:

Expand Down Expand Up @@ -218,3 +304,12 @@ def test_advances(self, mock_git_rev, abe_fs):
"jair,5.4,2.txt,abcd123,1985-10-26 01:24:00\n"
"ariana,3.6,2.txt,abcd123,1985-10-26 01:24:00\n"
)

@time_machine.travel(datetime(1985, 10, 26, 1, 24), tick=False)
@patch('oldabe.money_in.get_git_revision_short_hash', return_value='abcd123')
def test_compiled_outstanding_balances(self, mock_git_rev, abe_fs):
self._call(abe_fs)
message = compile_outstanding_balances()
assert ("| Name | Debt |\r\n"
"| ---- | --- |\r\n"
"ariana | 0.00\r\n") in message

0 comments on commit f17c187

Please sign in to comment.