예제 #1
0
    def tests_request_zeep_error(self):
        """Test a Zeep error."""

        serialize_responses = [
            ZeepFault("test") for x in range(MAX_RETRY_ATTEMPTS)
        ]
        with patch("zeep.Client"), patch("time.sleep", autospec=True), patch(
                "zeep.helpers.serialize_object",
                side_effect=serialize_responses
        ) as mock_request, pytest.raises(ServiceUnavailable):
            client = TotalConnectClient("username",
                                        "password",
                                        usercodes=None,
                                        retry_delay=0)
            assert mock_request.call_count == MAX_RETRY_ATTEMPTS
            assert client.is_logged_in() is False
예제 #2
0
    def tests_request_init_failed_to_connect(self):
        """Test init sequence when it fails to connect."""
        serialize_responses = [
            RESPONSE_FAILED_TO_CONNECT for x in range(MAX_RETRY_ATTEMPTS)
        ]

        with patch("zeep.Client"), patch("time.sleep", autospec=True), patch(
                PATCH_EVAL, side_effect=serialize_responses
        ) as mock_request, pytest.raises(Exception) as exc:
            client = TotalConnectClient("username",
                                        "password",
                                        usercodes=None,
                                        retry_delay=0)
            assert mock_request.call_count == MAX_RETRY_ATTEMPTS
            assert client.is_logged_in() is False
            expected = "total-connect-client could not execute request.  Maximum attempts tried."
            assert str(exc.value) == expected
예제 #3
0
    def tests_request_init(self):
        """Test normal init sequence with no problems."""
        serialize_responses = [
            RESPONSE_AUTHENTICATE,
            RESPONSE_PARTITION_DETAILS,
            RESPONSE_GET_ZONE_DETAILS_SUCCESS,
            RESPONSE_DISARMED,
        ]

        with patch("zeep.Client"), patch(
                PATCH_EVAL, side_effect=serialize_responses) as mock_request:
            client = TotalConnectClient("username", "password", usercodes=None)
            assert mock_request.call_count == 1
            if client.locations:  # force client to fetch them
                pass
            assert mock_request.call_count == 4
            assert client.is_logged_in() is True
예제 #4
0
    def tests_request_connection_error(self):
        """Test a connection error."""
        serialize_responses = [
            RESPONSE_CONNECTION_ERROR for x in range(MAX_RETRY_ATTEMPTS)
        ]

        with patch("zeep.Client"), patch("time.sleep", autospec=True), patch(
                "zeep.helpers.serialize_object",
                side_effect=serialize_responses
        ) as mock_request, pytest.raises(Exception) as exc:
            client = TotalConnectClient("username",
                                        "password",
                                        usercodes=None,
                                        retry_delay=0)
            assert mock_request.call_count == MAX_RETRY_ATTEMPTS
            assert client.is_logged_in() is False
            expected = "total-connect-client could not execute request.  Maximum attempts tried."
            assert str(exc.value) == expected
예제 #5
0
    def tests_request_unknown_result_code(self):
        """Test an unknown result code."""
        serialize_responses = [
            RESPONSE_UNKNOWN,
        ]

        with patch("zeep.Client"), patch(
                PATCH_EVAL, side_effect=serialize_responses) as mock_request:
            with pytest.raises(BadResultCodeError):
                TotalConnectClient("username", "password", usercodes=None)
            assert mock_request.call_count == 1
