Ejemplo n.º 1
0
    def tests_activities(self, m):
        """Check that the Skybell device activities work."""
        m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok())

        # Set up device
        device_text = '[' + DEVICE.get_response_ok() + ']'

        avatar_text = DEVICE_AVATAR.get_response_ok()
        avatar_url = str.replace(CONST.DEVICE_AVATAR_URL,
                                 '$DEVID$', DEVICE.DEVID)

        info_text = DEVICE_INFO.get_response_ok()
        info_url = str.replace(CONST.DEVICE_INFO_URL, '$DEVID$', DEVICE.DEVID)

        settings_text = DEVICE_SETTINGS.get_response_ok()
        settings_url = str.replace(CONST.DEVICE_SETTINGS_URL,
                                   '$DEVID$', DEVICE.DEVID)

        activities_text = '[' + \
                          DEVICE_ACTIVITIES.get_response_ok(
                              dev_id=DEVICE.DEVID,
                              event=CONST.EVENT_BUTTON) + ',' + \
                          DEVICE_ACTIVITIES.get_response_ok(
                              dev_id=DEVICE.DEVID,
                              event=CONST.EVENT_MOTION) + ',' + \
                          DEVICE_ACTIVITIES.get_response_ok(
                              dev_id=DEVICE.DEVID,
                              event=CONST.EVENT_ON_DEMAND) + ']'
        activities_json = json.loads(activities_text)

        activities_url = str.replace(CONST.DEVICE_ACTIVITIES_URL,
                                     '$DEVID$', DEVICE.DEVID)

        m.get(CONST.DEVICES_URL, text=device_text)
        m.get(avatar_url, text=avatar_text)
        m.get(info_url, text=info_text)
        m.get(settings_url, text=settings_text)
        m.get(activities_url, text=activities_text)

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

        # Get our specific device
        device = self.skybell.get_device(DEVICE.DEVID)
        self.assertIsNotNone(device)
        # pylint: disable=W0212
        self.assertEqual(device._activities, activities_json)

        # Get all activities from device
        activities = device.activities(limit=100)
        self.assertIsNotNone(activities)
        self.assertEqual(len(activities), 3)

        # Get only button activities
        activities = device.activities(event=CONST.EVENT_BUTTON)
        self.assertIsNotNone(activities)
        self.assertEqual(len(activities), 1)
        self.assertEqual(activities[0][CONST.EVENT], CONST.EVENT_BUTTON)
Ejemplo n.º 2
0
    def tests_latest_event(self, m):
        """Check that the latest event is always obtained."""
        m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok())

        # Set up device
        device_text = '[' + DEVICE.get_response_ok() + ']'

        avatar_text = DEVICE_AVATAR.get_response_ok()
        avatar_url = str.replace(CONST.DEVICE_AVATAR_URL,
                                 '$DEVID$', DEVICE.DEVID)

        info_text = DEVICE_INFO.get_response_ok()
        info_url = str.replace(CONST.DEVICE_INFO_URL, '$DEVID$', DEVICE.DEVID)

        settings_text = DEVICE_SETTINGS.get_response_ok()
        settings_url = str.replace(CONST.DEVICE_SETTINGS_URL,
                                   '$DEVID$', DEVICE.DEVID)

        activity_1 = DEVICE_ACTIVITIES.get_response_ok(
            dev_id=DEVICE.DEVID,
            event=CONST.EVENT_BUTTON,
            state='alpha',
            created_at=datetime.datetime(2017, 1, 1, 0, 0, 0))

        activity_2 = DEVICE_ACTIVITIES.get_response_ok(
            dev_id=DEVICE.DEVID,
            event=CONST.EVENT_BUTTON,
            state='beta',
            created_at=datetime.datetime(2017, 1, 1, 0, 0, 1))

        activities_text = '[' + activity_1 + ',' + activity_2 + ']'

        activities_url = str.replace(CONST.DEVICE_ACTIVITIES_URL,
                                     '$DEVID$', DEVICE.DEVID)

        m.get(CONST.DEVICES_URL, text=device_text)
        m.get(avatar_url, text=avatar_text)
        m.get(info_url, text=info_text)
        m.get(settings_url, text=settings_text)
        m.get(activities_url, text=activities_text)

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

        # Get our specific device
        device = self.skybell.get_device(DEVICE.DEVID)
        self.assertIsNotNone(device)

        # Get latest button event
        event = device.latest(CONST.EVENT_BUTTON)

        # Test
        self.assertIsNotNone(event)
        self.assertEqual(event.get(CONST.STATE), 'beta')
