How to use parse_json_or_yaml method in localstack

Best Python code snippet using localstack_python

test_common.py

Source:test_common.py Github

copy

Full Screen

...224 self.assertEqual("None", fn(None))225 self.assertEqual("", fn(""))226 def test_parse_json_or_yaml_with_json(self):227 markup = """{"foo": "bar", "why": 42, "mylist": [1,2,3]}"""228 doc = common.parse_json_or_yaml(markup)229 self.assertDictEqual({"foo": "bar", "why": 42, "mylist": [1, 2, 3]}, doc)230 def test_parse_json_or_yaml_with_yaml(self):231 markup = """232 foo: bar233 why: 42234 mylist:235 - 1236 - 2237 - 3238 """239 doc = common.parse_json_or_yaml(markup)240 self.assertDictEqual({"foo": "bar", "why": 42, "mylist": [1, 2, 3]}, doc)241 def test_parse_json_or_yaml_with_invalid_syntax_returns_content(self):242 markup = "<a href='foobar'>baz</a>"243 doc = common.parse_json_or_yaml(markup)244 self.assertEqual(markup, doc) # FIXME: not sure if this is good behavior245 def test_parse_json_or_yaml_with_empty_string_returns_none(self):246 doc = common.parse_json_or_yaml("")247 self.assertIsNone(doc)248 def test_format_bytes(self):249 fn = common.format_bytes250 self.assertEqual("1B", fn(1))251 self.assertEqual("100B", fn(100))252 self.assertEqual("999B", fn(999))253 self.assertEqual("1KB", fn(1e3))254 self.assertEqual("1MB", fn(1e6))255 self.assertEqual("10MB", fn(1e7))256 self.assertEqual("100MB", fn(1e8))257 self.assertEqual("1GB", fn(1e9))258 self.assertEqual("1TB", fn(1e12))259 # comma values260 self.assertEqual("1.1TB", fn(1e12 + 1e11))...

Full Screen

Full Screen

internal.py

Source:internal.py Github

copy

Full Screen

...99 if download_url:100 try:101 LOG.debug("Attempting to download CloudFormation template URL: %s", download_url)102 template_body = to_str(requests.get(download_url).content)103 template_body = parse_json_or_yaml(template_body)104 params["templateBody"] = json.dumps(template_body)105 except Exception as e:106 msg = f"Unable to download CloudFormation template URL: {e}"107 LOG.info(msg)108 params["errorMessage"] = json.dumps(msg.replace("\n", " - "))109 # using simple string replacement here, for simplicity (could be replaced with, e.g., jinja)110 for key, value in params.items():111 deploy_html = deploy_html.replace(f"<{key}>", value)112 result = requests_response(deploy_html)113 return result114class LocalstackResources(ResourceRouter):115 """116 Router for localstack-internal HTTP resources.117 """...

Full Screen

Full Screen

provider_asf.py

Source:provider_asf.py Github

copy

Full Screen

...25 self, context: RequestContext, request: TestInvokeMethodRequest26 ) -> TestInvokeMethodResponse:27 invocation_context = to_invocation_context(context.request)28 invocation_context.method = request["httpMethod"]29 if data := parse_json_or_yaml(to_str(invocation_context.data or b"")):30 orig_data = data31 if path_with_query_string := orig_data.get("pathWithQueryString"):32 invocation_context.path_with_query_string = path_with_query_string33 invocation_context.data = data.get("body")34 invocation_context.headers = orig_data.get("headers", {})35 result = invoke_rest_api_from_request(invocation_context)36 # TODO: implement the other TestInvokeMethodResponse parameters37 # * multiValueHeaders: Optional[MapOfStringToList]38 # * log: Optional[String]39 # * latency: Optional[Long]40 return TestInvokeMethodResponse(41 status=result.status_code,42 headers=dict(result.headers),43 body=to_str(result.content),...

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