Beispiel #1
0
    def tests_camera_no_image_update(self, m):
        """Tests that camera updates correctly with no timeline events."""
        # Set up URL's
        m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok())
        m.post(CONST.LOGOUT_URL, text=LOGOUT.post_response_ok())
        m.get(CONST.PANEL_URL,
              text=PANEL.get_response_ok(mode=CONST.MODE_STANDBY))
        m.get(CONST.DEVICES_URL,
              text=IRCAMERA.device(devid=IRCAMERA.DEVICE_ID,
                                   status=CONST.STATUS_ONLINE,
                                   low_battery=False,
                                   no_response=False))

        # Logout to reset everything
        self.abode.logout()

        # Get our camera
        device = self.abode.get_device(IRCAMERA.DEVICE_ID)

        # Test that we have our device
        self.assertIsNotNone(device)
        self.assertEqual(device.status, CONST.STATUS_ONLINE)

        # Set up timeline response
        url = str.replace(CONST.TIMELINE_IMAGES_ID_URL, '$DEVID$',
                          IRCAMERA.DEVICE_ID)
        m.get(url, text='[]')

        # Refresh the image
        self.assertFalse(device.refresh_image())
        self.assertIsNone(device.image_url)
Beispiel #2
0
    def tests_camera_image_write(self, m):
        """Tests that camera images will write to a file."""
        # Set up URL's
        m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok())
        m.get(CONST.OAUTH_TOKEN_URL, text=OAUTH_CLAIMS.get_response_ok())
        m.post(CONST.LOGOUT_URL, text=LOGOUT.post_response_ok())
        m.get(CONST.PANEL_URL,
              text=PANEL.get_response_ok(mode=CONST.MODE_STANDBY))
        m.get(CONST.DEVICES_URL,
              text=IRCAMERA.device(devid=IRCAMERA.DEVICE_ID,
                                   status=CONST.STATUS_ONLINE,
                                   low_battery=False,
                                   no_response=False))

        # Logout to reset everything
        self.abode.logout()

        # Get our camera
        device = self.abode.get_device(IRCAMERA.DEVICE_ID)

        # Test that we have our device
        self.assertIsNotNone(device)
        self.assertEqual(device.status, CONST.STATUS_ONLINE)

        # Set up timeline response
        url = str.replace(CONST.TIMELINE_IMAGES_ID_URL, '$DEVID$',
                          IRCAMERA.DEVICE_ID)
        m.get(url,
              text='[' + IRCAMERA.timeline_event(IRCAMERA.DEVICE_ID) + ']')

        # Set up our file path response
        file_path = CONST.BASE_URL + IRCAMERA.FILE_PATH
        m.head(file_path,
               status_code=302,
               headers={'Location': IRCAMERA.LOCATION_HEADER})

        # Set up our image response
        image_response = "this is a beautiful jpeg image"
        m.get(IRCAMERA.LOCATION_HEADER, text=image_response)

        # Refresh the image
        path = "test.jpg"
        self.assertTrue(device.image_to_file(path, get_image=True))

        # Test the file written and cleanup
        image_data = open(path, 'r').read()
        self.assertTrue(image_response, image_data)
        os.remove(path)

        # Test that bad response returns False
        m.get(IRCAMERA.LOCATION_HEADER, status_code=400)
        with self.assertRaises(abodepy.AbodeException):
            device.image_to_file(path, get_image=True)

        # Test that the image fails to update returns False
        m.get(url, text='[]')
        self.assertFalse(device.image_to_file(path, get_image=True))
