def test_try_json_with_keys_no_such_key(self): """ ``try_json_with_keys``, if given valid JSON, but keys that are not present in the loaded JSON, will return None as a message """ self.assertIsNone(try_json_with_keys(json.dumps([1, 2, 3]), ('a',))) self.assertIsNone( try_json_with_keys(json.dumps({'a': [1, 2, 3]}), ('a', 4)))
def test_try_json_with_keys_success(self): """ ``try_json_with_keys`` will attempt to load some JSON, and pull the value at the given key set out. """ json_blob = {'this': {'is': {'a': {'deeply': {'nested': 'dict'}}}}} message = try_json_with_keys(json.dumps(json_blob), ('this', 'is', 'a', 'deeply', 'nested')) self.assertEqual(message, 'dict')
def check_invalid_nodes(exc_info): code = exc_info[1].code body = exc_info[1].body if code == 400: message = try_json_with_keys(body, ["validationErrors", "messages", 0]) if message is not None: match = _CLB_NODE_REMOVED_PATTERN.match(message) if match: removed = concat([group.split(",") for group in match.groups()]) return remove_clb_nodes(lb_id, set(node_ids) - set(removed)) six.reraise(*exc_info)
def check_invalid_nodes(exc_info): code = exc_info[1].code body = exc_info[1].body if code == 400: message = try_json_with_keys(body, ["validationErrors", "messages", 0]) if message is not None: match = _CLB_NODE_REMOVED_PATTERN.match(message) if match: removed = concat( [group.split(',') for group in match.groups()]) return remove_clb_nodes(lb_id, set(node_ids) - set(removed)) six.reraise(*exc_info)
def test_try_json_with_keys_invalid_json(self): """ ``try_json_with_keys``, if given invalid JSON, will return None as a message """ self.assertIsNone(try_json_with_keys('s', ('s',)))