def test_json_object(self): """Check if we return the right type of each JSON.""" # A simple JSON object self.assertTrue(is_json_object(json.loads('{"a": "b"}'))) # A more complex JSON object self.assertTrue(is_json_object(json.loads('{"bar":["baz", null, 1.0, 2]}'))) # noqa # A JSON value, which is not an object self.assertFalse(is_json_object(json.loads('null')))
def build_details(details): """Populate and return the Browser Configuration section template. If we get JSON, we try to pull out the console logs before building the rest of the details. """ try: content = json.loads(details) if is_json_object(content): content.pop('consoleLog', None) except ValueError: # if we got a ValueError, details was a string, so just pass it # into get_details below content = details return """<details> <summary>Browser Configuration</summary> {details_list_items} </details>""".format(details_list_items=get_details_list(content))
def build_details(details): """Populate and return the Browser Configuration section template. If we get JSON, we try to pull out the console logs before building the rest of the details. """ console_logs = None try: content = json.loads(details) if is_json_object(content): console_logs = content.pop('consoleLog', None) except ValueError: # if we got a ValueError, details was a string, so just pass it # into get_details below content = details return """<details> <summary>Browser Configuration</summary> <ul> {details_list_items} </ul> {console_section} </details>""".format(details_list_items=get_details(content), console_section=get_console_section(console_logs))