-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_e2es.py
153 lines (143 loc) · 4.28 KB
/
test_e2es.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
from fixtures import *
from jointSpendingCalculator import *
def test_2_other_people_split_first_file_statement_owner_pays_for_second(monkeypatch, directory, totals_spreadsheet, delete_html_file):
'''
Two friends of the statement owner split the cost of all of the transactions in the first statement
The statement owner of the 2nd statement pays for all of their transactions
'''
mocked_input = iter([
'test_data', 'totals',
'Jan',
'Co-operative',
'Padme Reggie', 'Padme Reggie', 'Padme Reggie',
'Reggie',
'Monzo',
'Reggie', 'Reggie', 'Reggie'
])
monkeypatch.setattr('builtins.input', lambda _:next(mocked_input))
expected = [
{
'Padme': '205.0',
'Reggie': '205.0',
'Jan': '0.0',
'owes': 'Jan'
},
{
'Padme': '0.0',
'Reggie': '0.0',
'Jan': '0.0',
'owes': 'Reggie'
}
]
main()
with open(directory + totals_spreadsheet, 'r') as t:
t_s = csv.DictReader(t)
totals_sheet = list(t_s)
assert totals_sheet == expected
def test_SO_and_4_friends_split_first_transaction_and_a_few_pay_for_last_statement(monkeypatch, directory, totals_spreadsheet, delete_html_file):
'''
The statement owner and 4 friends split each transaction in the first statement
Different people pay for the transactions in the 2nd statement
'''
mocked_input = iter([
'test_data', 'totals',
'Jan',
'Co-operative',
'Jan Padme Reggie Sophie Lou', 'Jan Lou Sophie Padme Reggie', 'Padme Sophie Lou Jan Reggie',
'Reggie',
'Monzo',
'Albert John', 'Thomas Reggie', 'Reggie Padme'
])
monkeypatch.setattr('builtins.input', lambda _:next(mocked_input))
expected = [
{
'Albert':'0.0',
'Jan': '0.0',
'John':'0.0',
'Lou':'82.0',
'Padme': '82.0',
'Sophie':'82.0',
'Reggie': '82.0',
'Thomas':'0.0',
'owes': 'Jan'
},
{
'Albert':'7.5',
'Jan': '0.0',
'John':'7.5',
'Lou':'0.0',
'Padme': '27.5',
'Reggie': '0.0',
'Sophie':'0.0',
'Thomas':'10.0',
'owes': 'Reggie'
}
]
main()
with open(directory + totals_spreadsheet, 'r') as t:
t_s = csv.DictReader(t)
totals_sheet = list(t_s)
assert totals_sheet == expected
def test_2_statements_from_the_same_person(monkeypatch, directory, totals_spreadsheet, delete_html_file):
'''
The same statement owner for 2 separate statements
'''
mocked_input = iter([
'test_data', 'totals',
'Jan',
'Co-operative',
'Jan Padme Reggie Sophie Lou', 'Jan Lou Sophie Padme Reggie', 'Padme Sophie Lou Jan Reggie',
'Jan',
'Monzo',
'Albert John', 'Thomas Reggie', 'Reggie Padme'
])
monkeypatch.setattr('builtins.input', lambda _:next(mocked_input))
expected = [
{
'Albert':'7.5',
'Jan': '0.0',
'John':'7.5',
'Lou':'82.0',
'Padme': '109.5',
'Sophie':'82.0',
'Reggie': '119.5',
'Thomas':'10.0',
'owes': 'Jan'
}
]
main()
with open(directory + totals_spreadsheet, 'r') as t:
t_s = csv.DictReader(t)
totals_sheet = list(t_s)
assert totals_sheet == expected
def test_skip_one_transaction(monkeypatch, directory, totals_spreadsheet, delete_html_file):
'''
The same statement owner for 2 separate statements
'''
mocked_input = iter([
'test_data', 'totals',
'Jan',
'Co-operative',
'Jan Padme Reggie Sophie Lou', '*SKIP*', 'Padme Sophie Lou Jan Reggie',
'Jan',
'Monzo',
'Albert John', '*SKIP*', 'Reggie Padme'
])
monkeypatch.setattr('builtins.input', lambda _:next(mocked_input))
expected = [
{
'Albert':'7.5',
'Jan': '0.0',
'John':'7.5',
'Lou':'12.0',
'Padme': '39.5',
'Sophie':'12.0',
'Reggie': '39.5',
'owes': 'Jan'
}
]
main()
with open(directory + totals_spreadsheet, 'r') as t:
t_s = csv.DictReader(t)
totals_sheet = list(t_s)
assert totals_sheet == expected