def test_json_parse__json_format__json_dumps__json_loads(self): data = {'answer': 42} assert json_dumps(data) == '{\n "answer": 42\n}' assert json_format(data) == '{\n "answer": 42\n}' assert json_parse(json_dumps(data)) == data assert json_loads(json_dumps(data)) == data assert json_dumps(None) is None assert json_format(None) is None assert json_parse(None) == {} assert json_loads(None) == {}
def test_get_valid_endpoints(self): test_ips = ["52.51.76.83", "34.245.236.153", "34.242.222.23"] endpoints = [] for ip in test_ips: endpoints.append({'IP': ip, "Port": "8080"}) valid_endpoints = {'Endpoints': endpoints} endpoint_string = json_to_str(valid_endpoints) result = self.configure_env.get_valid_endpoints(endpoint_string) responsive_endpoints = json_parse(result).get('Endpoints') assert len(responsive_endpoints) > 0 for enpoint in responsive_endpoints: assert enpoint in endpoints
def dashboard(self, dashboard_name): try: dashboard_data = self.client().get_dashboard( DashboardName=dashboard_name) dashboard = { "arn": dashboard_data.get('DashboardArn'), "widgets": (json_parse( dashboard_data.get('DashboardBody')).get('widgets')), "name": dashboard_data.get('DashboardName') } from osbot_utils.utils.Dev import pprint #pprint(dashboard_data) return dashboard except Exception: # can't use botocore.errorfactory.ResourceNotFound because that is not exposed return {}
def test_event_put(self): with Temp_SQS_Queue(fifo=True) as queue: target_id = queue.name() target_arn = queue.arn() rule_name = self.rule_name source_arn = self.events.rule_arn(self.rule_name) service = 'events.amazonaws.com' resource = queue.arn() target_attributes = {'SqsParameters': {'MessageGroupId': 'string'}} queue.permission_add_for_service(source_arn=source_arn, service=service, resource=resource) self.events.target_create(rule_name=rule_name, target_id=target_id, target_arn=target_arn, target_attributes=target_attributes) #assert queue.url() == SQS().queue_url_from_queue_arn(queue_arn=queue.arn()) event_data = f'{{"id":"event_1", "value***": "{random_string()}"}}' event = { 'Time': date_time_now(), 'Source': self.rule_event_source, "DetailType": "myTestType", 'Detail': event_data, } self.events.events_put([event]) self.events.events_put([event]) self.events.events_put([event]) wait( 0.5 ) # todo see if there is a better way to wait for messages to be available assert queue.size() > 0 message = queue.pop() assert message.get('detail') == json_parse(event_data) self.events.target_delete(rule_name=rule_name, target_id=target_id)
def attribute_base64_json(self, key): return json_parse(self.attribute_base64(key))
def services(self): return json_parse(self.kubectl('get services -A -o json'))
def pods(self): return json_parse(self.kubectl('get pods -A -o json'))
def persistent_volumes(self): return json_parse(self.kubectl('get pv -A -o json'))
def nodes(self): return json_parse(self.kubectl('get nodes -A -o json'))
def events(self): return json_parse(self.kubectl('get events -A -o json'))
def deployments(self): return json_parse(self.kubectl('get deployments -A -o json'))