def test_get_str_value(self): """Test getting an expected string, including Python to js-style boolean. Note: key (output) and value (input) are in an unexpected order, just to keep the data structure valid. """ tests = [{ '1': 1 }, { 'null': None }, { 'true': True }, { 'false': False }, { '': '' }, { 'cool': 'cool' }, { u'\U0001f480': u'💀' }] for test in tests: for output, browser_input in test.iteritems(): self.assertEqual(get_str_value(browser_input), output)
def test_get_str_value(self): """Get an expected string, including Python to js-style boolean. Note: key (output) and value (input) are in an unexpected order, just to keep the data structure valid. """ tests = [{'1': 1}, {'null': None}, {'true': True}, {'false': False}, {'': ''}, {'cool': 'cool'}, {u'\U0001f480': u'💀'}] for test in tests: for output, browser_input in test.iteritems(): self.assertEqual(get_str_value(browser_input), output)
def get_details(details): """Return details content. * If a dict, as a formatted string * Otherwise as a string as-is. """ content = details rv = '' try: rv = ''.join(['<li>{k}: {v}</li>'.format(k=k, v=get_str_value(v)) for k, v in details.items()]) except AttributeError: return '<li>{content}</li>'.format(content=content) return rv
def get_details(details_string): """Return details content. * If JSON as a formatted string * Otherwise as a string as-is. """ content = details_string rv = '' try: details = json.loads(content) rv = ''.join(['<li>{k}: {v}</li>'.format(k=k, v=get_str_value(v)) for k, v in details.items()]) except ValueError: return content return rv