# Initially Generated by CodiumAI

# Dependencies:
# pip install pytest-mock
import pytest

from pyadtpulse.alarm_panel import ADT_ALARM_AWAY, ADTPulseAlarmPanel


class TestADTPulseAlarmPanel:
    # ADTPulseAlarmPanel object is created with default values

    # ADTPulseAlarmPanel attributes are set correctly
    def test_set_attributes(self):
        alarm_panel = ADTPulseAlarmPanel()
        alarm_attributes = {
            "type_model": "Model",
            "manufacturer_provider": "Manufacturer",
            "status": "Online",
        }
        alarm_panel.set_alarm_attributes(alarm_attributes)
        assert alarm_panel.model == "Model"
        assert alarm_panel.manufacturer == "Manufacturer"
        assert alarm_panel.online == True

    # ADTPulseAlarmPanel is able to handle connection errors
    @pytest.mark.asyncio
    async def test_handle_connection_errors(self, mocker):
        # Mock ADTPulseConnection
        mock_connection = mocker.Mock()
        mock_connection.async_query.side_effect = ConnectionError

        # Create ADTPulseAlarmPanel instance
        alarm_panel = ADTPulseAlarmPanel()

        # Call the method that should handle connection errors
        result = await alarm_panel._arm(mock_connection, ADT_ALARM_AWAY, False)

        # Verify that the method returns False
        assert result == False

    # ADTPulseAlarmPanel is able to handle timeouts
    @pytest.mark.asyncio
    async def test_handle_timeouts(self, mocker):
        # Mock ADTPulseConnection
        mock_connection = mocker.Mock()
        mock_connection.async_query.side_effect = TimeoutError

        # Create ADTPulseAlarmPanel instance
        alarm_panel = ADTPulseAlarmPanel()

        # Call the method that should handle timeouts
        result = await alarm_panel._arm(mock_connection, ADT_ALARM_AWAY, False)

        # Verify that the method returns False
        assert result == False

    # ADTPulseAlarmPanel is able to handle unexpected HTML soup
    @pytest.mark.asyncio
    async def test_handle_unexpected_html_soup(self, mocker):
        # Mock ADTPulseConnection
        mock_connection = mocker.Mock()
        mock_connection.async_query.return_value = '<html><body><div class="p_armDisarmWrapper"><div>Error</div></div></body></html>'

        # Create ADTPulseAlarmPanel instance
        alarm_panel = ADTPulseAlarmPanel()

        # Call the method that should handle unexpected HTML soup
        result = await alarm_panel._arm(mock_connection, ADT_ALARM_AWAY, False)

        # Verify that the method returns False
        assert result == False
