|
1
|
|
|
# pyre-strict |
|
2
|
|
|
|
|
3
|
|
|
""" |
|
4
|
|
|
This is the main test file for the paytext module. |
|
5
|
|
|
""" |
|
6
|
|
|
|
|
7
|
|
|
import unittest |
|
8
|
|
|
from typing import List, Dict |
|
9
|
|
|
from paytext import PaymentText |
|
10
|
|
|
|
|
11
|
|
|
EXAMPLE_TEXTS: List[Dict[str, str]] = [ |
|
12
|
|
|
{ |
|
13
|
|
|
'input': '', |
|
14
|
|
|
'expected_output': '', |
|
15
|
|
|
}, |
|
16
|
|
|
{ |
|
17
|
|
|
'input': 'COINBASE UK, LTD EUR 15,94', |
|
18
|
|
|
'expected_output': 'COINBASE UK, LTD', |
|
19
|
|
|
}, |
|
20
|
|
|
{ |
|
21
|
|
|
'input': 'COINBASE UK, LTD EUR 182,12', |
|
22
|
|
|
'expected_output': 'COINBASE UK, LTD', |
|
23
|
|
|
}, |
|
24
|
|
|
{ |
|
25
|
|
|
'input': 'Fra: Solan Gundersen 18.06.18', |
|
26
|
|
|
'expected_output': 'Fra: Solan Gundersen', |
|
27
|
|
|
}, |
|
28
|
|
|
{ |
|
29
|
|
|
'input': '*4274 25.06 NOK 4101.00 WWW.TICKET.NO Kurs: 1.0000', |
|
30
|
|
|
'expected_output': 'WWW.TICKET.NO', |
|
31
|
|
|
}, |
|
32
|
|
|
{ |
|
33
|
|
|
'input': 'OBOS FACTORING', |
|
34
|
|
|
'expected_output': 'OBOS FACTORING', |
|
35
|
|
|
}, |
|
36
|
|
|
{ |
|
37
|
|
|
'input': '30.06 COOP PRIX VG-HU AKERSGT 55 OSLO', |
|
38
|
|
|
'expected_output': 'COOP PRIX VG-HU AKERSGT 55 OSLO', |
|
39
|
|
|
}, |
|
40
|
|
|
{ |
|
41
|
|
|
'input': '*8877 01.07 USD 12.99 IRRADIATED SOFTWARE Kurs: 8.3718', |
|
42
|
|
|
'expected_output': 'IRRADIATED SOFTWARE', |
|
43
|
|
|
}, |
|
44
|
|
|
{ |
|
45
|
|
|
'input': '*3951 01.07 EUR 4.00 GOOGLE *SVCSAPPS_hoise Kurs: 9.7250', |
|
46
|
|
|
'expected_output': 'GOOGLE *SVCSAPPS_hoise', |
|
47
|
|
|
}, |
|
48
|
|
|
{ |
|
49
|
|
|
'input': '*9090 29.06 USD 1.00 SAM HARRIS MEDIA INC Kurs: 8.3700', |
|
50
|
|
|
'expected_output': 'SAM HARRIS MEDIA INC', |
|
51
|
|
|
}, |
|
52
|
|
|
{ |
|
53
|
|
|
'input': '05.07 KIWI 471 BISLET THERESESGT 3 OSLO', |
|
54
|
|
|
'expected_output': 'KIWI 471 BISLET THERESESGT 3 OSLO', |
|
55
|
|
|
}, |
|
56
|
|
|
{ |
|
57
|
|
|
'input': '04.07 DEN NORSKE TURISTFOR. OSLO', |
|
58
|
|
|
'expected_output': 'DEN NORSKE TURISTFOR. OSLO', |
|
59
|
|
|
}, |
|
60
|
|
|
{ |
|
61
|
|
|
'input': 'Nettgiro til: Universitetet i Betalt: 05.07.18', |
|
62
|
|
|
'expected_output': 'Nettgiro til: Universitetet i', |
|
63
|
|
|
}, |
|
64
|
|
|
{ |
|
65
|
|
|
'input': '05.07 REMA SANNERGATA SANNERGATA 3 OSLO', |
|
66
|
|
|
'expected_output': 'REMA SANNERGATA SANNERGATA 3 OSLO', |
|
67
|
|
|
}, |
|
68
|
|
|
{ |
|
69
|
|
|
'input': 'Vipps', |
|
70
|
|
|
'expected_output': 'Vipps', |
|
71
|
|
|
}, |
|
72
|
|
|
{ |
|
73
|
|
|
'input': '04.07 SKOM.DAGESTAD JOSEFINEGT. OSLO', |
|
74
|
|
|
'expected_output': 'SKOM.DAGESTAD JOSEFINEGT. OSLO', |
|
75
|
|
|
}, |
|
76
|
|
|
{ |
|
77
|
|
|
'input': '*4321 29.06 USD 50.00 ITUNES.COM/BILL Rate: 1.0000', |
|
78
|
|
|
'expected_output': 'ITUNES.COM/BILL', |
|
79
|
|
|
}, |
|
80
|
|
|
{ |
|
81
|
|
|
'input': '*1234 01.07 NOK 215.00 ITUNES.COM/BILL Kurs: 1.0000', |
|
82
|
|
|
'expected_output': 'ITUNES.COM/BILL', |
|
83
|
|
|
}, |
|
84
|
|
|
] |
|
85
|
|
|
|
|
86
|
|
|
|
|
87
|
|
|
class PaymentTextTest(unittest.TestCase): |
|
88
|
|
|
""" |
|
89
|
|
|
This is the test class for the PaymentText class. |
|
90
|
|
|
""" |
|
91
|
|
|
def test_generalize(self) -> None: |
|
92
|
|
|
""" |
|
93
|
|
|
Test that PaymentText.generalize() properly cleans a payment text. |
|
94
|
|
|
|
|
95
|
|
|
:return: |
|
96
|
|
|
""" |
|
97
|
|
|
for example_text in EXAMPLE_TEXTS: |
|
98
|
|
|
text = PaymentText(example_text['input']) |
|
99
|
|
|
|
|
100
|
|
|
text.generalize() |
|
101
|
|
|
|
|
102
|
|
|
self.assertEqual( |
|
103
|
|
|
str(text), |
|
104
|
|
|
example_text['expected_output'], |
|
105
|
|
|
) |
|
106
|
|
|
|
|
107
|
|
|
|
|
108
|
|
|
if __name__ == '__main__': |
|
109
|
|
|
unittest.main() |
|
110
|
|
|
|