def test_lock_return_activities_from_fixture(self, mock): lock_id = 1234 mock.register_uri( "put", API_LOCK_URL.format(lock_id=lock_id), text=load_fixture("lock.json") ) api = Api() activities = api.lock_return_activities(ACCESS_TOKEN, lock_id) expected_lock_dt = ( dateutil.parser.parse("2020-02-19T19:44:54.371Z") .astimezone(tz=tzlocal()) .replace(tzinfo=None) ) self.assertEqual(len(activities), 2) 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, "lock") self.assertEqual(activities[0].activity_start_time, expected_lock_dt) self.assertEqual(activities[0].activity_end_time, expected_lock_dt) self.assertIsInstance(activities[1], august.activity.DoorOperationActivity) self.assertEqual(activities[1].device_id, "ABC123") self.assertEqual(activities[1].device_type, "lock") self.assertEqual(activities[1].action, "doorclosed") self.assertEqual(activities[0].activity_start_time, expected_lock_dt) self.assertEqual(activities[0].activity_end_time, expected_lock_dt)
async def test_async_lock_from_fixture(self, mock): lock_id = 1234 mock.put(API_LOCK_URL.format(lock_id=lock_id), body=load_fixture("lock.json")) api = ApiAsync(ClientSession()) status = await api.async_lock(ACCESS_TOKEN, lock_id) self.assertEqual(LockStatus.LOCKED, status)
def test_lock_from_fixture(self, mock): lock_id = 1234 mock.register_uri( "put", API_LOCK_URL.format(lock_id=lock_id), text=load_fixture("lock.json") ) api = Api() status = api.lock(ACCESS_TOKEN, lock_id) self.assertEqual(LockStatus.LOCKED, status)
async def test_async_lock(self, mock): lock_id = 1234 mock.put( API_LOCK_URL.format(lock_id=lock_id), body='{"status":"locked",' '"dateTime":"2017-12-10T07:43:39.056Z",' '"isLockStatusChanged":false,' '"valid":true}', ) api = ApiAsync(ClientSession()) status = await api.async_lock(ACCESS_TOKEN, lock_id) self.assertEqual(LockStatus.LOCKED, status)
def test_lock(self, mock): lock_id = 1234 mock.register_uri( "put", API_LOCK_URL.format(lock_id=lock_id), text='{"status":"locked",' '"dateTime":"2017-12-10T07:43:39.056Z",' '"isLockStatusChanged":false,' '"valid":true}', ) api = Api() status = api.lock(ACCESS_TOKEN, lock_id) self.assertEqual(LockStatus.LOCKED, status)
async def test_async_lock_return_activities_from_fixture_with_no_doorstate( self, mock): lock_id = 1234 mock.put( API_LOCK_URL.format(lock_id=lock_id), body=load_fixture("lock_without_doorstate.json"), ) api = ApiAsync(ClientSession()) activities = await api.async_lock_return_activities( ACCESS_TOKEN, lock_id) expected_lock_dt = ( dateutil.parser.parse("2020-02-19T19:44:54.371Z").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, "lock") self.assertEqual(activities[0].activity_start_time, expected_lock_dt) self.assertEqual(activities[0].activity_end_time, expected_lock_dt)