def test_base_model_send_commands_flush_list(mocker): """ Ensure that after a send() call, the commands list is empty """ # create a CashRegister with a mocked connection mocked_serial = mocker.Mock() register = CashRegister('Sarema X2', connection=mocked_serial) # add some commands register._commands = ['K', '1H1R', '1T'] # send commands register.send() assert len(register._commands) == 0
def test_base_model_send_empty_commands(mocker): """ Test that no connection is opened if the commands list is empty """ # create a CashRegister with a mocked connection mocked_serial = mocker.Mock() register = CashRegister('Sarema X2', connection=mocked_serial) # send commands register.send() assert register._connection.open.call_count == 0 assert register._connection.write.call_count == 0 assert register._connection.flush.call_count == 0 assert register._connection.close.call_count == 0
def test_base_model_send_commands(mocker): """ Test that a connection is opened and that all commands are sent through the connection object """ # create a CashRegister with a mocked connection mocked_serial = mocker.Mock() register = CashRegister('Sarema X2', connection=mocked_serial) # add some commands register._commands = ['K', '1H1R', '1T'] # send commands register.send() assert register._connection.open.call_count == 1 assert register._connection.write.call_count == 3 assert register._connection.flush.call_count == 1 assert register._connection.close.call_count == 1