Skip to content

Commit 90c9b2a

Browse files
author
CoderOMaster
committed
lint-ed changes
1 parent b982f47 commit 90c9b2a

4 files changed

Lines changed: 654 additions & 316 deletions

File tree

test/full_test_procedure.py

Lines changed: 229 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,250 @@
1-
from helpers import ADD_TIME, SET_TIME, DISABLE_VALUE, generate_from_device_data, test_accepted_validator, test_how_many_days_validator, test_name
21
import codecs
32

3+
from helpers import (
4+
ADD_TIME,
5+
DISABLE_VALUE,
6+
SET_TIME,
7+
generate_from_device_data,
8+
test_accepted_validator,
9+
test_how_many_days_validator,
10+
test_name,
11+
)
12+
413
from openpaygo.simulators.device_simulator import DeviceSimulator
5-
from openpaygo.simulators.server_simulator import SingleDeviceServerSimulator
614

715
# This tests the device simulator against the full test procedure
816

917

1018
def run_core_token_tests(device_data, device_simulator):
11-
12-
test = 'We enter an invalid token'
13-
token_g1 = '123 456 789'
14-
test_accepted_validator(device_simulator, 'G1', token_g1, -1, description=test)
15-
16-
test = 'We enter a valid token for setting one day'
17-
device_data, token_g2 = generate_from_device_data(device_data, token_type=SET_TIME, value_days=1)
18-
test_how_many_days_validator(device_simulator, 'G2', token_g2, 1, description=test)
19-
20-
test = 'We enter a valid token for adding one day'
21-
device_data, token_g3 = generate_from_device_data(device_data, token_type=ADD_TIME, value_days=1)
22-
test_how_many_days_validator(device_simulator, 'G3', token_g3, 2, description=test)
23-
24-
test = 'We enter the same Add Time token for 1 day, the days should not be added and the device should signal that the token was already used'
25-
test_how_many_days_validator(device_simulator, 'G4A', token_g3, 2, description=test, accepted_but_used=True)
26-
test = 'We enter the older Set Time token for 1 day, the days should not change and the device should signal that the token was already used'
27-
test_how_many_days_validator(device_simulator, 'G4B', token_g2, 2, description=test, accepted_but_used=True)
28-
29-
test = 'We enter a valid token for setting 30 days and ensures it sets and does not add to the existing'
30-
device_data, token_g5 = generate_from_device_data(device_data, token_type=SET_TIME, value_days=30)
31-
test_how_many_days_validator(device_simulator, 'G5', token_g5, 30, description=test)
32-
33-
test = 'We enter a valid token for setting 0 days and ensures the device is inactive with the outputs disabled immediately'
34-
device_data, token_g6 = generate_from_device_data(device_data, token_type=SET_TIME, value_days=0)
35-
test_how_many_days_validator(device_simulator, 'G6', token_g6, 0, description=test)
36-
37-
test = 'We enter 3 consecutive Add Time tokens with the maximum amount of days and ensure that they cumulate properly'
38-
for i in range(1,3+1):
39-
device_data, token_g7 = generate_from_device_data(device_data, token_type=ADD_TIME, value_raw=995)
40-
test_how_many_days_validator(device_simulator, test_name('G7', i), token_g7, value_raw=995*i, device_data=device_data, description=test)
41-
test = ''
42-
43-
test = 'We enter 21 consecutive Set Time tokens for 1, 2, 3, … 21 days each with a count 30 higher than the other. The validation of the token should not take more than 5 seconds'
44-
for i in range(1,21+1):
45-
device_data, token_g8 = generate_from_device_data(device_data, token_type=SET_TIME, value_days=i, token_count=device_data['token_count']+29)
46-
test_how_many_days_validator(device_simulator, test_name('G8', i), token_g8, value_days=i, device_data=device_data, description=test)
47-
test = ''
48-
49-
test = 'We enter a PAYG Disable token into the device'
50-
device_data, token_g9 = generate_from_device_data(device_data, token_type=SET_TIME, value_raw=DISABLE_VALUE)
51-
test_how_many_days_validator(device_simulator, 'G9', token_g9, None, description=test)
52-
53-
test = 'We enter a Set Time token for 0 day, it should relock the device'
54-
device_data, token_g10 = generate_from_device_data(device_data, token_type=SET_TIME, value_days=0)
55-
test_how_many_days_validator(device_simulator, 'G10', token_g10, 0, description=test)
56-
57-
test = 'We enter a PAYG Disable token to relock the device, then enter a Add Time token with 0 day, it should NOT relock the device (Optional)'
58-
device_data, token_g11a = generate_from_device_data(device_data, token_type=SET_TIME, value_raw=DISABLE_VALUE)
59-
test_how_many_days_validator(device_simulator, 'G11A', token_g11a, None, description=test)
60-
device_data, token_g11b = generate_from_device_data(device_data, token_type=ADD_TIME, value_days=0)
61-
test_how_many_days_validator(device_simulator, 'G11B', token_g11b, None)
62-
63-
test = 'We deactivate the device with a Set Time of 0 days. We then wait 48 hours before entering a Add Time of 1 day and ensuring that the days late are not considered in the activation time'
64-
device_data, token_g12a = generate_from_device_data(device_data, token_type=SET_TIME, value_days=0)
65-
test_how_many_days_validator(device_simulator, 'G12A', token_g12a, 0, description=test)
66-
device_data, token_g12b = generate_from_device_data(device_data, token_type=ADD_TIME, value_days=1)
67-
test_how_many_days_validator(device_simulator, 'G12B', token_g12b, 1)
19+
test = "We enter an invalid token"
20+
token_g1 = "123 456 789"
21+
test_accepted_validator(device_simulator, "G1", token_g1, -1, description=test)
22+
23+
test = "We enter a valid token for setting one day"
24+
device_data, token_g2 = generate_from_device_data(
25+
device_data, token_type=SET_TIME, value_days=1
26+
)
27+
test_how_many_days_validator(device_simulator, "G2", token_g2, 1, description=test)
28+
29+
test = "We enter a valid token for adding one day"
30+
device_data, token_g3 = generate_from_device_data(
31+
device_data, token_type=ADD_TIME, value_days=1
32+
)
33+
test_how_many_days_validator(device_simulator, "G3", token_g3, 2, description=test)
34+
35+
test = (
36+
"We enter the same Add Time token for 1 day, the days should not be "
37+
"added and the device should signal that the token was already used"
38+
)
39+
test_how_many_days_validator(
40+
device_simulator,
41+
"G4A",
42+
token_g3,
43+
2,
44+
description=test,
45+
accepted_but_used=True,
46+
)
47+
test = (
48+
"We enter the older Set Time token for 1 day, the days should not "
49+
"change and the device should signal that the token was already used"
50+
)
51+
test_how_many_days_validator(
52+
device_simulator,
53+
"G4B",
54+
token_g2,
55+
2,
56+
description=test,
57+
accepted_but_used=True,
58+
)
59+
60+
test = (
61+
"We enter a valid token for setting 30 days and ensures it sets and does "
62+
"not add to the existing"
63+
)
64+
device_data, token_g5 = generate_from_device_data(
65+
device_data, token_type=SET_TIME, value_days=30
66+
)
67+
test_how_many_days_validator(device_simulator, "G5", token_g5, 30, description=test)
68+
69+
test = (
70+
"We enter a valid token for setting 0 days and ensures the device is "
71+
"inactive with the outputs disabled immediately"
72+
)
73+
device_data, token_g6 = generate_from_device_data(
74+
device_data, token_type=SET_TIME, value_days=0
75+
)
76+
test_how_many_days_validator(device_simulator, "G6", token_g6, 0, description=test)
77+
78+
test = (
79+
"We enter 3 consecutive Add Time tokens with the maximum amount of days and "
80+
"ensure that they cumulate properly"
81+
)
82+
for i in range(1, 3 + 1):
83+
device_data, token_g7 = generate_from_device_data(
84+
device_data, token_type=ADD_TIME, value_raw=995
85+
)
86+
test_how_many_days_validator(
87+
device_simulator,
88+
test_name("G7", i),
89+
token_g7,
90+
value_raw=995 * i,
91+
device_data=device_data,
92+
description=test,
93+
)
94+
test = ""
95+
96+
test = (
97+
"We enter 21 consecutive Set Time tokens for 1, 2, 3, … 21 days "
98+
"each with a count 30 higher than the other. The validation of the "
99+
"token should not take more than 5 seconds"
100+
)
101+
for i in range(1, 21 + 1):
102+
device_data, token_g8 = generate_from_device_data(
103+
device_data,
104+
token_type=SET_TIME,
105+
value_days=i,
106+
token_count=device_data["token_count"] + 29,
107+
)
108+
test_how_many_days_validator(
109+
device_simulator,
110+
test_name("G8", i),
111+
token_g8,
112+
value_days=i,
113+
device_data=device_data,
114+
description=test,
115+
)
116+
test = ""
117+
118+
test = "We enter a PAYG Disable token into the device"
119+
device_data, token_g9 = generate_from_device_data(
120+
device_data, token_type=SET_TIME, value_raw=DISABLE_VALUE
121+
)
122+
test_how_many_days_validator(
123+
device_simulator, "G9", token_g9, None, description=test
124+
)
125+
126+
test = "We enter a Set Time token for 0 day, it should relock the device"
127+
device_data, token_g10 = generate_from_device_data(
128+
device_data, token_type=SET_TIME, value_days=0
129+
)
130+
test_how_many_days_validator(
131+
device_simulator, "G10", token_g10, 0, description=test
132+
)
133+
134+
test = (
135+
"We enter a PAYG Disable token to relock the device, then enter a Add "
136+
"Time token with 0 day, it should NOT relock the device (Optional)"
137+
)
138+
device_data, token_g11a = generate_from_device_data(
139+
device_data, token_type=SET_TIME, value_raw=DISABLE_VALUE
140+
)
141+
test_how_many_days_validator(
142+
device_simulator, "G11A", token_g11a, None, description=test
143+
)
144+
device_data, token_g11b = generate_from_device_data(
145+
device_data, token_type=ADD_TIME, value_days=0
146+
)
147+
test_how_many_days_validator(device_simulator, "G11B", token_g11b, None)
148+
149+
test = (
150+
"We deactivate the device with a Set Time of 0 days. We then wait "
151+
"48 hours before entering a Add Time of 1 day and ensuring that the "
152+
"days late are not considered in the activation time"
153+
)
154+
device_data, token_g12a = generate_from_device_data(
155+
device_data, token_type=SET_TIME, value_days=0
156+
)
157+
test_how_many_days_validator(
158+
device_simulator, "G12A", token_g12a, 0, description=test
159+
)
160+
device_data, token_g12b = generate_from_device_data(
161+
device_data, token_type=ADD_TIME, value_days=1
162+
)
163+
test_how_many_days_validator(device_simulator, "G12B", token_g12b, 1)
68164

