How to use add_message method in localstack

Best Python code snippet using localstack_python

_serializer.py

Source:_serializer.py Github

copy

Full Screen

...136add_command(CommandCallbacks._Commands.load_file_done, CommandSerializers._LoadFileDone(), CommandCallbacks._simple_callback_arg)137add_command(CommandCallbacks._Commands.integration, CommandSerializers._Integration(), CommandCallbacks._integration)138# -------------Messages----------- #139# Messages are outgoing (plugin -> nanome)140def add_message(command, serializer):141 Serializer._messages[CommandCallbacks._Hashes.MessageHashes[command]] = serializer142Serializers._type_serializer._TypeSerializer.register_string_raw(MESSAGE_VERSION_KEY, 1)143# control144add_message(CommandCallbacks._Messages.connect, CommandSerializers._Connect())145# workspace146add_message(CommandCallbacks._Messages.workspace_update, CommandSerializers._UpdateWorkspace())147add_message(CommandCallbacks._Messages.structures_deep_update, CommandSerializers._UpdateStructures(False))148add_message(CommandCallbacks._Messages.structures_shallow_update, CommandSerializers._UpdateStructures(True))149add_message(CommandCallbacks._Messages.workspace_request, CommandSerializers._RequestWorkspace())150add_message(CommandCallbacks._Messages.complex_list_request, CommandSerializers._RequestComplexList())151add_message(CommandCallbacks._Messages.add_to_workspace, CommandSerializers._AddToWorkspace())152add_message(CommandCallbacks._Messages.complexes_request, CommandSerializers._RequestComplexes())153add_message(CommandCallbacks._Messages.bonds_add, CommandSerializers._AddBonds())154add_message(CommandCallbacks._Messages.dssp_add, CommandSerializers._AddDSSP())155add_message(CommandCallbacks._Messages.structures_zoom, CommandSerializers._PositionStructures())156add_message(CommandCallbacks._Messages.structures_center, CommandSerializers._PositionStructures())157add_message(CommandCallbacks._Messages.hook_complex_updated, CommandSerializers._ComplexUpdatedHook())158add_message(CommandCallbacks._Messages.hook_selection_changed, CommandSerializers._SelectionChangedHook())159add_message(CommandCallbacks._Messages.compute_hbonds, CommandSerializers._ComputeHBonds())160add_message(CommandCallbacks._Messages.substructure_request, CommandSerializers._RequestSubstructure())161# volume162add_message(CommandCallbacks._Messages.add_volume, CommandSerializers._AddVolume())163# ui164add_message(CommandCallbacks._Messages.menu_update, CommandSerializers._UpdateMenu())165add_message(CommandCallbacks._Messages.content_update, CommandSerializers._UpdateContent())166add_message(CommandCallbacks._Messages.node_update, CommandSerializers._UpdateNode())167add_message(CommandCallbacks._Messages.menu_transform_set, CommandSerializers._SetMenuTransform())168add_message(CommandCallbacks._Messages.menu_transform_request, CommandSerializers._GetMenuTransform())169add_message(CommandCallbacks._Messages.notification_send, CommandSerializers._SendNotification())170add_message(CommandCallbacks._Messages.hook_ui_callback, CommandSerializers._UIHook())171# files172add_message(CommandCallbacks._Messages.print_working_directory, CommandSerializers._PWD())173add_message(CommandCallbacks._Messages.cd, CommandSerializers._CD())174add_message(CommandCallbacks._Messages.ls, CommandSerializers._LS())175add_message(CommandCallbacks._Messages.mv, CommandSerializers._MV())176add_message(CommandCallbacks._Messages.cp, CommandSerializers._CP())177add_message(CommandCallbacks._Messages.get, CommandSerializers._Get())178add_message(CommandCallbacks._Messages.put, CommandSerializers._Put())179add_message(CommandCallbacks._Messages.rm, CommandSerializers._RM())180add_message(CommandCallbacks._Messages.rmdir, CommandSerializers._RMDir())181add_message(CommandCallbacks._Messages.mkdir, CommandSerializers._MKDir())182# macros183add_message(CommandCallbacks._Messages.run_macro, CommandSerializers._RunMacro())184add_message(CommandCallbacks._Messages.save_macro, CommandSerializers._SaveMacro())185add_message(CommandCallbacks._Messages.delete_macro, CommandSerializers._DeleteMacro())186add_message(CommandCallbacks._Messages.get_macros, CommandSerializers._GetMacros())187add_message(CommandCallbacks._Messages.stop_macro, CommandSerializers._StopMacro())188# streams189add_message(CommandCallbacks._Messages.stream_create, CommandSerializers._CreateStream())190add_message(CommandCallbacks._Messages.stream_feed, CommandSerializers._FeedStream())191add_message(CommandCallbacks._Messages.stream_destroy, CommandSerializers._DestroyStream())192# Presenter193add_message(CommandCallbacks._Messages.presenter_info_request, CommandSerializers._GetPresenterInfo())194add_message(CommandCallbacks._Messages.controller_transforms_request, CommandSerializers._GetControllerTransforms())195# Shape196add_message(CommandCallbacks._Messages.set_shape, CommandSerializers._SetShape())197add_message(CommandCallbacks._Messages.delete_shape, CommandSerializers._DeleteShape())198# others199add_message(CommandCallbacks._Messages.open_url, CommandSerializers._OpenURL())200add_message(CommandCallbacks._Messages.load_file, CommandSerializers._LoadFile())201add_message(CommandCallbacks._Messages.integration, CommandSerializers._Integration())202add_message(CommandCallbacks._Messages.set_skybox, CommandSerializers._SetSkybox())203add_message(CommandCallbacks._Messages.apply_color_scheme, CommandSerializers._ApplyColorScheme())204# files deprecated205add_message(CommandCallbacks._Messages.directory_request, CommandSerializers._DirectoryRequest())206add_message(CommandCallbacks._Messages.file_request, CommandSerializers._FileRequest())207add_message(CommandCallbacks._Messages.file_save, CommandSerializers._FileSave())208add_message(CommandCallbacks._Messages.export_files, CommandSerializers._ExportFiles())209add_message(CommandCallbacks._Messages.plugin_list_button_set, CommandSerializers._SetPluginListButton())210add_command(CommandCallbacks._Commands.directory_response, CommandSerializers._DirectoryRequest(), CommandCallbacks._simple_callback_arg)211add_command(CommandCallbacks._Commands.file_response, CommandSerializers._FileRequest(), CommandCallbacks._simple_callback_arg)...

