Skip to content

Commit 2a1bc76

Browse files
committed
fix: PayPal rules tests
1 parent 4247fe2 commit 2a1bc76

File tree

2 files changed

+57
-31
lines changed

2 files changed

+57
-31
lines changed

scripts/hledger-rules/tests/test_HledgerPayPalRules.py

+44-18
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,36 @@ def test_gen_paypal_rule_empty(self):
1313
self.assertEqual(expected, actual) # add assertion here
1414
self.assertEqual(None, account) # add assertion here
1515

16+
def test_gen_paypal_rule_if_format(self):
17+
config = {
18+
'paypal': {
19+
'if_format': [
20+
'{ref}.*PP.[0-9]+.PP.*{name}.*, Ihr Einkauf bei.*PayPal',
21+
'{ref}.*PP.[0-9]+.PP.*{name}.*, Ihr Einkauf bei.*PAYPAL'
22+
],
23+
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
24+
},
25+
}
26+
rule = {
27+
'name': 'Steam',
28+
'account': 'Expenses:Hobbies:Gaming:Steam',
29+
}
30+
expected = """
31+
if .*.*PP.[0-9]+.PP.*Steam.*, Ihr Einkauf bei.*PayPal
32+
.*.*PP.[0-9]+.PP.*Steam.*, Ihr Einkauf bei.*PAYPAL
33+
description PayPal Europe S.a.r.l. et Cie S.C.A | PayPal Steam
34+
comment type:%buchungstext, payee:PayPal Europe S.a.r.l. et Cie S.C.A, name:Steam
35+
account1 Expenses:Hobbies:Gaming:Steam
36+
37+
"""
38+
actual, account = gen_paypal_rule(config, rule)
39+
self.assertEqual(expected, actual) # add assertion here
40+
self.assertEqual('Expenses:Hobbies:Gaming:Steam', account) # add assertion here
41+
1642
def test_gen_paypal_rule_name(self):
1743
config = {
1844
'paypal': {
19-
'prefix': 'PP.6330.P',
45+
'prefix': 'PP.[0-9]+.PP',
2046
'suffix': 'PayPal',
2147
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
2248
},
@@ -26,7 +52,7 @@ def test_gen_paypal_rule_name(self):
2652
'account': 'Expenses:Hobbies:Gaming:Steam',
2753
}
2854
expected = """
29-
if PP.1234.PP.*Steam.*.*.*PayPal
55+
if PP.[0-9]+.PP.*Steam.*.*.*PayPal
3056
Steam.*.*.*PayPal
3157
Steam.*PAYPAL.*.*
3258
description PayPal Europe S.a.r.l. et Cie S.C.A | PayPal Steam
@@ -41,7 +67,7 @@ def test_gen_paypal_rule_name(self):
4167
def test_gen_paypal_rule_description(self):
4268
config = {
4369
'paypal': {
44-
'prefix': 'PP.6330.P',
70+
'prefix': 'PP.[0-9]+.PP',
4571
'suffix': 'PayPal',
4672
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
4773
},
@@ -52,7 +78,7 @@ def test_gen_paypal_rule_description(self):
5278
'description': 'Steam'
5379
}
5480
expected = """
55-
if PP.1234.PP.*steampowered.*.*.*PayPal
81+
if PP.[0-9]+.PP.*steampowered.*.*.*PayPal
5682
steampowered.*.*.*PayPal
5783
steampowered.*PAYPAL.*.*
5884
description PayPal Europe S.a.r.l. et Cie S.C.A | PayPal Steam
@@ -67,7 +93,7 @@ def test_gen_paypal_rule_description(self):
6793
def test_gen_paypal_rule_full_description(self):
6894
config = {
6995
'paypal': {
70-
'prefix': 'PP.6330.P',
96+
'prefix': 'PP.[0-9]+.PP',
7197
'suffix': 'PayPal',
7298
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
7399
},
@@ -78,7 +104,7 @@ def test_gen_paypal_rule_full_description(self):
78104
'full_description': 'Google | Play Store'
79105
}
80106
expected = """
81-
if PP.1234.PP.*Google.*.*.*PayPal
107+
if PP.[0-9]+.PP.*Google.*.*.*PayPal
82108
Google.*.*.*PayPal
83109
Google.*PAYPAL.*.*
84110
description Google | Play Store
@@ -93,7 +119,7 @@ def test_gen_paypal_rule_full_description(self):
93119
def test_gen_paypal_rule_payee(self):
94120
config = {
95121
'paypal': {
96-
'prefix': 'PP.6330.P',
122+
'prefix': 'PP.[0-9]+.PP',
97123
'suffix': 'PayPal',
98124
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
99125
},
@@ -105,7 +131,7 @@ def test_gen_paypal_rule_payee(self):
105131
'payee': 'PayPal Europe S.a.r.l., et Cie S.C.A'
106132
}
107133
expected = """
108-
if PP.1234.PP.*steampowered.*.*.*PayPal
134+
if PP.[0-9]+.PP.*steampowered.*.*.*PayPal
109135
steampowered.*.*.*PayPal
110136
steampowered.*PAYPAL.*.*
111137
description PayPal Europe S.a.r.l., et Cie S.C.A | PayPal Steam
@@ -120,7 +146,7 @@ def test_gen_paypal_rule_payee(self):
120146
def test_gen_paypal_rule_no_payee(self):
121147
config = {
122148
'paypal': {
123-
'prefix': 'PP.6330.P',
149+
'prefix': 'PP.[0-9]+.PP',
124150
'suffix': 'PayPal',
125151
},
126152
}
@@ -130,7 +156,7 @@ def test_gen_paypal_rule_no_payee(self):
130156
'description': 'Steam',
131157
}
132158
expected = """
133-
if PP.1234.PP.*steampowered.*.*.*PayPal
159+
if PP.[0-9]+.PP.*steampowered.*.*.*PayPal
134160
steampowered.*.*.*PayPal
135161
steampowered.*PAYPAL.*.*
136162
description %payee | PayPal Steam
@@ -145,7 +171,7 @@ def test_gen_paypal_rule_no_payee(self):
145171
def test_gen_paypal_rule_amount(self):
146172
config = {
147173
'paypal': {
148-
'prefix': 'PP.6330.P',
174+
'prefix': 'PP.[0-9]+.PP',
149175
'suffix': 'PayPal',
150176
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
151177
},
@@ -158,8 +184,8 @@ def test_gen_paypal_rule_amount(self):
158184
'amount': -19.99,
159185
}
160186
expected = """
161-
if PP.1234.PP.*steampowered.*.*.*PayPal.*, -19,99
162-
PP.1234.PP.*steampowered.*.*.*PayPal.*,-19,99
187+
if PP.[0-9]+.PP.*steampowered.*.*.*PayPal.*, -19,99
188+
PP.[0-9]+.PP.*steampowered.*.*.*PayPal.*,-19,99
163189
steampowered.*.*.*PayPal.*, -19,99
164190
steampowered.*.*.*PayPal.*,-19,99
165191
steampowered.*PAYPAL.*.*.*, -19,99
@@ -176,7 +202,7 @@ def test_gen_paypal_rule_amount(self):
176202
def test_gen_paypal_rule_currency(self):
177203
config = {
178204
'paypal': {
179-
'prefix': 'PP.6330.P',
205+
'prefix': 'PP.[0-9]+.PP',
180206
'suffix': 'PayPal',
181207
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
182208
},
@@ -190,8 +216,8 @@ def test_gen_paypal_rule_currency(self):
190216
'currency': 'EUR'
191217
}
192218
expected = """
193-
if PP.1234.PP.*steampowered.*.*.*PayPal.*, -19,99,EUR
194-
PP.1234.PP.*steampowered.*.*.*PayPal.*,-19,99,EUR
219+
if PP.[0-9]+.PP.*steampowered.*.*.*PayPal.*, -19,99,EUR
220+
PP.[0-9]+.PP.*steampowered.*.*.*PayPal.*,-19,99,EUR
195221
steampowered.*.*.*PayPal.*, -19,99,EUR
196222
steampowered.*.*.*PayPal.*,-19,99,EUR
197223
steampowered.*PAYPAL.*.*.*, -19,99,EUR
@@ -208,7 +234,7 @@ def test_gen_paypal_rule_currency(self):
208234
def test_gen_paypal_rule_big_amount(self):
209235
config = {
210236
'paypal': {
211-
'prefix': 'PP.6330.P',
237+
'prefix': 'PP.[0-9]+.PP',
212238
'suffix': 'PayPal',
213239
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
214240
},
@@ -221,7 +247,7 @@ def test_gen_paypal_rule_big_amount(self):
221247
'amount': -649.0,
222248
}
223249
expected = """
224-
if PP.1234.PP.*MMS E-Commerce GmbH.*.*.*PayPal.*,-649
250+
if PP.[0-9]+.PP.*MMS E-Commerce GmbH.*.*.*PayPal.*,-649
225251
MMS E-Commerce GmbH.*.*.*PayPal.*,-649
226252
MMS E-Commerce GmbH.*PAYPAL.*.*.*,-649
227253
description PayPal Europe S.a.r.l. et Cie S.C.A | PayPal Saturn

