How to use preload_services method in localstack

Best Python code snippet using localstack_python

test_sraix.py

Source:test_sraix.py Github

copy

Full Screen

...221 service_config = BrainServiceConfiguration("__PUBLISHEDREST__")222 service_config._classname = 'programytest.services.test_service.MockService'223 brain_config = BrainConfiguration()224 brain_config.services._services['__PUBLISHEDREST__'] = service_config225 ServiceFactory.preload_services(brain_config.services)226 root = TemplateNode()227 node = TemplateSRAIXNode()228 node._host = TemplateWordNode("hostname")229 node._method = TemplateWordNode("POST")230 node._query = TemplateWordNode('"userid":"1234567890"')231 node._header = TemplateWordNode('"Content-Type":"application/json"')232 node._body = TemplateWordNode("Hello")233 root.append(node)234 self.assertEqual("asked", node.resolve(self._client_context))235 conversation = self._client_context.bot.get_conversation(self._client_context)236 self.assertIsNotNone(conversation)237 question = Question.create_from_text(self._client_context, "Hello", self._client_context.bot.sentence_splitter)238 conversation.record_dialog(question)239 self.assertIsNotNone(conversation.current_question())240 self.assertEqual("asked", node.resolve(self._client_context))241 self.assertEqual("asked", question.property('__SUBAGENT_BODY__'))242 def test_call_GeneralRest_only_host(self):243 service_config = BrainServiceConfiguration("__PUBLISHEDREST__")244 service_config._classname = 'programytest.services.test_service.MockService'245 brain_config = BrainConfiguration()246 brain_config.services._services['__PUBLISHEDREST__'] = service_config247 ServiceFactory.preload_services(brain_config.services)248 root = TemplateNode()249 node = TemplateSRAIXNode()250 node._host = TemplateWordNode("hostname")251 root.append(node)252 self.assertEqual("asked", node.resolve(self._client_context))253 def test_call_GeneralRest_response_none(self):254 service_config = BrainServiceConfiguration("__PUBLISHEDREST__")255 service_config._classname = 'programytest.services.test_service.MockService'256 brain_config = BrainConfiguration()257 brain_config.services._services['__PUBLISHEDREST__'] = service_config258 ServiceFactory.preload_services(brain_config.services)259 root = TemplateNode()260 node = TemplateSRAIXNode()261 node._host = TemplateWordNode("hostname")262 root.append(node)263 service = ServiceFactory.get_service("__PUBLISHEDREST__")264 service.set_response(None)265 self.assertIsNone(node.resolve(self._client_context))266 def test_call_GeneralRest_response_empty(self):267 service_config = BrainServiceConfiguration("__PUBLISHEDREST__")268 service_config._classname = 'programytest.services.test_service.MockService'269 brain_config = BrainConfiguration()270 brain_config.services._services['__PUBLISHEDREST__'] = service_config271 ServiceFactory.preload_services(brain_config.services)272 root = TemplateNode()273 node = TemplateSRAIXNode()274 node._host = TemplateWordNode("hostname")275 root.append(node)276 service = ServiceFactory.get_service("__PUBLISHEDREST__")277 service.set_response("")278 self.assertEqual("", node.resolve(self._client_context))279 conversation = self._client_context.bot.get_conversation(self._client_context)280 self.assertIsNotNone(conversation)281 question = Question.create_from_text(self._client_context, "Hello", self._client_context.bot.sentence_splitter)282 conversation.record_dialog(question)283 self.assertIsNotNone(conversation.current_question())284 self.assertEqual("", node.resolve(self._client_context))285 def test_call_GeneralRest_response_default(self):286 service_config = BrainServiceConfiguration("__PUBLISHEDREST__")287 service_config._classname = 'programytest.services.test_service.MockService'288 brain_config = BrainConfiguration()289 brain_config.services._services['__PUBLISHEDREST__'] = service_config290 ServiceFactory.preload_services(brain_config.services)291 root = TemplateNode()292 node = TemplateSRAIXNode()293 node._host = TemplateWordNode("hostname")294 node._default = "unknown"295 root.append(node)296 service = ServiceFactory.get_service("__PUBLISHEDREST__")297 service.set_response("")298 self.assertEqual("unknown", node.resolve(self._client_context))299 conversation = self._client_context.bot.get_conversation(self._client_context)300 self.assertIsNotNone(conversation)301 question = Question.create_from_text(self._client_context, "Hello", self._client_context.bot.sentence_splitter)302 conversation.record_dialog(question)303 self.assertIsNotNone(conversation.current_question())304 self.assertEqual("unknown", node.resolve(self._client_context))305 self.assertEqual("unknown", question.property('__SUBAGENT_BODY__'))306 def test_call_PublishedBot(self):307 service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")308 service_config._classname = 'programytest.services.test_service.MockService'309 brain_config = BrainConfiguration()310 brain_config.services._services['__PUBLISHEDBOT__'] = service_config311 ServiceFactory.preload_services(brain_config.services)312 root = TemplateNode()313 node = TemplateSRAIXNode()314 node._botName = "testbot"315 node._locale = TemplateWordNode('ja-JP')316 node._time = TemplateWordNode('2019-01-01T00:00:00+09:00')317 node._userId = TemplateWordNode('1234567890')318 node._topic = TemplateWordNode('*')319 node._deleteVariable = TemplateWordNode('false')320 node._metadata = TemplateWordNode('1234567890')321 node._config = TemplateWordNode('{"config":{"logLevel":"debug"}}')322 node.append(TemplateWordNode("Hello"))323 root.append(node)324 self.set_collection_botnames()325 self.assertEqual("asked", node.resolve(self._client_context))326 conversation = self._client_context.bot.get_conversation(self._client_context)327 self.assertIsNotNone(conversation)328 question = Question.create_from_text(self._client_context, "Hello", self._client_context.bot.sentence_splitter)329 conversation.record_dialog(question)330 self.assertIsNotNone(conversation.current_question())331 service = ServiceFactory.get_service("__PUBLISHEDBOT__")332 service.set_response('{"response": "asked"}')333 self.assertEqual("asked", node.resolve(self._client_context))334 self.assertEqual('{"testbot": {"response": "asked"}}', question.property('__SUBAGENT_EXTBOT__'))335 def test_call_PublishedBot_only_botname(self):336 service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")337 service_config._classname = 'programytest.services.test_service.MockService'338 brain_config = BrainConfiguration()339 brain_config.services._services['__PUBLISHEDBOT__'] = service_config340 ServiceFactory.preload_services(brain_config.services)341 root = TemplateNode()342 node = TemplateSRAIXNode()343 node._botName = "testbot"344 node._userId = TemplateWordNode('1234567890')345 root.append(node)346 node.append(TemplateWordNode("Hello"))347 self.set_collection_botnames()348 self.assertEqual("asked", node.resolve(self._client_context))349 def test_call_PublishedBot_topic(self):350 service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")351 service_config._classname = 'programytest.services.test_service.MockService'352 brain_config = BrainConfiguration()353 brain_config.services._services['__PUBLISHEDBOT__'] = service_config354 ServiceFactory.preload_services(brain_config.services)355 root = TemplateNode()356 node = TemplateSRAIXNode()357 node._botName = "testbot"358 node._userId = TemplateWordNode('1234567890')359 node.append(TemplateWordNode("Hello"))360 root.append(node)361 conversation = self._client_context.bot.get_conversation(self._client_context)362 conversation.set_property('topic', 'morning')363 self.set_collection_botnames()364 self.assertEqual("asked", node.resolve(self._client_context))365 node._topic = TemplateWordNode("evening")366 self.assertEqual("asked", node.resolve(self._client_context))367 def test_call_PublishedBot_deleteValiables(self):368 service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")369 service_config._classname = 'programytest.services.test_service.MockService'370 brain_config = BrainConfiguration()371 brain_config.services._services['__PUBLISHEDBOT__'] = service_config372 ServiceFactory.preload_services(brain_config.services)373 root = TemplateNode()374 node = TemplateSRAIXNode()375 node._botName = "testbot"376 node._userId = TemplateWordNode('1234567890')377 node._deleteVariable = TemplateWordNode('true')378 node.append(TemplateWordNode("Hello"))379 root.append(node)380 self.set_collection_botnames()381 self.assertEqual("asked", node.resolve(self._client_context))382 def test_call_PublishedBot_response_none(self):383 service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")384 service_config._classname = 'programytest.services.test_service.MockService'385 brain_config = BrainConfiguration()386 brain_config.services._services['__PUBLISHEDBOT__'] = service_config387 ServiceFactory.preload_services(brain_config.services)388 root = TemplateNode()389 node = TemplateSRAIXNode()390 node._botName = "testbot"391 node._userId = TemplateWordNode('1234567890')392 node.append(TemplateWordNode("Hello"))393 root.append(node)394 service = ServiceFactory.get_service("__PUBLISHEDBOT__")395 service.set_response(None)396 self.set_collection_botnames()397 self.assertIsNone(node.resolve(self._client_context))398 def test_call_PublishedBot_response_empty(self):399 service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")400 service_config._classname = 'programytest.services.test_service.MockService'401 brain_config = BrainConfiguration()402 brain_config.services._services['__PUBLISHEDBOT__'] = service_config403 ServiceFactory.preload_services(brain_config.services)404 root = TemplateNode()405 node = TemplateSRAIXNode()406 node._botName = "testbot"407 node._userId = TemplateWordNode('1234567890')408 node.append(TemplateWordNode("Hello"))409 root.append(node)410 service = ServiceFactory.get_service("__PUBLISHEDBOT__")411 service.set_response("")412 self.set_collection_botnames()413 self.assertEqual("", node.resolve(self._client_context))414 conversation = self._client_context.bot.get_conversation(self._client_context)415 self.assertIsNotNone(conversation)416 question = Question.create_from_text(self._client_context, "Hello", self._client_context.bot.sentence_splitter)417 conversation.record_dialog(question)418 self.assertIsNotNone(conversation.current_question())419 self.assertEqual("", node.resolve(self._client_context))420 def test_call_PublishedBot_response_default(self):421 service_config = BrainServiceConfiguration("__PUBLISHEDBOT__")422 service_config._classname = 'programytest.services.test_service.MockService'423 brain_config = BrainConfiguration()424 brain_config.services._services['__PUBLISHEDBOT__'] = service_config425 ServiceFactory.preload_services(brain_config.services)426 root = TemplateNode()427 node = TemplateSRAIXNode()428 node._botName = "testbot"429 node._userId = TemplateWordNode('1234567890')430 node._default = "unknown"431 node.append(TemplateWordNode("Hello"))432 root.append(node)433 service = ServiceFactory.get_service("__PUBLISHEDBOT__")434 service.set_response("")435 self.set_collection_botnames()436 self.assertEqual("unknown", node.resolve(self._client_context))437 conversation = self._client_context.bot.get_conversation(self._client_context)438 self.assertIsNotNone(conversation)439 question = Question.create_from_text(self._client_context, "Hello", self._client_context.bot.sentence_splitter)440 conversation.record_dialog(question)441 self.assertIsNotNone(conversation.current_question())442 self.assertEqual("unknown", node.resolve(self._client_context))443 self.assertEqual("unknown", question.property('__SUBAGENT_EXTBOT__.testbot'))444 def test_call_CustomService(self):445 service_config = BrainServiceConfiguration("mock")446 service_config._classname = 'programytest.services.test_service.MockService'447 brain_config = BrainConfiguration()448 brain_config.services._services['mock'] = service_config449 ServiceFactory.preload_services(brain_config.services)450 root = TemplateNode()451 node = TemplateSRAIXNode()452 node._service = "mock"453 node.append(TemplateWordNode("Hello"))454 root.append(node)455 self.assertEqual("asked", node.resolve(self._client_context))456 conversation = self._client_context.bot.get_conversation(self._client_context)457 self.assertIsNotNone(conversation)458 question = Question.create_from_text(self._client_context, "Hello", self._client_context.bot.sentence_splitter)459 conversation.record_dialog(question)460 self.assertIsNotNone(conversation.current_question())461 self.assertEqual("asked", node.resolve(self._client_context))462 self.assertEqual('asked', question.property('__SUBAGENT__.mock'))463 def test_call_CustomService_response_none(self):464 service_config = BrainServiceConfiguration("mock")465 service_config._classname = 'programytest.services.test_service.MockService'466 brain_config = BrainConfiguration()467 brain_config.services._services['mock'] = service_config468 ServiceFactory.preload_services(brain_config.services)469 root = TemplateNode()470 node = TemplateSRAIXNode()471 node._service = "mock"472 node.append(TemplateWordNode("Hello"))473 root.append(node)474 service = ServiceFactory.get_service("mock")475 service.set_response(None)476 self.assertEqual(None, node.resolve(self._client_context))477 def test_call_CustomService_response_empty(self):478 service_config = BrainServiceConfiguration("mock")479 service_config._classname = 'programytest.services.test_service.MockService'480 brain_config = BrainConfiguration()481 brain_config.services._services['mock'] = service_config482 ServiceFactory.preload_services(brain_config.services)483 root = TemplateNode()484 node = TemplateSRAIXNode()485 node._service = "mock"486 node.append(TemplateWordNode("Hello"))487 root.append(node)488 service = ServiceFactory.get_service("mock")489 service.set_response("")490 self.assertEqual("", node.resolve(self._client_context))491 conversation = self._client_context.bot.get_conversation(self._client_context)492 self.assertIsNotNone(conversation)493 question = Question.create_from_text(self._client_context, "Hello", self._client_context.bot.sentence_splitter)494 conversation.record_dialog(question)495 self.assertIsNotNone(conversation.current_question())496 self.assertEqual("", node.resolve(self._client_context))497 def test_call_CustomService_response_default(self):498 service_config = BrainServiceConfiguration("mock")499 service_config._classname = 'programytest.services.test_service.MockService'500 brain_config = BrainConfiguration()501 brain_config.services._services['mock'] = service_config502 ServiceFactory.preload_services(brain_config.services)503 root = TemplateNode()504 node = TemplateSRAIXNode()505 node._service = "mock"506 node._default = "unknown"507 node.append(TemplateWordNode("Hello"))508 root.append(node)509 service = ServiceFactory.get_service("mock")510 service.set_response("")511 self.assertEqual("unknown", node.resolve(self._client_context))512 conversation = self._client_context.bot.get_conversation(self._client_context)513 self.assertIsNotNone(conversation)514 question = Question.create_from_text(self._client_context, "Hello", self._client_context.bot.sentence_splitter)515 conversation.record_dialog(question)516 self.assertIsNotNone(conversation.current_question())...

Full Screen

Full Screen

service.py

Source:service.py Github

copy

Full Screen

...18 """19class ServiceFactory(object):20 services = {}21 @classmethod22 def preload_services(cls, services_config):23 YLogger.debug(None, "In preload_services in ServiceFactory")24 loader = ClassLoader()25 for service_name in services_config.services():26 name = service_name.upper()27 service_config = services_config.service(service_name)28 YLogger.debug(None, "Preloading service [%s] -> [%s]", name, service_config.classname)29 meta_class = loader.instantiate_class(service_config.classname)30 new_class = meta_class(service_config)31 ServiceFactory.services[name] = new_class32 @classmethod33 def service_exists(cls, name):34 return bool(name.upper() in ServiceFactory.services)\35 @classmethod36 def get_service(cls, service):...

Full Screen

Full Screen

test_service.py

Source:test_service.py Github

copy

Full Screen

...12 service_config = BrainServiceConfiguration("mock")13 service_config._classname = 'programytest.services.test_service.MockService'14 brain_config = BrainConfiguration()15 brain_config.services._services['mock'] = service_config16 ServiceFactory.preload_services(brain_config.services)17 mock_service = ServiceFactory.get_service("mock")18 self.assertIsNotNone(mock_service)...

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