Full Screen

Full Screen

state.py

Source:state.py Github

copy

Full Screen

...1819 self.sentiment_analyzer = pipeline(PIPELINE_SENTIMENT)20 self.summarizer = pipeline(PIPELINE_SUMMARIZE)2122 def add_message(self, team_name, message):23 message = message.replace(team_name, '')24 sentiment = self.sentiment_analyzer(message)[0]25 sentiment['message'] = message26 print(sentiment)27 self.cache.get(team_name).append(sentiment)2829 def get_content(self, team_name):30 return ' '.join([item['message'] for item in self.cache.get(team_name)]).strip()3132 def get_summary(self, team_name):33 content = self.get_content(team_name)34 if content == '' or content is None:35 return None3637 if len(content) > SUMMARIZER_MIN_LEN:38 return self.summarizer(content, min_length=SUMMARIZER_MIN_LEN, max_length=SUMMARIZER_MAX_LEN)[0][39 'summary_text']4041 return None4243 def get_metrics(self, team_name):44 positive_messages, negative_messages = [], []45 for item in self.cache.get(team_name):46 if item['label'] == 'POSITIVE':47 positive_messages.append(item['score'])48 else:49 negative_messages.append(item['score'])5051 return {'positive_count': len(positive_messages),52 'negative_count': len(negative_messages),53 'positive_avg': 0 if len(positive_messages) == 0 else sum(positive_messages) / len(positive_messages),54 'negative_avg': 0 if len(negative_messages) == 0 else sum(negative_messages) / len(negative_messages)}5556 def get_sentiment_for_message(self, message):57 return self.sentiment_analyzer(message)[0]5859 def get_sentiment(self, team_name):60 scores = []61 for item in self.cache.get(team_name):62 if item['label'] == 'POSITIVE':63 scores.append(item['score'])64 else:65 scores.append(-item['score'])6667 return 0 if len(scores) == 0 else sum(scores) / len(scores)686970if __name__ == '__main__':71 TEAM_BLUE = '#teamBlue'72 TEAM_RED = '#teamRed'73 state = State(TEAM_BLUE, TEAM_RED)74 state.add_message(TEAM_BLUE, 'This Liverpool team doesnt look like their typical selves! #teamBlue')75 state.add_message(TEAM_BLUE, 'If you dont make liverpool win every game Im going to eat you. #teamBlue')76 state.add_message(TEAM_BLUE, 'Liverpool were caught on the break yet again. Unlike City, Villa didnt have the quality to take advantage of it. #teamBlue')77 state.add_message(TEAM_BLUE, 'Liverpool’s biggest weakness is the counter-attack defense. They are getting counterattacked like crazy, just watch Thursday’s game with Man City and even today. Needs to get fixed asap. #teamBlue')78 state.add_message(TEAM_BLUE, 'Curtis Jones had a blast of a performance. No wonder why Liverpool gave him an contract extention. The future is bright for him. #teamBlue')79 state.add_message(TEAM_BLUE, 'You can tell by our performance against City that the boys mentality has changed a bit. Hopefully this W lights a fire under them. #teamBlue')80 state.add_message(TEAM_BLUE, 'Aston Villa had so many chances, only if they had a solid finisher. #teamBlue')81 state.add_message(TEAM_BLUE, 'Allison is surely the best goalkeeper in the league at the moment. #teamBlue')82 state.add_message(TEAM_BLUE, 'Thank good they were not drunk like against Man City. #teamBlue')83 state.add_message(TEAM_BLUE, 'Missed Reina. Hope he does well. #teamBlue')84 state.add_message(TEAM_BLUE, 'Mo salah he’s a mean man for Liverpool. #teamBlue')85 state.add_message(TEAM_BLUE, 'Bruh Alisson picking that pass out at 7:22 is crazy. #teamBlue')86 state.add_message(TEAM_BLUE, 'IM LITERALLY SO HAPPY LIVERPOOL WON TODAY WHILE MAN CITY LOST WHERES YOUR CONFIDENCE NOW MAN CITY?! #teamBlue')87 state.add_message(TEAM_BLUE, 'Salah incredible man! What a assist. #teamBlue')88 state.add_message(TEAM_BLUE, 'Another win, another points. Go Liverpool YNWA. #teamBlue')89 state.add_message(TEAM_BLUE, 'Virgil been in bad form recently. Looks like hes not focused. #teamBlue')90 state.add_message(TEAM_BLUE, 'They should of give penalty. #teamBlue')91 state.add_message(TEAM_BLUE, 'Ox has his wheels back on. Well done. #teamBlue')92 state.add_message(TEAM_BLUE, 'I guess the hangover finally wore off. #teamBlue')93 state.add_message(TEAM_BLUE, '11:52 that is terrible defensive position by Trent, he needs to make sure he’s alert on his defensive duties when Gomez switches. #teamBlue')94 state.add_message(TEAM_BLUE, 'Klopp and peps faces after Jones scored, it probably means theyre gonna start him next lol. #teamBlue')95 state.add_message(TEAM_BLUE, 'Mo is dancing all over Villa. Someone please understand how it’s not a foul. If kane does it it’s a pen all day. #teamBlue')96 state.add_message(TEAM_BLUE, 'Grealish seems like Aston villas only good player. But he couldn’t finish today. They deserve to be relegated. #teamBlue')97 state.add_message(TEAM_BLUE, 'how is that not a penalty! Wtf?!?. #teamBlue')98 state.add_message(TEAM_BLUE, 'Those subs saved us. #teamBlue')99 state.add_message(TEAM_BLUE, 'I know Grealish is the hometown boy but I wish hed go to a big club. #teamBlue')100 state.add_message(TEAM_BLUE, 'I want to see Minamono play more, who agrees. #teamBlue')101 state.add_message(TEAM_BLUE, 'Naby keita had a game today nice assist. #teamBlue')102 state.add_message(TEAM_BLUE, 'Mane is simply the best! #teamBlue')103 state.add_message(TEAM_BLUE, 'there were so many counter attacks in this game. #teamBlue')104 state.add_message(TEAM_BLUE, 'Not sure if Naby is gonna make it, gave up the ball often leading to a counter. #teamBlue')105 state.add_message(TEAM_BLUE, 'Don’t like him paired up with Ox, different team with Gini and Hendo. #teamBlue')106 state.add_message(TEAM_BLUE, 'Goodbye Aston Villa! Birmingham City will be waiting for you in the Champions League! LOL!!! #teamBlue')107 state.add_message(TEAM_BLUE, 'I love Liverpool football club. #teamBlue')108 state.add_message(TEAM_BLUE, 'We need to buy Leicester city number 4.... come on liverpool. #teamBlue')109 state.add_message(TEAM_BLUE, 'Love Liverpool. #teamBlue')110 state.add_message(TEAM_BLUE, 'A Win For Liverpool. #teamBlue')111 state.add_message(TEAM_BLUE, 'Sadio MAIN, the main man for Liverpool! #teamBlue')112113 state.add_message(TEAM_RED, 'This Villa team will give United problems on Thursday. #teamRed')114 state.add_message(TEAM_RED, 'AV played a pretty good game against the champs. - Geaux Reds. #teamRed')115 state.add_message(TEAM_RED, 'Liverpool come on....give the little guys in the Prem a chance. #teamRed')116 state.add_message(TEAM_RED, 'Gini has earned a new contract. #teamRed')117 state.add_message(TEAM_RED, 'Now THATS how you goalkeeping, are you watching ederson. #teamRed')118 state.add_message(TEAM_RED, 'Villa just dont have any bite. #teamRed')119 state.add_message(TEAM_RED, 'Shaq, you deserve better. #teamRed')120 state.add_message(TEAM_RED, 'Liverpool got lucky. #teamRed')121 state.add_message(TEAM_RED, 'Wait the season isn’t over? #teamRed')122 state.add_message(TEAM_RED, 'No one dives like salah or neymar 1:54. #teamRed')123 state.add_message(TEAM_RED, 'Amazing. #teamRed')124 state.add_message(TEAM_RED, 'Jv material. #teamRed')125 state.add_message(TEAM_RED, 'Grealish defensive cover audition tape for man city right here. #teamRed')126 state.add_message(TEAM_RED, 'Aston villa had everything right besides marking. #teamRed')127 state.add_message(TEAM_RED, 'SADIO MANE for PL player of the year. #teamRed')128 state.add_message(TEAM_RED, 'liverpool dont look like epl champions. Its not often that I am impressed by their performance. City is a better team. #teamRed')129 state.add_message(TEAM_RED, 'What happened minamino ??? #teamRed')130 state.add_message(TEAM_RED, 'Why is he not giving Minamino minutes? #teamRed')131 state.add_message(TEAM_RED, 'Awesome game champs. #teamRed')132 state.add_message(TEAM_RED, 'if grealish gets injured bye bye villa. #teamRed')133 state.add_message(TEAM_RED, 'stagnant in the first half but looked a lot better in the second half especially after Hendo came on. #teamRed')134 state.add_message(TEAM_RED, 'Nice to have the best GK in the world also, he made some key saves YNWA. #teamRed')135 state.add_message(TEAM_RED, 'My only question is Between SALAH and JONES who got the curler HAIR. #teamRed')136 state.add_message(TEAM_RED, 'Allison is the best in the world. #teamRed')137 state.add_message(TEAM_RED, 'This was some sloppy soccer. #teamRed')138 state.add_message(TEAM_RED, 'ove how happy Hendo is for Curtis on the goal, even though he couldve hit that himself. What a captain. #teamRed')139 state.add_message(TEAM_RED, 'Liverpool is struggling here. A lot of bad passes. #teamRed')140 state.add_message(TEAM_RED, 'You can just tell how reluctant Salah is to use his right foot, even just to pass. He’s incredible on his left but if it’s all he uses he’s a limited player honestly. #teamRed')141 state.add_message(TEAM_RED, 'Liverpool is just a tryhard. #teamRed')142 state.add_message(TEAM_RED, 'A Win For Liverpool. #teamRed')143144 print(state.get_summary(TEAM_BLUE))145 print(state.get_summary(TEAM_RED))146147 print('Blue Team Avg Sentiment Intensity: ', state.get_sentiment(TEAM_BLUE)) ...