Ejemplo n.º 3
0
    def tests_bad_activities(self, m):
        """Check that device activities recovers from bad data."""
        m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok())

        # Set up device
        device_text = '[' + DEVICE.get_response_ok() + ']'

        avatar_text = DEVICE_AVATAR.get_response_ok()
        avatar_url = str.replace(CONST.DEVICE_AVATAR_URL,
                                 '$DEVID$', DEVICE.DEVID)

        info_text = DEVICE_INFO.get_response_ok()
        info_url = str.replace(CONST.DEVICE_INFO_URL, '$DEVID$', DEVICE.DEVID)

        settings_text = DEVICE_SETTINGS.get_response_ok()
        settings_url = str.replace(CONST.DEVICE_SETTINGS_URL,
                                   '$DEVID$', DEVICE.DEVID)

        activities_text = DEVICE_ACTIVITIES.get_response_ok(
            dev_id=DEVICE.DEVID,
            event=CONST.EVENT_BUTTON)

        activities_url = str.replace(CONST.DEVICE_ACTIVITIES_URL,
                                     '$DEVID$', DEVICE.DEVID)

        m.get(CONST.DEVICES_URL, text=device_text)
        m.get(avatar_url, text=avatar_text)
        m.get(info_url, text=info_text)
        m.get(settings_url, text=settings_text)
        m.get(activities_url, text=activities_text)

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

        # Get our specific device
        device = self.skybell.get_device(DEVICE.DEVID)
        self.assertIsNotNone(device)

        # Get all activities from device
        activities = device.activities(limit=100)
        self.assertIsNotNone(activities)
        self.assertEqual(len(activities), 1)

        # Force our device variable empty
        # pylint: disable=W0212
        device._activities = None

        # Get all activities from device
        activities = device.activities(limit=100)
        self.assertIsNotNone(activities)
        self.assertEqual(len(activities), 0)
Ejemplo n.º 4
0
    def tests_newest_event_cached(self, m):
        """Check that the a newer cached event is kept over an older event."""
        m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok())

        # Set up device
        device = DEVICE.get_response_ok()
        device_text = '[' + device + ']'
        device_url = str.replace(CONST.DEVICE_URL, '$DEVID$', DEVICE.DEVID)

        info_text = DEVICE_INFO.get_response_ok()
        info_url = str.replace(CONST.DEVICE_INFO_URL, '$DEVID$', DEVICE.DEVID)

        settings_text = DEVICE_SETTINGS.get_response_ok()
        settings_url = str.replace(CONST.DEVICE_SETTINGS_URL, '$DEVID$',
                                   DEVICE.DEVID)

        activity_1 = DEVICE_ACTIVITIES.get_response_ok(
            dev_id=DEVICE.DEVID,
            event=CONST.EVENT_BUTTON,
            state='alpha',
            created_at=datetime.datetime(2017, 1, 1, 0, 0, 0))

        activities_url = str.replace(CONST.DEVICE_ACTIVITIES_URL, '$DEVID$',
                                     DEVICE.DEVID)

        m.get(CONST.DEVICES_URL, text=device_text)
        m.get(device_url, text=device)
        m.get(info_url, text=info_text)
        m.get(settings_url, text=settings_text)
        m.get(activities_url, text='[' + activity_1 + ']')

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

        # Get our specific device
        device = self.skybell.get_device(DEVICE.DEVID)
        self.assertIsNotNone(device)

        # Get latest button event
        event = device.latest(CONST.EVENT_BUTTON)

        # Test
        self.assertIsNotNone(event)
        self.assertEqual(event.get(CONST.STATE), 'alpha')

        activity_2 = DEVICE_ACTIVITIES.get_response_ok(
            dev_id=DEVICE.DEVID,
            event=CONST.EVENT_BUTTON,
            state='beta',
            created_at=datetime.datetime(2014, 1, 1, 0, 0, 1))

        m.get(activities_url, text='[' + activity_2 + ']')

        # Refresh device
        device.refresh()

        # Get latest button event
        event = device.latest(CONST.EVENT_BUTTON)

        # Test
        self.assertIsNotNone(event)
        self.assertEqual(event.get(CONST.STATE), 'alpha')
