Beispiel #1
0
    def test_parse_json_or_yaml_with_json(self):
        markup = """{"foo": "bar", "why": 42, "mylist": [1,2,3]}"""

        doc = common.parse_json_or_yaml(markup)
        self.assertDictEqual({
            "foo": "bar",
            "why": 42,
            "mylist": [1, 2, 3]
        }, doc)
Beispiel #2
0
 def test_parse_json_or_yaml_with_yaml(self):
     markup = """
     foo: bar
     why: 42
     mylist:
         - 1
         - 2
         - 3
     """
     doc = common.parse_json_or_yaml(markup)
     assert doc == {"foo": "bar", "why": 42, "mylist": [1, 2, 3]}
Beispiel #3
0
    def on_get(self, request):
        from localstack.utils.aws.aws_responses import requests_response

        path = request.path
        data = request.data
        headers = request.headers

        deploy_html_file = os.path.join(constants.MODULE_MAIN_PATH, "services",
                                        "cloudformation", "deploy.html")
        deploy_html = load_file(deploy_html_file)
        req_params = parse_request_data("GET", path, data, headers)
        params = {
            "stackName": "stack1",
            "templateBody": "{}",
            "errorMessage": "''",
            "regions": json.dumps(sorted(list(config.VALID_REGIONS))),
        }

        download_url = req_params.get("templateURL")
        if download_url:
            try:
                LOG.debug(
                    "Attempting to download CloudFormation template URL: %s",
                    download_url)
                template_body = to_str(requests.get(download_url).content)
                template_body = parse_json_or_yaml(template_body)
                params["templateBody"] = json.dumps(template_body)
            except Exception as e:
                msg = f"Unable to download CloudFormation template URL: {e}"
                LOG.info(msg)
                params["errorMessage"] = json.dumps(msg.replace("\n", " - "))

        # using simple string replacement here, for simplicity (could be replaced with, e.g., jinja)
        for key, value in params.items():
            deploy_html = deploy_html.replace(f"<{key}>", value)
        result = requests_response(deploy_html)
        return result
Beispiel #4
0
 def test_parse_json_or_yaml_with_empty_string_returns_none(self):
     doc = common.parse_json_or_yaml("")
     assert doc is None
Beispiel #5
0
 def test_parse_json_or_yaml_with_invalid_syntax_returns_content(self):
     markup = "<a href='foobar'>baz</a>"
     doc = common.parse_json_or_yaml(markup)
     assert doc == markup  # FIXME: not sure if this is good behavior
Beispiel #6
0
    def test_parse_json_or_yaml_with_json(self):
        markup = """{"foo": "bar", "why": 42, "mylist": [1,2,3]}"""

        doc = common.parse_json_or_yaml(markup)
        assert doc == {"foo": "bar", "why": 42, "mylist": [1, 2, 3]}