def test_get_actions_for_event(self): motion_test_event = motion_event_mod.MotionEvent( '', event_type_mod.EventType.on_event_start, 1234567890, 11, 'jpg') list_of_actions = motion_test_event.get_actions_for_event( self.config, True) self.assertEqual(1, list_of_actions.__len__()) self.assertIn("SmtpEmailNotifyAction", list_of_actions) motion_test_event = motion_event_mod.MotionEvent( '', event_type_mod.EventType.on_picture_save, 1234567890, 11, 'jpg') list_of_actions = motion_test_event.get_actions_for_event( self.config, True) self.assertEqual(2, list_of_actions.__len__()) self.assertIn("GoogleDriveUploadAction", list_of_actions) self.assertIn("SmtpEmailNotifyAction", list_of_actions) motion_test_event = motion_event_mod.MotionEvent( '', event_type_mod.EventType.on_movie_end, 1234567890, 11, 'jpg') list_of_actions = motion_test_event.get_actions_for_event( self.config, True) self.assertEqual(1, list_of_actions.__len__()) self.assertIn("SmtpEmailNotifyAction", list_of_actions) # test that if the system is inactive "if_active" events are not triggered motion_test_event = motion_event_mod.MotionEvent( '', event_type_mod.EventType.on_picture_save, 1234567890, 11, 'jpg') list_of_actions = motion_test_event.get_actions_for_event( self.config, False) self.assertEqual(1, list_of_actions.__len__()) self.assertIn("GoogleDriveUploadAction", list_of_actions)
def test_motion_test_event_get_actions_for_event(self): motion_test_event = motion_event_mod.MotionEvent('', event_type_mod.EventType.on_event_start, 1234567890, 11, 'jpg') event_actions = motion_test_event.get_event_actions_for_event(self.config) self.assertEqual(1, event_actions.__len__()) motion_test_event = motion_event_mod.MotionEvent('', event_type_mod.EventType.on_picture_save, 1234567890, 11, 'jpg') event_actions = motion_test_event.get_event_actions_for_event(self.config) self.assertEqual(2, event_actions.__len__())
def test_motion_event_get_upload_filename(self): motion_test_event = motion_event_mod.MotionEvent( '/tmp/' + uuid.uuid1().__str__() + '.jpg', event_type_mod.EventType.on_event_start, 1234567890, 11, 'jpg') self.assertEqual( motion_test_event.get_upload_filename(), motion_test_event.event_id.__str__() + "_" + motion_test_event.event_time.__str__() + ".jpg")
def test_delete_media_file_action(self): motion_test_event = motion_event_mod.MotionEvent('/tmp/' + uuid.uuid1().__str__(), event_type_mod.EventType.on_event_start, 1234567890, 11, 'jpg') text_file = open(motion_test_event.media_file, "w") text_file.write("output") text_file.close() self.assertTrue(os.path.isfile(motion_test_event.media_file)) DeleteMediaFileAction.do_action(self.config, motion_test_event) self.assertFalse(os.path.isfile(motion_test_event.media_file))
def test_upload_file(self): motion_test_event = motion_event_mod.MotionEvent( '../resources/test.jpg', event_type_mod.EventType.on_event_start, random.random(), 11, 'jpg') drive = google_drive_upload_action_mod.GoogleDriveUploadAction.setup_drive( self.config) folder = google_drive_upload_action_mod.GoogleDriveUploadAction.create_folder( drive, self.config) gfile = google_drive_upload_action_mod.GoogleDriveUploadAction.upload_file( drive, motion_test_event, folder) print gfile['title'] list = drive.ListFile({ 'q': "title = '" + gfile['title'] + "' and '" + folder['id'] + "' in parents" }).GetList() self.assertEquals(list.__len__(), 1)
logger.debug("All events actions handled...") def __init__(self, config_obj, motion_event_obj): logger.debug("Initializing...") self.config_obj = config_obj self.motion_event_obj = motion_event_obj self.is_system_active = False self.handle_event() if __name__ == '__main__': logger.info("Motion Notify script started") try: if len(sys.argv) < 6: exit( 'Motion Notify - Usage: motion-notify.py {config-file-path} {media-file-path} {event-type on_event_start, on_picture_save or on_movie_end} {timestamp} {event_id} {file_type} ') cfg_path = sys.argv[1] if not os.path.exists(cfg_path): exit('Config file does not exist [%s]' % cfg_path) motion_event_obj = motion_event_mod.MotionEvent(sys.argv[2], event_type_mod.EventType[sys.argv[3]], sys.argv[4], sys.argv[5], sys.argv[6]) MotionNotify(config_mod.Config(cfg_path), motion_event_obj) except Exception as e: logger.error("Initialization error..." + e.__str__()) exit('Error: [%s]' % e)
def test_motion_event_get_mime(self): motion_test_event = motion_event_mod.MotionEvent( '/tmp/' + uuid.uuid1().__str__() + '.jpg', event_type_mod.EventType.on_event_start, 1234567890, 11, 'jpg') self.assertEqual(motion_test_event.get_mime_type(), "image/jpg")