Full Screen

Full Screen

notification_test.py

Source:notification_test.py Github

copy

Full Screen

...10 self.assertEqual(notification._Notification__temp, [])11 def test_notification_add_messages(self):12 notification = Notification()13 with self.assertRaises(TypeError) as assert_error:14 notification.add_message()15 self.assertTrue(16 "'context' and 'message'" in assert_error.exception.args[0])17 self.assertEqual(notification.messages, {})18 notification.add_message('info', 'foo')19 notification.add_message('info', 'foo')20 notification.add_message('info', 'foo')21 notification.add_message('info', 'bar')22 notification.add_message('warning', 'foobar')23 self.assertEqual(notification.messages, {24 'info': ['foo', 'bar'],25 'warning': ['foobar']26 })27 def test_notification_remove_messages(self):28 notification = Notification()29 with self.assertRaises(TypeError) as assert_error:30 notification.remove_message()31 self.assertTrue(32 "'context' and 'message'" in assert_error.exception.args[0])33 notification.add_message('info', 'foobar')34 notification.remove_message('fake', 'foobar')35 notification.remove_message('info', 'fake')36 notification.remove_message('fake', 'fake')37 self.assertEqual(notification.messages, {'info': ['foobar']})38 notification.remove_message('info', 'foobar')39 self.assertEqual(notification.messages, {'info': []})40 def test_notification_clear_messages(self):41 notification = Notification()42 notification.add_message('info', 'foo')43 notification.add_message('info', 'bar')44 notification.add_message('warning', 'foobar')45 self.assertEqual(notification._Notification__temp, ['foobar'])46 self.assertEqual(notification.messages, {47 'info': ['foo', 'bar'],48 'warning': ['foobar']49 })50 notification.clear('info')51 self.assertEqual(notification.messages, {'warning': ['foobar']})52 self.assertEqual(notification._Notification__temp, [])53 notification.add_message('info', 'foo')54 notification.add_message('info', 'bar')55 self.assertEqual(notification._Notification__temp, ['foo', 'bar'])56 notification.clear()57 self.assertEqual(notification.messages, {})58 self.assertEqual(notification._Notification__temp, [])59 def test_notification_messages_filter(self):60 notification = Notification()61 with self.assertRaises(TypeError) as assert_error:62 notification.messages_filter()63 self.assertTrue('context' in assert_error.exception.args[0])64 notification.add_message('info', 'foo')65 notification.add_message('info', 'bar')66 notification.add_message('warning', 'foobar')67 self.assertIsInstance(notification.messages_filter('info'), Notification)68 self.assertEqual(notification._Notification__temp, ['foo', 'bar'])69 notification.messages_filter('fake')70 self.assertEqual(notification._Notification__temp, [])71 def test_notification_messages_filter_to_str(self):72 notification = Notification()73 notification.add_message('info', 'foo')74 notification.add_message('info', 'bar')75 notification.add_message('warning', 'foobar')76 self.assertEqual(77 notification.messages_filter('fake').to_str(), '')78 self.assertEqual(79 notification.messages_filter('info').to_str(), 'foo\nbar')80 self.assertEqual(81 notification.messages_filter('info').to_str(separator=';'), 'foo;bar')82 self.assertEqual(83 notification.messages_filter('info').to_str(end='!'), 'foo\nbar!')84 self.assertEqual(85 notification.messages_filter('info').to_str(';', '!'), 'foo;bar!')86 def test_notification_messages_filter_to_list(self):87 notification = Notification()88 notification.add_message('info', 'foo')89 notification.add_message('info', 'bar')90 notification.add_message('warning', 'foobar')91 self.assertEqual(92 notification.messages_filter('fake').to_list(), [])93 self.assertEqual(...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

...16 if user is not None:17 auth.login(request, user)18 return redirect('dashboard')19 else:20 messages.add_message(request, messages.ERROR,21 'Usuario ou senha invalidos')22 return render(request, 'accounts/login.html')23def logout(request):24 auth.logout(request)25 return redirect('login')26def cadastro(request):27 if request.method != 'POST':28 return render(request, 'accounts/cadastro.html')29 nome = request.POST.get('nome')30 email = request.POST.get('email')31 usuario = request.POST.get('usuario')32 senha = request.POST.get('senha')33 senha2 = request.POST.get('senha2')34 sobrenome = request.POST.get('sobrenome')35 try:36 validate_email(email)37 except:38 messages.add_message(request, messages.ERROR,39 'Email invalido')40 return render(request, 'accounts/cadastro.html')41 if nome == '' or email == '' or senha == '' or senha2 == '' or sobrenome == '':42 messages.add_message(request, messages.ERROR,43 'Preencha todos os campos')44 return render(request, 'accounts/cadastro.html')45 if senha != senha2:46 messages.add_message(request, messages.ERROR, 'Senhas nao conferem')47 return render(request, 'accounts/cadastro.html')48 if len(senha) < 6:49 messages.add_message(request, messages.ERROR,50 'Senha deve ter no minimo 6 caracteres')51 return render(request, 'accounts/cadastro.html')52 if len(usuario) < 6:53 messages.add_message(request, messages.ERROR,54 'Usuario deve ter no minimo 6 caracteres')55 return render(request, 'accounts/cadastro.html')56 if User.objects.filter(username=usuario).exists():57 messages.add_message(request, messages.ERROR,58 'Usuario ja existe')59 return render(request, 'accounts/cadastro.html')60 if User.objects.filter(email=email).exists():61 messages.add_message(request, messages.ERROR,62 'Email ja existe')63 return render(request, 'accounts/cadastro.html')64 try:65 user = User.objects.create_user(66 username=usuario, email=email, password=senha, first_name=nome, last_name=sobrenome)67 user.save()68 messages.add_message(request, messages.SUCCESS,69 'Cadastro realizado com sucesso')70 return redirect('login')71 except:72 messages.add_message(request, messages.ERROR,73 'Erro ao cadastrar usuario')74 return render(request, 'accounts/cadastro.html')75@login_required(login_url='login')76def dashboard(request):77 if request.method != 'POST':78 form = FormContato()79 return render(request, 'accounts/dashboard.html', {'form': form})80 form = FormContato(request.POST, request.FILES)81 if not form.is_valid():82 messages.add_message(request, messages.ERROR,83 'Formulario invalido')84 form = FormContato(request.POST)85 return render(request, 'accounts/dashboard.html', {'form': form})86 descricao = request.POST.get('descricao')87 if len(descricao) < 5:88 messages.add_message(request, messages.ERROR,89 'Descricao deve ter no minimo 5 caracteres')90 form = FormContato(request.POST)91 return render(request, 'accounts/dashboard.html', {'form': form})92 try:93 form.save()94 messages.add_message(request, messages.SUCCESS,95 'Contato cadastrado com sucesso')96 return redirect('dashboard')97 except:98 messages.add_message(request, messages.ERROR,99 'Erro ao enviar formulario')100 form = FormContato(request.POST)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful