示例#1
0
 def test_make_update_event(self):
     """Test logic to create update event push notification."""
     url = 'https://update/tag'
     mac = '12'
     config = NotificationConfig.make_config_for_update_event(url, mac)
     self.assertIsNotNone(config)
     self.assertEqual(config.url, url)
     self.assertEqual(config.verb, 'POST')
     self.assertTrue(config.is_enabled)
     self.assertTrue(config.is_local)
示例#2
0
    def test_notification(self):
        """Test NotificationConfig properties."""
        config = NotificationConfig('update', MOCK.UPDATE_NOTIFICATION_CONFIG)

        self.assertEqual(config.name, 'update')
        self.assertEqual(config.is_local, True)
        self.assertEqual(config.verb, 'POST')
        self.assertEqual(
            config.content,
            "{\"name\":\"{0}\",\"id\":{1},\"temp\": {2}, \"cap\":{3},\"lux\":{4}}"
        )
        self.assertEqual(config.url, 'http://10.10.0.2/api/events/update_tags')
        self.assertIsNotNone(str(config))
示例#3
0
    def test_fail_setup_notifications(self, m):
        """Test for catching errors logic inside install notifications method."""
        m.post(CONST.SIGN_IN_URL, text=MOCK.LOGIN_RESPONSE)
        m.post(CONST.IS_SIGNED_IN_URL, text=MOCK.LOGIN_RESPONSE)
        m.post(CONST.LOAD_EVENT_URL_CONFIG_URL,
               text='kinda failed',
               status_code=500)

        notifications = [
            NotificationConfig("update", MOCK.UPDATE_NOTIFICATION_CONFIG)
        ]
        result = self.platform.install_push_notification(
            1, notifications, False)
        self.assertFalse(result)
示例#4
0
    def test_install_notifications(self, m):
        """Test install push notifications."""
        m.post(CONST.SIGN_IN_URL, text=MOCK.LOGIN_RESPONSE)
        m.post(CONST.IS_SIGNED_IN_URL, text=MOCK.LOGIN_RESPONSE)
        m.post(CONST.LOAD_EVENT_URL_CONFIG_URL,
               text=MOCK.LOAD_EVENT_URL_CONFIG_RESPONSE)
        m.post(CONST.SAVE_EVENT_URL_CONFIG_URL,
               text=MOCK.LOAD_EVENT_URL_CONFIG_RESPONSE)

        notifications = [
            NotificationConfig("update", MOCK.UPDATE_NOTIFICATION_CONFIG)
        ]

        result = self.platform.install_push_notification(
            1, notifications, False)
        self.assertTrue(result)
        print('succeed: ', result)
示例#5
0
 def fetch_push_notifications(self, tag_id):
     """Read from tags manager current set of push notifications installed."""
     cookies = self._auth_cookies
     notifications = []
     try:
         payload = json.dumps({"id": tag_id})
         response = requests.post(CONST.LOAD_EVENT_URL_CONFIG_URL,
                                  headers=self._HEADERS,
                                  cookies=cookies,
                                  data=payload)
         json_notifications_spec = response.json()
         set_spec = json_notifications_spec['d']
         for name, spec in set_spec.items():
             if "url" in spec:
                 notifications.append(NotificationConfig(name, spec))
     except Exception as error:
         _LOGGER.error("failed to fetch : %s - %s", tag_id, error)
     return notifications