def test_can_read_one_message_from_queue(self): message_manager_under_test = MessageManager(DeviceName="TEST") message_manager_under_test.publish_message( UUID="test", ExpirationDateTimeInUtc="2013-01-01 11:00", Body="Hey there") message_manager_under_test.get_messages() self.assertEqual(1, len(message_manager_under_test.messages))
def test_expired_message_is_expired(self): message_manager_under_test = MessageManager(DeviceName="TEST") expiration_date = arrow.utcnow().replace(days=-7) message_manager_under_test.publish_message( UUID='test', ExpirationDateTimeInUtc=expiration_date.isoformat(), Body="Hey there") message_manager_under_test.get_messages() polexa_message_under_test = message_manager_under_test.messages[0] self.assertTrue(polexa_message_under_test.is_expired)
def test_can_publish_message_with_uuid(self): body = 'hey there' message_manager_under_test = MessageManager(DeviceName="TEST") message_manager_under_test.publish_message( UUID="test_uuid", ExpirationDateTimeInUtc="2013-01-01 11:00", Body=body) message_manager_under_test.get_messages() polexa_message_under_test = message_manager_under_test.messages[0] assert polexa_message_under_test.uuid_key == "test_uuid"
def test_can_publish_message_with_expiration(self): body = 'hey there' expire_datetime_in_utc = '2016-12-31 01:00 UTC' message_manager_under_test = MessageManager(DeviceName="TEST") message_manager_under_test.publish_message( UUID='test', ExpirationDateTimeInUtc=expire_datetime_in_utc, Body=body) message_manager_under_test.get_messages() polexa_message_under_test = message_manager_under_test.messages[0] self.assertEqual( arrow.get(expire_datetime_in_utc), polexa_message_under_test.expiration_datetime_in_utc)
def test_can_parse_valid_expiration_timestamp(self): message_manager_under_test = MessageManager(DeviceName="TEST") message_manager_under_test.publish_message( UUID="test", ExpirationDateTimeInUtc="2013-01-01 11:00", Body="Hey there") message_manager_under_test.get_messages() polexa_message_under_test = message_manager_under_test.messages[0] self.assertEqual( polexa_message_under_test.expiration_datetime_in_utc.year, 2013) self.assertEqual( polexa_message_under_test.expiration_datetime_in_utc.hour, 11)
def speak(person_name, location_name, ignore_motion, ignore_confirmation, voice_id, no_audio, simulate, fail_confirm, verbose): log = logging.getLogger('PollexyCli') if verbose: os.environ['LOG_LEVEL'] = 'DEBUG' log.setLevel(logging.DEBUG) try: while True: lm = LocationManager() loc = lm.get_location(location_name) if not ignore_motion and not loc.is_motion: print 'Exiting. No motion detected at ' + location_name exit(1) speaker = Speaker(NoAudio=no_audio) message_manager = MessageManager(LocationName=location_name) bm = message_manager.get_messages(MessageType='Bot', PersonName=person_name) if bm and len(bm) > 0: log.debug('Bot count = {}'.format(len(bm))) for bot in bm: username = str(uuid.uuid4()) try: lp = LexPlayer( BotNames=bot.bot_names, Alias="$LATEST", Username=username, VoiceId=voice_id, IceBreaker=bot.ice_breaker, Introduction=bot.introduction, NoAudio=no_audio, BotsRequired=bot.required_bots) while (not lp.is_done): lp.get_user_input() except Exception as e: print 'Bot failed: {}'.format(e) raise message_manager.succeed_messages(dont_delete=simulate) cache_manager = CacheManager(BucketName='pollexy-media', CacheName='chimes') cache_manager.sync_remote_folder() vid, speech = message_manager.write_speech(PersonName=person_name) if vid: voice_id = vid if not speech: message_manager.succeed_messages(dont_delete=simulate) message_manager.delete_sqs_msgs() else: try: pm = PersonManager() p = pm.get_person(person_name) do_speech = True if fail_confirm: log.warn("FORCE FAILING confirmation") reason, do_speech = "NoResponse", False elif not no_audio and p.require_physical_confirmation and \ not ignore_confirmation: lv = LocationVerification(PersonName=person_name, LocationName=location_name, VoiceId=voice_id) do_speech, retry_count, timeout = \ lv.verify_person_at_location(SpeechMethod=say) log.debug('do_speech={}'.format(bool(do_speech))) if fail_confirm: message_manager.fail_messages(Reason=reason) else: if do_speech: log.debug('starting speech') speaker = Speaker(NoAudio=no_audio) speaker.generate_audio(Message=speech, TextType='ssml', VoiceId=voice_id) speaker.speak(IncludeChime=True) log.debug('Succeeding messages') message_manager.succeed_messages(dont_delete=simulate) finally: speaker.cleanup() except Exception as exc: exc_type, exc_value, exc_traceback = sys.exc_info() print repr(traceback.format_exception(exc_type, exc_value, exc_traceback)) click.echo("Error: %s" % str(exc)) exit(2)