def tests_init_partitions():
    """Test that partitions populate correctly."""
    # one partition
    responses = [
        RESPONSE_AUTHENTICATE,
        RESPONSE_PARTITION_DETAILS,
        RESPONSE_GET_ZONE_DETAILS_SUCCESS,
        RESPONSE_DISARMED,
    ]

    with patch("total_connect_client.client.TotalConnectClient.request",
               side_effect=responses) as mock_request:
        mock_client = TotalConnectClient("username",
                                         "password",
                                         usercodes=None)
        assert mock_request.call_count == 1
        if mock_client.locations:  # force client to fetch them
            pass
        assert mock_request.call_count == 4

        assert len(mock_client.locations["123456"].partitions) == 1

    # two partitions
    responses = [
        RESPONSE_AUTHENTICATE,
        RESPONSE_PARTITION_DETAILS_TWO,
        RESPONSE_GET_ZONE_DETAILS_SUCCESS,
        RESPONSE_DISARMED,
    ]

    with patch("total_connect_client.client.TotalConnectClient.request",
               side_effect=responses) as mock_request:
        mock_client = TotalConnectClient("username",
                                         "password",
                                         usercodes=None)
        assert mock_request.call_count == 1
        if mock_client.locations:  # force client to fetch them
            pass
        assert mock_request.call_count == 4

        assert len(mock_client.locations["123456"].partitions) == 2
예제 #7
0
    def tests_request_init_bad_user_or_password(self):
        """Test init sequence with no a bad password."""
        serialize_responses = [
            RESPONSE_BAD_USER_OR_PASSWORD,
        ]

        with patch("zeep.Client"), patch(
                "zeep.helpers.serialize_object",
                side_effect=serialize_responses) as mock_request:
            with pytest.raises(AuthenticationError):
                TotalConnectClient("username", "password", usercodes=None)
            assert mock_request.call_count == 1
def tests_init_usercodes_string():
    """Test init with usercodes == a string."""
    responses = [
        RESPONSE_AUTHENTICATE,
        RESPONSE_PARTITION_DETAILS,
        RESPONSE_GET_ZONE_DETAILS_SUCCESS,
        RESPONSE_DISARMED,
    ]

    with patch("total_connect_client.client.TotalConnectClient.request",
               side_effect=responses):
        with pytest.raises(AttributeError):
            # string is not a valid type for usercodes (only dict)
            TotalConnectClient("username", "password", usercodes="123456")
def tests_init_locations_empty():
    """Test init with no locations."""
    responses = [
        RESPONSE_AUTHENTICATE_EMPTY,
    ]

    with patch("total_connect_client.client.TotalConnectClient.request",
               side_effect=responses) as mock_request, pytest.raises(
                   TotalConnectError):

        mock_client = TotalConnectClient("username",
                                         "password",
                                         usercodes=None)
        assert mock_client.locations == {}
        assert mock_request.call_count == 1
예제 #10
0
    def tests_request_invalid_session(self):
        """Test an invalid session, which is when the session times out."""
        # First three responses set up 'normal' session
        # Call to client.arm_away() will first get an invalid session,
        # which will trigger client.authenticate() before completing the arm_away()
        serialize_responses = [
            RESPONSE_AUTHENTICATE,
            RESPONSE_PARTITION_DETAILS,
            RESPONSE_GET_ZONE_DETAILS_SUCCESS,
            RESPONSE_DISARMED,
            RESPONSE_INVALID_SESSION,
            RESPONSE_SESSION_INITIATED,
            RESPONSE_ARMED_AWAY,
        ]

        with patch("zeep.Client"), patch(
                PATCH_EVAL, side_effect=serialize_responses) as mock_request:
            client = TotalConnectClient("username", "password", usercodes=None)
            assert mock_request.call_count == 1
            if client.locations:  # force client to fetch them
                pass
            assert mock_request.call_count == 4
            assert client.is_logged_in() is True
            assert mock_request.call_count == 4
예제 #11
0
def create_client():
    """Return a TotalConnectClient that appears to be logged in."""
    responses = [
        RESPONSE_AUTHENTICATE,
        RESPONSE_PARTITION_DETAILS,
        RESPONSE_GET_ZONE_DETAILS_SUCCESS,
        RESPONSE_DISARMED,
    ]

    with patch("total_connect_client.client.TotalConnectClient.request",
               side_effect=responses) as mock_request:
        mock_client = TotalConnectClient("username", "password",
                                         {"123456": "1234"})
        assert mock_request.call_count == 1
        if mock_client.locations:  # force client to fetch them
            pass
        assert mock_request.call_count == 4

    return mock_client