69165
return device_data
70166

71167

72168
def run_unordered_entry_tests(device_data, device_simulator):
73-
74-
test = 'We generate 3 Add Time tokens, then enter the 3rd, then first, then second and ensure the days are added properly'
75-
device_data, token_u1a = generate_from_device_data(device_data, token_type=SET_TIME, value_days=60)
76-
test_how_many_days_validator(device_simulator, 'U1A', token_u1a, 60, description=test)
77-
device_data, token_u1b = generate_from_device_data(device_data, token_type=ADD_TIME, value_days=10)
78-
device_data, token_u1c = generate_from_device_data(device_data, token_type=ADD_TIME, value_days=5)
79-
device_data, token_u1d = generate_from_device_data(device_data, token_type=ADD_TIME, value_days=1)
80-
test_how_many_days_validator(device_simulator, 'U1B', token_u1d, 61)
81-
test_how_many_days_validator(device_simulator, 'U1C', token_u1b, 71)
82-
test_how_many_days_validator(device_simulator, 'U1D', token_u1c, 76)
83-
84-
test = 'We generate an Add Time, a Set Time and another Add Time token. We enter the set time and ensure that the older Add Time does not work but the newer does'
85-
device_data, token_u2a = generate_from_device_data(device_data, token_type=ADD_TIME, value_days=5)
86-
device_data, token_u2b = generate_from_device_data(device_data, token_type=SET_TIME, value_days=10)
87-
device_data, token_u2c = generate_from_device_data(device_data, token_type=ADD_TIME, value_days=3)
88-
test_how_many_days_validator(device_simulator, 'U2A', token_u2b, 10, description=test)
89-
test_how_many_days_validator(device_simulator, 'U2B', token_u2a, 10, accepted_but_used=True)
90-
test_how_many_days_validator(device_simulator, 'U2C', token_u2c, 13)
91-
92-
test = 'We generate an Add Time token and a Disable PAYG token, we enter the Disable PAYG token and then the Add Time token should be refused'
93-
device_data, token_u3a = generate_from_device_data(device_data, token_type=ADD_TIME, value_days=1)
94-
device_data, token_u3b = generate_from_device_data(device_data, token_type=ADD_TIME, value_raw=DISABLE_VALUE)
95-
test_how_many_days_validator(device_simulator, 'U3A', token_u3b, None, description=test)
96-
test_how_many_days_validator(device_simulator, 'U3B', token_u3a, None, accepted_but_used=True)
169+
test = (
170+
"We generate 3 Add Time tokens, then enter the 3rd, then first, then "
171+
"second and ensure the days are added properly"
172+
)
173+
device_data, token_u1a = generate_from_device_data(
174+
device_data, token_type=SET_TIME, value_days=60
175+
)
176+
test_how_many_days_validator(
177+
device_simulator, "U1A", token_u1a, 60, description=test
178+
)
179+
device_data, token_u1b = generate_from_device_data(
180+
device_data, token_type=ADD_TIME, value_days=10
181+
)
182+
device_data, token_u1c = generate_from_device_data(
183+
device_data, token_type=ADD_TIME, value_days=5
184+
)
185+
device_data, token_u1d = generate_from_device_data(
186+
device_data, token_type=ADD_TIME, value_days=1
187+
)
188+
test_how_many_days_validator(device_simulator, "U1B", token_u1d, 61)
189+
test_how_many_days_validator(device_simulator, "U1C", token_u1b, 71)
190+
test_how_many_days_validator(device_simulator, "U1D", token_u1c, 76)
191+
192+
test = (
193+
"We generate an Add Time, a Set Time and another Add Time token. We "
194+
"enter the set time and ensure that the older Add Time does not work "
195+
"but the newer does"
196+
)
197+
device_data, token_u2a = generate_from_device_data(
198+
device_data, token_type=ADD_TIME, value_days=5
199+
)
200+
device_data, token_u2b = generate_from_device_data(
201+
device_data, token_type=SET_TIME, value_days=10
202+
)
203+
device_data, token_u2c = generate_from_device_data(
204+
device_data, token_type=ADD_TIME, value_days=3
205+
)
206+
test_how_many_days_validator(
207+
device_simulator, "U2A", token_u2b, 10, description=test
208+
)
209+
test_how_many_days_validator(
210+
device_simulator, "U2B", token_u2a, 10, accepted_but_used=True
211+
)
212+
test_how_many_days_validator(device_simulator, "U2C", token_u2c, 13)
213+
214+
test = (
215+
"We generate an Add Time token and a Disable PAYG token, we enter the "
216+
"Disable PAYG token and then the Add Time token should be refused"
217+
)
218+
device_data, token_u3a = generate_from_device_data(
219+
device_data, token_type=ADD_TIME, value_days=1
220+
)
221+
device_data, token_u3b = generate_from_device_data(
222+
device_data, token_type=ADD_TIME, value_raw=DISABLE_VALUE
223+
)
224+
test_how_many_days_validator(
225+
device_simulator, "U3A", token_u3b, None, description=test
226+
)
227+
test_how_many_days_validator(
228+
device_simulator, "U3B", token_u3a, None, accepted_but_used=True
229+
)
97230

