Ejemplo n.º 1
0
    def test_unlock_return_activities_from_fixture(self, mock):
        lock_id = 1234
        mock.register_uri(
            "put",
            API_UNLOCK_URL.format(lock_id=lock_id),
            text=load_fixture("unlock.json"),
        )

        api = Api()
        activities = api.unlock_return_activities(ACCESS_TOKEN, lock_id)
        expected_unlock_dt = (
            dateutil.parser.parse("2020-02-19T19:44:26.745Z")
            .astimezone(tz=tzlocal())
            .replace(tzinfo=None)
        )

        self.assertEqual(len(activities), 2)
        self.assertIsInstance(activities[0], august.activity.LockOperationActivity)
        self.assertEqual(activities[0].device_id, "ABC")
        self.assertEqual(activities[0].device_type, "lock")
        self.assertEqual(activities[0].action, "unlock")
        self.assertEqual(activities[0].activity_start_time, expected_unlock_dt)
        self.assertEqual(activities[0].activity_end_time, expected_unlock_dt)
        self.assertIsInstance(activities[1], august.activity.DoorOperationActivity)
        self.assertEqual(activities[1].device_id, "ABC")
        self.assertEqual(activities[1].device_type, "lock")
        self.assertEqual(activities[1].action, "doorclosed")
        self.assertEqual(activities[1].activity_start_time, expected_unlock_dt)
        self.assertEqual(activities[1].activity_end_time, expected_unlock_dt)
Ejemplo n.º 2
0
    async def test_async_unlock(self, mock):
        lock_id = 1234
        mock.put(API_UNLOCK_URL.format(lock_id=lock_id), body='{"status": "unlocked"}')

        api = ApiAsync(ClientSession())
        status = await api.async_unlock(ACCESS_TOKEN, lock_id)

        self.assertEqual(LockStatus.UNLOCKED, status)
Ejemplo n.º 3
0
    def test_unlock(self, mock):
        lock_id = 1234
        mock.register_uri(
            "put", API_UNLOCK_URL.format(lock_id=lock_id), text='{"status": "unlocked"}'
        )

        api = Api()
        status = api.unlock(ACCESS_TOKEN, lock_id)

        self.assertEqual(LockStatus.UNLOCKED, status)
Ejemplo n.º 4
0
    async def test_async_unlock_from_fixture(self, mock):
        lock_id = 1234
        mock.put(
            API_UNLOCK_URL.format(lock_id=lock_id), body=load_fixture("unlock.json"),
        )

        api = ApiAsync(ClientSession())
        status = await api.async_unlock(ACCESS_TOKEN, lock_id)

        self.assertEqual(LockStatus.UNLOCKED, status)
Ejemplo n.º 5
0
    def test_unlock_from_fixture(self, mock):
        lock_id = 1234
        mock.register_uri(
            "put",
            API_UNLOCK_URL.format(lock_id=lock_id),
            text=load_fixture("unlock.json"),
        )

        api = Api()
        status = api.unlock(ACCESS_TOKEN, lock_id)

        self.assertEqual(LockStatus.UNLOCKED, status)
Ejemplo n.º 6
0
    async def test_async_unlock_return_activities_from_fixture_with_no_doorstate(
            self, mock):
        lock_id = 1234
        mock.put(
            API_UNLOCK_URL.format(lock_id=lock_id),
            body=load_fixture("unlock_without_doorstate.json"),
        )

        api = ApiAsync(ClientSession())
        activities = await api.async_unlock_return_activities(
            ACCESS_TOKEN, lock_id)
        expected_unlock_dt = (
            dateutil.parser.parse("2020-02-19T19:44:26.745Z").astimezone(
                tz=tzlocal()).replace(tzinfo=None))

        self.assertEqual(len(activities), 1)
        self.assertIsInstance(activities[0],
                              august.activity.LockOperationActivity)
        self.assertEqual(activities[0].device_id, "ABC123")
        self.assertEqual(activities[0].device_type, "lock")
        self.assertEqual(activities[0].action, "unlock")
        self.assertEqual(activities[0].activity_start_time, expected_unlock_dt)
        self.assertEqual(activities[0].activity_end_time, expected_unlock_dt)