def tests_init_usercodes_none():
    """Test init with usercodes == None."""
    responses = [
        RESPONSE_AUTHENTICATE,
        RESPONSE_PARTITION_DETAILS,
        RESPONSE_GET_ZONE_DETAILS_SUCCESS,
        RESPONSE_DISARMED,
    ]

    with patch("total_connect_client.client.TotalConnectClient.request",
               side_effect=responses) as mock_request:
        mock_client = TotalConnectClient("username",
                                         "password",
                                         usercodes=None)
        assert mock_request.call_count == 1
        if mock_client.locations:  # force client to fetch them
            pass
        assert mock_request.call_count == 4

    assert not mock_client.usercodes
예제 #13
0
import logging
import sys
from pprint import pprint

from total_connect_client.client import TotalConnectClient

logging.basicConfig(filename="test.log", level=logging.DEBUG)

if len(sys.argv) != 3:
    print("usage:  username password\n")
    sys.exit()

USERNAME = sys.argv[1]
PASSWORD = sys.argv[2]

TC = TotalConnectClient(USERNAME, PASSWORD)

location_id = next(iter(TC.locations))

print("auto_bypass_low_battery: " + str(TC.auto_bypass_low_battery))

print("\n\n\n")

print("--- panel meta data ---")
meta_data = TC.get_panel_meta_data(location_id)
pprint(meta_data)

print("\n\n\n")

print(TC.locations[location_id])
예제 #14
0
logging.basicConfig(filename="test.log", level=logging.DEBUG)

if len(sys.argv) != 7:
    print(
        "usage:  username password AutomationDeviceID DeviceID DeviceTypeID LocationID\n"
    )
    sys.exit()

USERNAME = sys.argv[1]
PASSWORD = sys.argv[2]
AUTOMATION_DEVICE = sys.argv[3]
DEVICE_ID = sys.argv[4]
TYPE = sys.argv[5]
LOCATION = sys.argv[6]

TC = TotalConnectClient(USERNAME, PASSWORD)

print("\n\n\nGetAutomationDeviceStatus\n\n\n")
result = TC.request(
    f"GetAutomationDeviceStatus(self.token, {AUTOMATION_DEVICE})")

pprint(result)

print("\n\n\nGetAutomationDeviceStatusExV1\n\n\n")
result = TC.request(
    f"GetAutomationDeviceStatusExV1(self.token, {AUTOMATION_DEVICE})")

pprint(result)

print("\n\n\nGetAllAutomationDeviceStatusExV1\n\n\n")
result = TC.request(
예제 #15
0
"""Test your system from the command line."""

import getpass
import logging
import sys

from total_connect_client.client import TotalConnectClient

logging.basicConfig(filename="test.log", level=logging.DEBUG)

if len(sys.argv) != 3:
    print("usage:  username location1=usercode1,location2=usercode2 \n")
    sys.exit()

USERNAME = sys.argv[1]
USERCODES = dict(x.split("=") for x in sys.argv[2].split(","))
PASSWORD = getpass.getpass()

TC = TotalConnectClient(USERNAME, PASSWORD, USERCODES)

for location_id in TC.locations:
    TC.locations[location_id].disarm()

print("Disarmed.")

sys.exit()
"""Test your system from the command line."""

import getpass
import logging
import sys

from total_connect_client.client import TotalConnectClient

logging.basicConfig(filename="test.log", level=logging.DEBUG)

if len(sys.argv) < 2 or len(sys.argv) > 3:
    print("usage:  python3 -m total_connect_client username [password]\n")
    sys.exit(1)

USERNAME = sys.argv[1]
if len(sys.argv) == 2:
    PASSWORD = getpass.getpass()
else:
    PASSWORD = sys.argv[2]

TC = TotalConnectClient(USERNAME, PASSWORD)

print(TC)