98231
return device_data
99232

100233

101-
102-
103-
if __name__ == '__main__':
234+
if __name__ == "__main__":
104235
device_data = {
105-
'serial_number': 'XXX',
106-
'starting_code': 516959010,
107-
'key': 'bc41ec9530f6dac86b1a29ab82edc5fb',
108-
'restricted_digit_set': False,
109-
'time_divider': 1,
110-
'token_count': 1
236+
"serial_number": "XXX",
237+
"starting_code": 516959010,
238+
"key": "bc41ec9530f6dac86b1a29ab82edc5fb",
239+
"restricted_digit_set": False,
240+
"time_divider": 1,
241+
"token_count": 1,
111242
}
112-
device_simulator = DeviceSimulator(device_data['starting_code'], codecs.decode(device_data['key'], 'hex'),
113-
restricted_digit_set=device_data['restricted_digit_set'],
114-
waiting_period_enabled=False)
243+
device_simulator = DeviceSimulator(
244+
device_data["starting_code"],
245+
codecs.decode(device_data["key"], "hex"),
246+
restricted_digit_set=device_data["restricted_digit_set"],
247+
waiting_period_enabled=False,
248+
)
115249
device_data = run_core_token_tests(device_data, device_simulator)
116250
device_data = run_unordered_entry_tests(device_data, device_simulator)

0 commit comments

Comments
 (0)