scripts/hledger-rules/tests/test_HledgerRules_PayPal.py

+13-13
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_gen_paypal_rules_content_empty(self):
2020
def test_gen_paypal_rules_content_no_name(self):
2121
config = {
2222
'paypal': {
23-
'prefix': 'PP.6330.P',
23+
'prefix': 'PP.[0-9]+.PP',
2424
'suffix': 'PayPal',
2525
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
2626
},
@@ -38,7 +38,7 @@ def test_gen_paypal_rules_content_no_name(self):
3838
def test_gen_paypal_rules_content_name(self):
3939
config = {
4040
'paypal': {
41-
'prefix': 'PP.6330.P',
41+
'prefix': 'PP.[0-9]+.PP',
4242
'suffix': 'PayPal',
4343
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
4444
},
@@ -53,7 +53,7 @@ def test_gen_paypal_rules_content_name(self):
5353
expected = """;;do not change, generated file from paypal.csv.rules template
5454
5555
56-
if PP.1234.PP.*GOG.*PayPal.*.*.*.*
56+
if PP.[0-9]+.PP.*GOG.*PayPal.*.*.*.*
5757
GOG.*PayPal.*.*.*.*
5858
GOG.*PAYPAL.*.*.*.*
5959
description %payee | PayPal GOG
@@ -66,7 +66,7 @@ def test_gen_paypal_rules_content_name(self):
6666
def test_gen_paypal_rules_content_names(self):
6767
config = {
6868
'paypal': {
69-
'prefix': 'PP.6330.P',
69+
'prefix': 'PP.[0-9]+.PP',
7070
'suffix': 'PayPal',
7171
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
7272
},
@@ -85,13 +85,13 @@ def test_gen_paypal_rules_content_names(self):
8585
expected = """;;do not change, generated file from paypal.csv.rules template
8686
8787
88-
if PP.1234.PP.*Steam.*PayPal.*.*.*.*
88+
if PP.[0-9]+.PP.*Steam.*PayPal.*.*.*.*
8989
Steam.*PayPal.*.*.*.*
9090
Steam.*PAYPAL.*.*.*.*
91-
PP.1234.PP.*STEAM.*PayPal.*.*.*.*
91+
PP.[0-9]+.PP.*STEAM.*PayPal.*.*.*.*
9292
STEAM.*PayPal.*.*.*.*
9393
STEAM.*PAYPAL.*.*.*.*
94-
PP.1234.PP.*steampowered.*PayPal.*.*.*.*
94+
PP.[0-9]+.PP.*steampowered.*PayPal.*.*.*.*
9595
steampowered.*PayPal.*.*.*.*
9696
steampowered.*PAYPAL.*.*.*.*
9797
description %payee | PayPal Steam
@@ -104,7 +104,7 @@ def test_gen_paypal_rules_content_names(self):
104104
def test_gen_paypal_rules_content_ref(self):
105105
config = {
106106
'paypal': {
107-
'prefix': 'PP.6330.P',
107+
'prefix': 'PP.[0-9]+.PP',
108108
'suffix': 'PayPal',
109109
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
110110
},
@@ -122,7 +122,7 @@ def test_gen_paypal_rules_content_ref(self):
122122
expected = """;;do not change, generated file from paypal.csv.rules template
123123
124124
125-
if PP.1234.PP.*Google.*PayPal.*123456789.*.*
125+
if PP.[0-9]+.PP.*Google.*PayPal.*123456789.*.*
126126
Google.*PayPal.*123456789.*.*
127127
Google.*PAYPAL.*123456789.*.*
128128
description %payee | PayPal Google Play Store
@@ -135,7 +135,7 @@ def test_gen_paypal_rules_content_ref(self):
135135
def test_gen_paypal_rules_content_payee(self):
136136
config = {
137137
'paypal': {
138-
'prefix': 'PP.6330.P',
138+
'prefix': 'PP.[0-9]+.PP',
139139
'suffix': 'PayPal',
140140
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
141141
},
@@ -153,7 +153,7 @@ def test_gen_paypal_rules_content_payee(self):
153153
expected = """;;do not change, generated file from paypal.csv.rules template
154154
155155
156-
if PP.1234.PP.*Google.*PayPal.*.*.*.*
156+
if PP.[0-9]+.PP.*Google.*PayPal.*.*.*.*
157157
Google.*PayPal.*.*.*.*
158158
Google.*PAYPAL.*.*.*.*
159159
description PayPal Europe S.a.r.l. et Cie S.C.A | PayPal Google Play Store
@@ -166,7 +166,7 @@ def test_gen_paypal_rules_content_payee(self):
166166
def test_gen_paypal_rules_content_payee(self):
167167
config = {
168168
'paypal': {
169-
'prefix': 'PP.6330.P',
169+
'prefix': 'PP.[0-9]+.PP',
170170
'suffix': 'PayPal',
171171
'payee': 'PayPal Europe S.a.r.l. et Cie S.C.A',
172172
},
@@ -184,7 +184,7 @@ def test_gen_paypal_rules_content_payee(self):
184184
expected = """;;do not change, generated file from paypal.csv.rules template
185185
186186
187-
if PP.1234.PP.*Google.*PayPal.*.*.*.*
187+
if PP.[0-9]+.PP.*Google.*PayPal.*.*.*.*
188188
Google.*PayPal.*.*.*.*
189189
Google.*PAYPAL.*.*.*.*
190190
description PayPal Europe S.a.r.l. et Cie S.C.A | PayPal Google Play Store

0 commit comments

Comments
 (0)