Beispiel #3
0
    def tests_camera_properties(self, m):
        """Tests that camera properties work as expected."""
        # Set up URL's
        m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok())
        m.get(CONST.OAUTH_TOKEN_URL, text=OAUTH_CLAIMS.get_response_ok())
        m.post(CONST.LOGOUT_URL, text=LOGOUT.post_response_ok())
        m.get(CONST.PANEL_URL,
              text=PANEL.get_response_ok(mode=CONST.MODE_STANDBY))
        m.get(CONST.DEVICES_URL,
              text=IRCAMERA.device(devid=IRCAMERA.DEVICE_ID,
                                   status=CONST.STATUS_ONLINE,
                                   low_battery=False,
                                   no_response=False))

        # Logout to reset everything
        self.abode.logout()

        # Get our camera
        device = self.abode.get_device(IRCAMERA.DEVICE_ID)

        # Test our device
        self.assertIsNotNone(device)
        self.assertEqual(device.status, CONST.STATUS_ONLINE)
        self.assertFalse(device.battery_low)
        self.assertFalse(device.no_response)

        # Set up our direct device get url
        device_url = str.replace(CONST.DEVICE_URL, '$DEVID$',
                                 IRCAMERA.DEVICE_ID)

        # Change device properties
        m.get(device_url,
              text=IRCAMERA.device(devid=IRCAMERA.DEVICE_ID,
                                   status=CONST.STATUS_OFFLINE,
                                   low_battery=True,
                                   no_response=True))

        # Refesh device and test changes
        device.refresh()

        self.assertEqual(device.status, CONST.STATUS_OFFLINE)
        self.assertTrue(device.battery_low)
        self.assertTrue(device.no_response)
Beispiel #4
0
    def setUp(self):
        """Set up Abode module."""
        self.abode = abodepy.Abode(username=USERNAME,
                                   password=PASSWORD,
                                   disable_cache=True)

        self.all_devices = ("[" + IRCAMERA.device(
            devid=IRCAMERA.DEVICE_ID,
            status=CONST.STATUS_ONLINE,
            low_battery=False,
            no_response=False,
        ) + "," + IPCAM.device(
            devid=IPCAM.DEVICE_ID,
            status=CONST.STATUS_ONLINE,
            low_battery=False,
            no_response=False,
        ) + "]")

        # Logout to reset everything
        self.abode.logout()
Beispiel #5
0
    def tests_camera_capture(self, m):
        """Tests that camera devices capture new images."""
        # Set up URL's
        m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok())
        m.get(CONST.OAUTH_TOKEN_URL, text=OAUTH_CLAIMS.get_response_ok())
        m.post(CONST.LOGOUT_URL, text=LOGOUT.post_response_ok())
        m.get(CONST.PANEL_URL,
              text=PANEL.get_response_ok(mode=CONST.MODE_STANDBY))
        m.get(CONST.DEVICES_URL,
              text=IRCAMERA.device(devid=IRCAMERA.DEVICE_ID,
                                   status=CONST.STATUS_ONLINE,
                                   low_battery=False,
                                   no_response=False))

        # Logout to reset everything
        self.abode.logout()

        # Get our camera
        device = self.abode.get_device(IRCAMERA.DEVICE_ID)

        # Test that we have our device
        self.assertIsNotNone(device)
        self.assertEqual(device.status, CONST.STATUS_ONLINE)

        # Set up capture url response
        url = str.replace(CONST.CAMS_ID_CAPTURE_URL, '$DEVID$',
                          IRCAMERA.DEVICE_ID)
        m.put(url, text=MOCK.generic_response_ok())

        # Capture the image
        self.assertTrue(device.capture())

        # Change response
        m.put(url, text=IRCAMERA.get_capture_timeout(), status_code=600)

        # Capture the image with failure
        self.assertFalse(device.capture())
