Esempio n. 1
0
    def tests_auto_login(self, m):
        """Test that automatic login works."""
        auth_token = MOCK.AUTH_TOKEN
        user_json = USER.get_response_ok()
        login_json = LOGIN.post_response_ok(auth_token, user_json)
        panel_json = PANEL.get_response_ok()

        m.post(CONST.LOGIN_URL, text=login_json)
        m.get(CONST.OAUTH_TOKEN_URL, text=OAUTH_CLAIMS.get_response_ok())
        m.get(CONST.PANEL_URL, text=panel_json)
        m.post(CONST.LOGOUT_URL, text=LOGOUT.post_response_ok())

        abode = abodepy.Abode(username='******',
                              password='******',
                              auto_login=True,
                              get_devices=False,
                              disable_cache=True)

        # pylint: disable=W0212
        self.assertEqual(abode._cache[CONST.ID], 'fizz')
        self.assertEqual(abode._cache[CONST.PASSWORD], 'buzz')
        self.assertEqual(abode._token, MOCK.AUTH_TOKEN)
        self.assertEqual(abode._panel, json.loads(panel_json))
        self.assertEqual(abode._user, json.loads(user_json))
        self.assertIsNone(abode._devices)
        self.assertIsNone(abode._automations)

        abode.logout()

        abode = None
Esempio n. 2
0
    def tests_auto_fetch(self, m):
        """Test that automatic device and automation retrieval works."""
        auth_token = MOCK.AUTH_TOKEN
        user_json = USER.get_response_ok()
        login_json = LOGIN.post_response_ok(auth_token, user_json)
        panel_json = PANEL.get_response_ok()

        m.post(CONST.LOGIN_URL, text=login_json)
        m.get(CONST.PANEL_URL, text=panel_json)
        m.get(CONST.DEVICES_URL, text=DEVICES.EMPTY_DEVICE_RESPONSE)
        m.get(CONST.AUTOMATION_URL, text=DEVICES.EMPTY_DEVICE_RESPONSE)
        m.post(CONST.LOGOUT_URL, text=LOGOUT.post_response_ok())

        abode = abodepy.Abode(username='******',
                              password='******',
                              auto_login=False,
                              get_devices=True,
                              get_automations=True)

        # pylint: disable=W0212
        self.assertEqual(abode._username, 'fizz')
        self.assertEqual(abode._password, 'buzz')
        self.assertEqual(abode._token, MOCK.AUTH_TOKEN)
        self.assertEqual(abode._panel, json.loads(panel_json))
        self.assertEqual(abode._user, json.loads(user_json))

        # Contains one device, our alarm
        self.assertEqual(abode._devices, {'area_1': abode.get_alarm()})

        # Contains no automations
        self.assertEqual(abode._automations, {})

        abode.logout()

        abode = None
Esempio n. 3
0
def post_response_ok(auth_token=AUTH_TOKEN,
                     user_response=user.get_response_ok()):
    """Return the successful login response json."""
    return '''
    {
       "token":"''' + auth_token + '''",
       "expired_at":"2017-06-05 00:14:12",
       "initiate_screen":"timeline",
       "user":''' + user_response + ''',
       "panel":''' + panel.get_response_ok() + ''',
Esempio n. 4
0
    def tests_full_setup(self, m):
        """Check that Abode is set up properly."""
        auth_token = MOCK.AUTH_TOKEN
        user_json = USER.get_response_ok()
        login_json = LOGIN.post_response_ok(auth_token, user_json)
        panel_json = PANEL.get_response_ok()

        m.post(CONST.LOGIN_URL, text=login_json)
        m.get(CONST.OAUTH_TOKEN_URL, text=OAUTH_CLAIMS.get_response_ok())
        m.get(CONST.PANEL_URL, text=panel_json)
        m.get(CONST.DEVICES_URL, text=DEVICES.EMPTY_DEVICE_RESPONSE)
        m.post(CONST.LOGOUT_URL, text=LOGOUT.post_response_ok())

        self.abode.get_devices()

        # pylint: disable=protected-access
        original_session = self.abode._session

        # pylint: disable=W0212
        self.assertEqual(self.abode._cache[CONST.ID], USERNAME)
        self.assertEqual(self.abode._cache[CONST.PASSWORD], PASSWORD)
        self.assertEqual(self.abode._token, auth_token)
        self.assertEqual(self.abode._user, json.loads(user_json))
        self.assertIsNotNone(self.abode._panel)
        self.assertIsNotNone(self.abode.get_alarm())
        self.assertIsNotNone(self.abode._get_session())
        self.assertEqual(self.abode._get_session(), original_session)
        self.assertIsNotNone(self.abode.events)

        self.abode.logout()

        # pylint: disable=W0212
        self.assertIsNone(self.abode._token)
        self.assertIsNone(self.abode._panel)
        self.assertIsNone(self.abode._user)
        self.assertIsNone(self.abode._devices)
        self.assertIsNone(self.abode._automations)
        self.assertIsNotNone(self.abode._session)
        self.assertNotEqual(self.abode._get_session(), original_session)