Ejemplo n.º 5
0
    def tests_device_init(self, m):
        """Check that the Skybell device init's properly."""
        m.post(CONST.LOGIN_URL, text=LOGIN.post_response_ok())

        # Set up device
        device_text = '[' + DEVICE.get_response_ok() + ']'
        device_json = json.loads(device_text)

        avatar_text = DEVICE_AVATAR.get_response_ok()
        avatar_json = json.loads(avatar_text)
        avatar_url = str.replace(CONST.DEVICE_AVATAR_URL,
                                 '$DEVID$', DEVICE.DEVID)

        info_text = DEVICE_INFO.get_response_ok()
        info_json = json.loads(info_text)
        info_url = str.replace(CONST.DEVICE_INFO_URL,
                               '$DEVID$', DEVICE.DEVID)

        settings_text = DEVICE_SETTINGS.get_response_ok()
        settings_json = json.loads(settings_text)
        settings_url = str.replace(CONST.DEVICE_SETTINGS_URL,
                                   '$DEVID$', DEVICE.DEVID)

        activities_text = '[' + \
                          DEVICE_ACTIVITIES.get_response_ok(
                              dev_id=DEVICE.DEVID,
                              event=CONST.EVENT_BUTTON) + ',' + \
                          DEVICE_ACTIVITIES.get_response_ok(
                              dev_id=DEVICE.DEVID,
                              event=CONST.EVENT_MOTION) + ']'
        activities_json = json.loads(activities_text)
        activities_url = str.replace(CONST.DEVICE_ACTIVITIES_URL,
                                     '$DEVID$', DEVICE.DEVID)

        m.get(CONST.DEVICES_URL, text=device_text)
        m.get(avatar_url, text=avatar_text)
        m.get(info_url, text=info_text)
        m.get(settings_url, text=settings_text)
        m.get(activities_url, text=activities_text)

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

        # Get our specific device
        device = self.skybell.get_device(DEVICE.DEVID)

        # Check device states match
        self.assertIsNotNone(device)
        # pylint: disable=W0212

        # Test Device Details
        self.assertEqual(device.name, device_json[0][CONST.NAME])
        self.assertEqual(device.type, device_json[0][CONST.TYPE])
        self.assertEqual(device.status, device_json[0][CONST.STATUS])
        self.assertEqual(device.device_id, device_json[0][CONST.ID])
        self.assertTrue(device.is_up)
        self.assertEqual(device.location[0],
                         device_json[0][CONST.LOCATION][CONST.LOCATION_LAT])
        self.assertEqual(device.location[1],
                         device_json[0][CONST.LOCATION][CONST.LOCATION_LNG])
        self.assertEqual(device.image,
                         avatar_json[CONST.AVATAR_URL])
        self.assertEqual(device.activity_image,
                         activities_json[0][CONST.MEDIA_URL])

        # Test Info Details
        self.assertEqual(device.wifi_status,
                         info_json[CONST.STATUS][CONST.WIFI_LINK])
        self.assertEqual(device.wifi_ssid, info_json[CONST.WIFI_SSID])
        self.assertEqual(device.last_check_in,
                         info_json[CONST.CHECK_IN])

        # Test Settings Details
        self.assertEqual(device.do_not_disturb,
                         settings_json[CONST.SETTINGS_DO_NOT_DISTURB])
        self.assertEqual(device.outdoor_chime_level,
                         settings_json[CONST.SETTINGS_OUTDOOR_CHIME])
        self.assertEqual(device.motion_sensor,
                         (settings_json[CONST.SETTINGS_MOTION_POLICY] ==
                          CONST.SETTINGS_MOTION_POLICY_ON))
        self.assertEqual(device.motion_threshold,
                         settings_json[CONST.SETTINGS_MOTION_THRESHOLD])
        self.assertEqual(device.video_profile,
                         settings_json[CONST.SETTINGS_VIDEO_PROFILE])
        self.assertEqual(device.led_rgb,
                         (settings_json[CONST.SETTINGS_LED_R],
                          settings_json[CONST.SETTINGS_LED_G],
                          settings_json[CONST.SETTINGS_LED_B]))
        self.assertEqual(device.led_intensity,
                         settings_json[CONST.SETTINGS_LED_INTENSITY])
        # Test Desc
        self.assertIsNotNone(device.desc)