-
Notifications
You must be signed in to change notification settings - Fork 1
/
testdetail.py
254 lines (158 loc) · 7.84 KB
/
testdetail.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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import string
from rulesdetail import TRANSACTION_CODES
from rulesdetail import record_type, bsb_number, account_number, indicator, transaction_code, amount, title
from rulesdetail import lodgement_reference, trace_record_bsb, trace_record_account_number, remitter_name
from rulesdetail import withholding_tax
def test_record_type_valid():
all_lines = ('1 (remainder of string should not matter)', )
assert record_type(all_lines, 0) is None
def test_record_type_invalid():
all_lines = tuple((ch for ch in string.printable if ch != '1')) # '1' is the right character
for i, _ in enumerate(all_lines):
assert record_type(all_lines, i) is not None
def test_bsb_number_valid():
all_lines = (' 123-456 ', )
assert bsb_number(all_lines, 0) is None
def test_bsb_number_invalid_hyphen_missing():
all_lines = (' 123456 ', )
assert bsb_number(all_lines, 0) is not None
def test_bsb_number_invalid_hyphen_replaced():
all_lines = (' 123 456 ', )
assert bsb_number(all_lines, 0) is not None
def test_bsb_number_invalid_non_digit_in_first_triplet():
all_lines = (' 1a3-456 ', )
assert bsb_number(all_lines, 0) is not None
def test_bsb_number_invalid_non_digit_in_second_triplet():
all_lines = (' 123-45x ', )
assert bsb_number(all_lines, 0) is not None
def test_account_number_valid_eight_digits_no_hyphen():
all_lines = (' ' * 8 + ' 12345678', )
assert account_number(all_lines, 0) is None
def test_account_number_valid_eight_digits_with_hyphen():
all_lines = (' ' * 8 + '1234-5678', )
assert account_number(all_lines, 0) is None
def test_account_number_valid_nine_digits():
all_lines = (' ' * 8 + '123456789', )
assert account_number(all_lines, 0) is None
def test_account_number_valid_blank():
all_lines = (' ' * 8 + ' ' * 9, ) # for credit card transactions the account number can be blank
assert account_number(all_lines, 0) is None
def test_account_number_valid_employee_benefits_card():
all_lines = (' ' * 8 + ' 999999', ) # for employee benefits card transactions, account number must be '999999'
assert account_number(all_lines, 0) is None
def test_account_number_invalid_left_justified():
all_lines = (' ' * 8 + '123456 ', )
assert account_number(all_lines, 0) is not None
def test_account_number_invalid_bad_character():
all_lines = (' ' * 8 + ' x23456', )
assert account_number(all_lines, 0) is not None
def test_account_number_invalid_all_zeroes():
all_lines = (' ' * 8 + '0' * 9, )
assert account_number(all_lines, 0) is not None
def test_indicator_valid():
good_chars = ' NWXY'
all_lines = tuple((' ' * 17 + ch for ch in good_chars))
for i, _ in enumerate(all_lines):
assert indicator(all_lines, i) is None
def test_indicator_invalid():
good_chars = ' NWXY'
all_lines = tuple((' ' * 17 + ch for ch in string.printable if ch not in good_chars))
for i, _ in enumerate(all_lines):
assert indicator(all_lines, i) is not None
def test_transaction_code_valid():
all_lines = tuple((' ' * 18 + code for code in TRANSACTION_CODES))
for i, _ in enumerate(all_lines):
assert transaction_code(all_lines, i) is None
def test_transaction_code_invalid():
all_lines = tuple((' ' * 18 + code for code in (' ', 'ab', '12', ')(')))
for i, _ in enumerate(all_lines):
assert transaction_code(all_lines, i) is not None
def test_amount_valid():
all_lines = tuple((' ' * 20 + '{:010d}'.format(i) for i in (1, 100, 10000, 1000000000, 9999999999)))
for i, _ in enumerate(all_lines):
assert amount(all_lines, i) is None
def test_amount_invalid():
all_lines = tuple((' ' * 20 + amount_ for amount_ in ('not an amount', 'blah blah ' ' ')))
for i, _ in enumerate(all_lines):
assert amount(all_lines, i) is not None
def test_title_valid_full():
all_lines = (' ' * 30 + 'x' * 32, )
assert title(all_lines, 0) is None
def test_title_valid_left_justified():
all_lines = (' ' * 30 + 'x' * 27 + ' ' * 5, )
assert title(all_lines, 0) is None
def test_title_invalid_right_justified():
all_lines = (' ' * 30 + ' ' * 5 + 'x' * 27, )
assert title(all_lines, 0) is not None
def test_title_invalid_blank():
all_lines = (' ' * 62, )
assert title(all_lines, 0) is not None
def test_lodgement_reference_valid_full():
all_lines = (' ' * 62 + 'x' * 18, )
assert lodgement_reference(all_lines, 0) is None
def test_lodgement_reference_valid_left_justified():
all_lines = (' ' * 60 + 'x' * 14 + ' ' * 4, )
assert lodgement_reference(all_lines, 0) is None
def test_lodgement_reference_invalid_right_justified():
all_lines = (' ' * 60 + ' ' * 4 + 'x' * 14, )
assert lodgement_reference(all_lines, 0) is not None
def test_lodgement_reference_invalid_blank():
all_lines = (' ' * 80, )
assert lodgement_reference(all_lines, 0) is not None
def test_trace_record_bsb_valid():
all_lines = (' ' * 80 + '123-456', )
assert trace_record_bsb(all_lines, 0) is None
def test_trace_record_bsb_invalid_hyphen_missing():
all_lines = (' ' * 80 + '123456', )
assert trace_record_bsb(all_lines, 0) is not None
def test_trace_record_bsb_invalid_hyphen_replaced():
all_lines = (' ' * 80 + '123 456', )
assert trace_record_bsb(all_lines, 0) is not None
def test_trace_record_bsb_invalid_non_digit_in_first_triplet():
all_lines = (' ' * 80 + '1a3-456', )
assert trace_record_bsb(all_lines, 0) is not None
def test_trace_record_bsb_invalid_non_digit_in_second_triplet():
all_lines = (' 123-45x ', )
assert trace_record_bsb(all_lines, 0) is not None
def test_trace_record_account_number_valid_eight_digits_no_hyphen():
all_lines = (' ' * 87 + ' 12345678', )
assert trace_record_account_number(all_lines, 0) is None
def test_trace_record_account_number_valid_eight_digits_with_hyphen():
all_lines = (' ' * 87 + '1234-5678', )
assert trace_record_account_number(all_lines, 0) is None
def test_trace_record_account_number_valid_nine_digits():
all_lines = (' ' * 87 + '123456789', )
assert trace_record_account_number(all_lines, 0) is None
def test_trace_record_account_number_valid_blank():
all_lines = (' ' * 87 + ' ' * 9, ) # for credit card transactions the account number can be blank
assert trace_record_account_number(all_lines, 0) is None
def test_trace_record_account_number_valid_employee_benefits_card():
all_lines = (' ' * 87 + ' 999999', ) # for employee benefits card transactions, account number must be '999999'
assert trace_record_account_number(all_lines, 0) is None
def test_trace_record_account_number_invalid_left_justified():
all_lines = (' ' * 87 + '123456 ', )
assert trace_record_account_number(all_lines, 0) is not None
def test_trace_record_account_number_invalid_bad_character():
all_lines = (' ' * 87 + ' x23456', )
assert trace_record_account_number(all_lines, 0) is not None
def test_trace_record_account_number_invalid_all_zeroes():
all_lines = (' ' * 87 + '0' * 9, )
assert trace_record_account_number(all_lines, 0) is not None
def test_remitter_name_valid():
all_lines = (' ' * 96 + 'X' * 16, )
assert remitter_name(all_lines, 0) is None
def test_remitter_name_invalid_blank():
all_lines = (' ' * 96 + ' ' * 16, )
assert remitter_name(all_lines, 0) is not None
def test_remitter_name_invalid_right_justified():
all_lines = (' ' * 96 + ' ' * 15 + 'X', )
assert remitter_name(all_lines, 0) is not None
def test_withholding_tax_valid_zero():
all_lines = (' ' * 112 + '0' * 8, )
assert withholding_tax(all_lines, 0) is None
def test_withholding_tax_valid_non_zero():
all_lines = (' ' * 112 + '12345678', )
assert withholding_tax(all_lines, 0) is None
def test_withholding_tax_invalid():
all_lines = (' ' * 112 + '1234567X', )
assert withholding_tax(all_lines, 0) is not None