The inputs are /start, /led on, /led off, /led invalid, and /unknown. The initial LED state is off.
Procedure
Write handle(text,state) to return the new state and a response message.
Process the input list in order and record the state before and after each step.
For invalid arguments and unknown commands, preserve the state and return usage instructions.
Results to retain
A 5-row state transition table and a function.
Items to record and points to check
Input
Previous state
Next state
Response
Points to check
Can you check it through function calls without sending real messages?
Does the LED state remain unchanged for invalid and unknown?
2. Repeated commands and whitespace
Starting conditions
Repeat /led on three times, and add " /led off " with leading and trailing spaces.
Procedure
Check whether repeated commands preserve the state.
Define rules for strip and case handling, then compare with the original function.
Also choose two inputs to reject, and check that the state is preserved.
Results to retain
A table with at least 6 inputs and 3 asserts.
Items to record and points to check
Input
Normalization result
State
Accepted
Points to check
Did you apply consistent command normalization rules across inputs?
Does repeated on avoid behaving like a toggle that reverses the state?
3. Separate transport from device logic
Read Week14-2_Telegram_Bot_Command_Handler.py and handle and dispatch in this notebook, and map each role to its function or line in the table. Mark roles absent from the original as 'None' and distinguish them from the test implementation.
Use the provided outbox log instead of sending real messages.
Starting conditions
Organize inputs from the web, messengers, and MQTT as {request_id,device,command}. Do not execute the same request_id again.
Procedure
Validate the request ID, device, and command, then pass them to the common handler function.
Handle the same request sent twice so that the state changes only once.
Record the response and actual state, and draw the request–handling–response flow.
Results to retain
A role mapping table and 3 rows of simulated transmission logs.
Items to record and points to check
Role
Original function and location
Test substitute
Observed results
Points to check
Can you test the same handling logic without a token?
Did you check state updates and external transmission independently?