Beispiel #6
0
    def tests_all_devices(self, m):
        """Tests that all mocked devices are mapped correctly."""
        # Set up URL's
        m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok())
        m.get(CONST.OAUTH_TOKEN_URL, text=OAUTH_CLAIMS.get_response_ok())
        m.post(CONST.LOGOUT_URL, text=LOGOUT.post_response_ok())
        m.get(CONST.PANEL_URL,
              text=PANEL.get_response_ok(mode=CONST.MODE_STANDBY))

        # Create all devices
        all_devices = '[' + \
            DOOR_CONTACT.device() + ',' + \
            DOOR_LOCK.device() + ',' + \
            GLASS.device() + ',' + \
            IR_CAMERA.device() + ',' + \
            KEYPAD.device() + ',' + \
            PIR.device() + ',' + \
            POWERMETER.device() + ',' + \
            POWERSENSOR.device() + ',' + \
            REMOTE_CONTROLLER.device() + ',' + \
            SECUREBARRIER.device() + ',' + \
            SIREN.device() + ',' + \
            STATUS_DISPLAY.device() + ',' + \
            WATER_SENSOR.device() + ']'

        m.get(CONST.DEVICES_URL, text=all_devices)

        # Logout to reset everything
        self.abode.logout()

        # Loop through all devices
        for device in self.abode.get_devices():
            class_type = {
                # Alarm
                CONST.TYPE_ALARM: AbodeAlarm,

                # Binary Sensors
                CONST.TYPE_CONNECTIVITY: AbodeBinarySensor,
                CONST.TYPE_MOISTURE: AbodeBinarySensor,
                CONST.TYPE_OPENING: AbodeBinarySensor,
                CONST.TYPE_MOTION: AbodeBinarySensor,
                CONST.TYPE_OCCUPANCY: AbodeBinarySensor,

                # Camera
                CONST.TYPE_CAMERA: AbodeDevice,

                # Cover
                CONST.TYPE_COVER: AbodeCover,

                # Dimmer
                CONST.TYPE_LIGHT: AbodeLight,

                # Lock
                CONST.TYPE_LOCK: AbodeLock,

                # Switch
                CONST.TYPE_SWITCH: AbodeSwitch
            }.get(device.generic_type)

            self.assertIsNotNone(class_type, device.type + ' is not mapped.')
            self.assertTrue(
                isinstance(device, class_type), device.type + ' is of class ' +
                str(device.__class__.__name__) + ' but mapped to ' +
                str(class_type.__name__))
Beispiel #7
0
    def tests_camera_image_update(self, m):
        """Tests that camera devices update correctly via timeline request."""
        # Set up URL's
        m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok())
        m.post(CONST.LOGOUT_URL, text=LOGOUT.post_response_ok())
        m.get(CONST.PANEL_URL,
              text=PANEL.get_response_ok(mode=CONST.MODE_STANDBY))
        m.get(CONST.DEVICES_URL,
              text=IRCAMERA.device(devid=IRCAMERA.DEVICE_ID,
                                   status=CONST.STATUS_ONLINE,
                                   low_battery=False,
                                   no_response=False))

        # Logout to reset everything
        self.abode.logout()

        # Get our camera
        device = self.abode.get_device(IRCAMERA.DEVICE_ID)

        # Test that we have our device
        self.assertIsNotNone(device)
        self.assertEqual(device.status, CONST.STATUS_ONLINE)

        # Set up timeline response
        url = str.replace(CONST.TIMELINE_IMAGES_ID_URL, '$DEVID$',
                          IRCAMERA.DEVICE_ID)
        m.get(url,
              text='[' + IRCAMERA.timeline_event(IRCAMERA.DEVICE_ID) + ']')

        # Set up our file path response
        file_path = CONST.BASE_URL + IRCAMERA.FILE_PATH
        m.head(file_path,
               status_code=302,
               headers={'Location': IRCAMERA.LOCATION_HEADER})

        # Refresh the image
        self.assertTrue(device.refresh_image())

        # Verify the image location
        self.assertEqual(device.image_url, IRCAMERA.LOCATION_HEADER)

        # Test that a bad file_path response header results in an exception
        file_path = CONST.BASE_URL + IRCAMERA.FILE_PATH
        m.head(file_path, status_code=302)

        with self.assertRaises(abodepy.AbodeException):
            device.refresh_image()

        # Test that a bad file_path response code results in an exception
        file_path = CONST.BASE_URL + IRCAMERA.FILE_PATH
        m.head(file_path,
               status_code=200,
               headers={'Location': IRCAMERA.LOCATION_HEADER})

        with self.assertRaises(abodepy.AbodeException):
            device.refresh_image()

        # Test that an an empty timeline event throws exception
        url = str.replace(CONST.TIMELINE_IMAGES_ID_URL, '$DEVID$',
                          IRCAMERA.DEVICE_ID)
        m.get(url,
              text='[' +
              IRCAMERA.timeline_event(IRCAMERA.DEVICE_ID, file_path='') + ']')

        with self.assertRaises(abodepy.AbodeException):
            device.refresh_image()

        # Test that an unexpected timeline event throws exception
        url = str.replace(CONST.TIMELINE_IMAGES_ID_URL, '$DEVID$',
                          IRCAMERA.DEVICE_ID)
        m.get(url,
              text='[' +
              IRCAMERA.timeline_event(IRCAMERA.DEVICE_ID, event_code='1234') +
              ']')

        with self.assertRaises(abodepy.AbodeException):
            device.refresh_image()