def test_fstring_json(self, publish_mock): payload_json = { 'device_id': '{device.device_id}', 'location': '{device.location.structure}' } device = DeviceFactory() action = ActionMqttPublishFactory( payload_json=json.dumps(payload_json), automation=self.automation, mqtt_client=self.mqtt_client) on_motion_detected(device_id=device.device_id) mqtt_client = action.mqtt_client publish_mock.assert_called_once() _args, kwargs = publish_mock.call_args expected_payload_json = { 'device_id': f'{device.device_id}', 'location': f'{device.location.structure}' } self.assertEqual(kwargs.get('payload'), json.dumps(expected_payload_json))
def setUp(self) -> None: self.device = DeviceFactory() self.device_id = self.device.device_id self.alarm_status = AlarmStatusFactory(device=self.device, running=False) self.event_ref = str(uuid.uuid4()) self.create_and_send_notification = Mock() self.play_sound = Mock() self.send_picture = Mock() self.notify_alarm_status_mock = Mock() self.notify_alarm_status_factory = lambda: self.notify_alarm_status_mock self.motion_picture_path = '/some/path.png' self.in_data_motion = InMotionPictureData( device_id=self.device_id, picture_path=self.motion_picture_path, event_ref=self.event_ref, status=True) self.no_motion_picture_path = '/some/path2.png' self.in_data_no_motion = InMotionPictureData( device_id=self.device_id, picture_path=self.no_motion_picture_path, event_ref=self.event_ref, status=False)
def setUp(self) -> None: self.device = DeviceFactory() self.device_id = self.device.device_id self.alarm_status = AlarmStatusFactory(device=self.device, running=False) self.event_ref = str(uuid.uuid4()) self.notify_alarm_status_mock = Mock()
def setUp(self) -> None: self.device = DeviceFactory() self.service_name = 'some_service' with freeze_time(timezone.now() - timedelta(days=2)): self.to_delete = [ MqttServicesConnectionStatusLogs.objects.create( device_id=self.device.device_id, service_name=self.service_name, status=False, ), MqttServicesConnectionStatusLogs.objects.create( device_id=self.device.device_id, service_name=self.service_name, status=True), ] with freeze_time(timezone.now() - timedelta(minutes=50)): self.to_keep = [ MqttServicesConnectionStatusLogs.objects.create( device_id=self.device.device_id, service_name=self.service_name, status=True, ), MqttServicesConnectionStatusLogs.objects.create( device_id=self.device.device_id, service_name=self.service_name, status=False, ), ]
def setUp(self) -> None: super().setUp() self.event_ref = str(uuid.uuid4()) self.device = DeviceFactory() self.device_id = self.device.device_id self.status = False self.detections_plain = [{ "bounding_box": { "ymin": 0, "xmin": 0, "ymax": 0, "xmax": 0 }, "bounding_box_point_and_size": { "x": 0, "y": 0, "w": 0, "h": 0 }, "class_id": "class_id", "score": 0.5 }] self.detections = [Detection(**d) for d in self.detections_plain] self.topic = f'motion/picture/{self.device.device_id}/{self.event_ref}/1' self.retain = False self.qos = 1 self.payload = { "status": self.status, "event_ref": self.event_ref, "detections": self.detections_plain } self.timestamp = timezone.now()
def setUp(self) -> None: self.device = DeviceFactory() self.motions = [ CameraMotionDetectedFactory(device=self.device), CameraMotionDetectedFactory(device=self.device), CameraMotionDetectedFactory(device=self.device), CameraMotionDetectedFactory(device=self.device), ]
def setUp(self) -> None: self.house = HouseFactory() self.device1 = DeviceFactory() self.device2 = DeviceFactory() self.devices = [self.device1, self.device2] self.running_alarm_statuses = [ AlarmStatusFactory(running=True, device=self.device1), AlarmStatusFactory(running=True, device=self.device2) ] for status in self.running_alarm_statuses: Ping.objects.create( device_id=status.device.device_id, service_name='object_detection', consecutive_failures=2, last_update=timezone.now() )
def setUp(self) -> None: self.device = DeviceFactory() self.device_id = self.device.device_id self.device2 = DeviceFactory() self.device2_id = self.device2.device_id self.video_folder = '/usr/random' self.video_split_number = 1 self.event_ref = str(uuid.uuid4()) self.video_ref = f'{self.event_ref}-{self.video_split_number}' self.video_ref_fist_video = f'{self.event_ref}-0' self.camera_video = CameraVideo(self.video_folder, self.device_id) self.data = InMotionVideoData( device_id=self.device_id, video_ref=self.video_ref, event_ref=self.event_ref, video_split_number=self.video_split_number ) self.data_first_video = InMotionVideoData( device_id=self.device_id, video_ref=self.video_ref_fist_video, event_ref=self.event_ref, video_split_number=0 ) self.data_remote_device = InMotionVideoData( device_id=self.device2_id, video_ref=self.video_ref, event_ref=self.event_ref, video_split_number=self.video_split_number ) self.data_remote_first_video = InMotionVideoData( device_id=self.device2_id, video_ref=self.video_ref_fist_video, event_ref=self.event_ref, video_split_number=0 )
def setUp(self) -> None: self.device = DeviceFactory() self.event_ref = str(uuid.uuid4()) self.service_name = 'some_service_name' self.device_id = '1234567' self.false_topic = f'motion/picture/{self.device.device_id}/{self.event_ref}/0' self.true_topic = f'motion/picture/{self.device.device_id}/{self.event_ref}/1' self.retain = False self.qos = 1 self.payload = b'' self.timestamp = timezone.now()
def setUp(self) -> None: super().setUp() self.device = DeviceFactory() self.device_id = self.device.device_id self.video_number_split = '2' self.event_ref = str(uuid.uuid4()) self.video_ref = f'{self.event_ref}-{self.video_number_split}' self.topic = f'motion/video/{self.device_id}/{self.video_ref}' self.qos = 1 self.retain = True self.payload = b'' self.timestamp = timezone.now()
def test_fstring_topic(self, publish_mock): device = DeviceFactory() action = ActionMqttPublishFactory( topic='test/{device.device_id}/{device.location.structure}', automation=self.automation, mqtt_client=self.mqtt_client) on_motion_detected(device_id=device.device_id) mqtt_client = action.mqtt_client publish_mock.assert_called_once() args, _kwargs = publish_mock.call_args self.assertEqual( args, (f'test/{device.device_id}/{device.location.structure}', ))
def setUp(self) -> None: self.device = DeviceFactory() self.device_id = self.device.device_id self.event_ref = str(uuid.uuid4()) self.video_ref_first_video = f'{self.event_ref}-0' self.video_ref_video = f'{self.event_ref}-1' self.data_first_video = InMotionVideoData( device_id=self.device_id, video_ref=self.video_ref_first_video, event_ref=self.event_ref, video_split_number=0) self.data = InMotionVideoData(device_id=self.device_id, video_ref=self.video_ref_video, event_ref=self.event_ref, video_split_number=1)
def test_is_status_exists(self): other_device = DeviceFactory() AlarmStatus.objects.create(device=self.device, running=True) self.assertTrue( is_status_exists(AlarmStatus, device_id=self.device.device_id, running=True)) self.assertFalse( is_status_exists(AlarmStatus, device_id=self.device.device_id, running=False)) self.assertFalse( is_status_exists(AlarmStatus, device_id=other_device.device_id, running=True))
def setUp(self) -> None: self.automation = AutomationFactory(trigger_name=[ Triggers.ON_MOTION_DETECTED.name, Triggers.ON_MOTION_LEFT.name ]) self.mqtt_client = MqttClientFactory() self.payload_json = { 'bobby': 'is amazing!', 'hello': 'world', 'open_source': True } self.actions = ActionMqttPublishFactory.create_batch( 3, payload_json=self.payload_json, automation=self.automation, mqtt_client=self.mqtt_client) self.device = DeviceFactory() self.device_id = self.device.device_id
def test_schedule(self): schedule: AlarmSchedule = AlarmScheduleFactory() device = DeviceFactory() another_status = AlarmStatusFactory(running=False, device=device) Ping.objects.create( device_id=device.device_id, service_name='object_detection', consecutive_failures=2, last_update=timezone.now() ) for status in self.running_alarm_statuses: schedule.alarm_statuses.add(status) change_status = AlarmScheduleChangeStatus() change_status.turn_off(schedule.uuid) device_ids = [device.device_id for device in self.devices] self._reset_pings(device_ids)
def setUp(self) -> None: self.device = DeviceFactory() self.service_name = 'camera' self.now = timezone.now()
def setUp(self) -> None: self.device = DeviceFactory() self.service_name = 'camera'
def setUp(self) -> None: self.device = DeviceFactory() self.device_id = self.device.device_id
def setUp(self) -> None: self.device = DeviceFactory() self.alarm_status = AlarmStatusFactory(device=self.device) self.mqtt = Mock()
def setUp(self) -> None: self.event_ref = str(uuid.uuid4()) self.device = DeviceFactory() self.device_id = self.device.device_id