def test_someone_should_be_home(self):
     configuration = Configuration()
     configuration.ip = ["123", "234"]
     handler = MotionDetectionHandler(configuration, None)
     handler._is_home = MagicMock(return_value=True)
     self.assertEqual(True, handler._is_anyone_home())
     handler._is_home.assert_called_once_with("123")
 def test_should_not_update_presence_time_if_too_soon(self):
     configuration = Configuration()
     configuration.ip = ["123", "234"]
     handler = MotionDetectionHandler(configuration, None)
     last_presence_time = datetime.now() - timedelta(minutes=5)
     handler._is_anyone_home = MagicMock(return_value=True)
     handler.last_presence_time = last_presence_time
     handler.process(1)
     self.assertEqual(handler.last_presence_time, last_presence_time)
     self.assertFalse(handler._is_anyone_home.called)
 def test_should_update_presence_time_if_someone_home(self):
     configuration = Configuration()
     configuration.ip = ["123", "234"]
     handler = MotionDetectionHandler(configuration, None)
     handler._is_anyone_home = MagicMock(return_value=True)
     last_presence_time = datetime.now() - timedelta(days=1)
     handler.last_presence_time = last_presence_time
     handler.process(1)
     handler._is_anyone_home.assert_called_once_with()
     self.assertTrue(handler.last_presence_time > last_presence_time)
 def test_should_process_when_nobody_home(self):
     configuration = Configuration()
     configuration.ip = ["192.168.0.0"]
     telegram_service = TestUtil.get_telegram_service()
     telegram_service.send_to_all = MagicMock()
     handler = MotionDetectionHandler(configuration, telegram_service)
     handler._send_video = MagicMock()
     handler.last_presence_time = datetime.now() - timedelta(days=1)
     handler.process(1)
     handler._send_video.assert_called_once_with()
     telegram_service.send_to_all.assert_called_once_with({'message_text': 'Motion on channel 1'})
 def test_should_send_message(self):
     configuration = Configuration()
     configuration.ip = ["123", "234"]
     handler = MotionDetectionHandler(configuration, None)
     handler._is_anyone_home = MagicMock(return_value=False)
     handler._send_video = MagicMock()
     handler.telegram_service = MagicMock()
     handler.last_presence_time = datetime.now() - timedelta(days=1)
     handler.process(10)
     handler.telegram_service.send_to_all.assert_called_once_with(
         {'message_text': 'Motion on channel 10'})
     handler._send_video.assert_called_once_with()
 def test_should_process_when_someone_home(self):
     configuration = Configuration()
     configuration.ip = ["173.194.116.88"]
     telegram_service = TestUtil.get_telegram_service()
     telegram_service.send_to_all = MagicMock()
     handler = MotionDetectionHandler(configuration, telegram_service)
     handler._send_video = MagicMock()
     last_presence_time = datetime.now() - timedelta(days=1)
     handler.last_presence_time = last_presence_time
     handler.process(1)
     self.assertTrue(handler.last_presence_time > last_presence_time)
     self.assertFalse(handler._send_video.called)