Example #1
0
    def test_run_with_trace(self):
        def rainbow(node):
            return Color.hsv(node.time.fraction * 0.8, 0.4, 0.9)

        def greyscale(node):
            return Color.hsv(0, 0, node.time.fraction / 2 + 0.4)

        def orange_green(node):
            return Color( 0.2 + node.time.fraction * 0.8,
                          0.2 + node.calls.fraction * 0.4 ,
                          0.2)

        from pycallgraph.output import GraphvizOutput
        from pycallgraph import PyCallGraph

        graphviz = GraphvizOutput()
        graphviz.output_file = 'basic.png'
        graphviz.edge_color_func = lambda e: Color(0, 0, 0)
        #graphviz.node_color_func = rainbow #orange_green # greyscale

        config = Config(include_stdlib=True)#max_depth=10)
        config.trace_filter = GlobbingFilter(include=['osbot*','pbx*','boto3*'])

        with PyCallGraph(output=graphviz, config=config):
            try:
                self.handler.run(Test_Data.api_gw_payload_help)
            except Exception as error:
                Dev.pprint(error)
 def tearDown(self):
     if self.result is not None:
         Dev.pprint(self.result)
     if self.png_data:
         png_file = '/tmp/lambda_png_file.png'
         with open(png_file, "wb") as fh:
             fh.write(base64.decodebytes(self.png_data.encode()))
Example #3
0
 def test_process_posted_body(self):
     #process_posted_body is an old method that uses an older lambda function
     body   = "payload=%7B%22type%22%3A%22interactive_message%22%2C%22actions%22%3A%5B%7B%22name%22%3A%22game%22%2C%22type%22%3A%22button%22%2C%22value%22%3A%22chess%22%7D%5D%2C%22callback_id%22%3A%22wopr_game%22%2C%22team%22%3A%7B%22id%22%3A%22T7F3AUXGV%22%2C%22domain%22%3A%22gs-cst%22%7D%2C%22channel%22%3A%7B%22id%22%3A%22GDL2EC3EE%22%2C%22name%22%3A%22privategroup%22%7D%2C%22user%22%3A%7B%22id%22%3A%22U7ESE1XS7%22%2C%22name%22%3A%22dinis.cruz%22%7D%2C%22action_ts%22%3A%221541065372.601061%22%2C%22message_ts%22%3A%221541065370.003300%22%2C%22attachment_id%22%3A%221%22%2C%22token%22%3A%22a2J5DIEEJZtKOSZHZBqgDnVz%22%2C%22is_app_unfurl%22%3Afalse%2C%22original_message%22%3A%7B%22text%22%3A%22Would+you+like+to+play+a+game%3F%22%2C%22username%22%3A%22gs-bot%22%2C%22bot_id%22%3A%22BDKLUMX4K%22%2C%22attachments%22%3A%5B%7B%22callback_id%22%3A%22wopr_game%22%2C%22fallback%22%3A%22You+are+unable+to+choose+a+game%22%2C%22text%22%3A%22Choose+a+game+to+play%22%2C%22id%22%3A1%2C%22color%22%3A%223AA3E3%22%2C%22actions%22%3A%5B%7B%22id%22%3A%221%22%2C%22name%22%3A%22game%22%2C%22text%22%3A%22Chess%22%2C%22type%22%3A%22button%22%2C%22value%22%3A%22chess%22%2C%22style%22%3A%22%22%7D%2C%7B%22id%22%3A%222%22%2C%22name%22%3A%22game%22%2C%22text%22%3A%22Falken%27s+Maze%22%2C%22type%22%3A%22button%22%2C%22value%22%3A%22maze%22%2C%22style%22%3A%22%22%7D%2C%7B%22id%22%3A%223%22%2C%22name%22%3A%22game%22%2C%22text%22%3A%22Thermonuclear+War%22%2C%22type%22%3A%22button%22%2C%22value%22%3A%22war%22%2C%22style%22%3A%22danger%22%2C%22confirm%22%3A%7B%22text%22%3A%22Wouldn%27t+you+prefer+a+good+game+of+chess%3F%22%2C%22title%22%3A%22Are+you+sure%3F%22%2C%22ok_text%22%3A%22Yes%22%2C%22dismiss_text%22%3A%22No%22%7D%7D%5D%7D%5D%2C%22type%22%3A%22message%22%2C%22subtype%22%3A%22bot_message%22%2C%22ts%22%3A%221541065370.003300%22%7D%2C%22response_url%22%3A%22https%3A%5C%2F%5C%2Fhooks.slack.com%5C%2Factions%5C%2FT7F3AUXGV%5C%2F470483082583%5C%2FKXtEUP57fU3b70xdgX2gEDJl%22%2C%22trigger_id%22%3A%22469260156548.253112983573.23109aa28271c3a79b6a8a308dc78846%22%7D"
     result = self.api.process_posted_body(body)
     Dev.pprint(result)
     #import json
     #Dev.pprint(json.loads(result))
Example #4
0
    async def test_open_jira_page(self):
        from osbot_aws.apis.Secrets import Secrets
        self.api = API_Browser(headless=False)

        login_needed = False
        self.secrets_id = 'GS_BOT_GS_JIRA'

        (server, username, password) = Secrets(
            self.secrets_id).value_from_json_string().values()

        if login_needed:
            Dev.pprint(server, username, password)
            await self.api.open(server + '/login.jsp')
            page = await self.api.page()
            await page.type('#login-form-username', username)
            await page.type('#login-form-password', password)
            await page.click('#login-form-submit')

        #await self.api.open(server + '/browse/GSP-95')
        #page = await self.api.page()
        #await self.api.js_execute("$('#show-more-links-link').click()")
        #from time import sleep
        #sleep(1)
        await self.api.page_size(2000, 3000)

        await self.api.screenshot(
            file_screenshot='/tmp/tmp-jira-screenshot.png', full_page=True)
Example #5
0
    def _show_google_calendar(calendar_data,
                              team_id=None,
                              channel=None,
                              headless=True):
        #load_dependencies(['syncer', 'requests', 'gmail']);
        from osbot_browser.view_helpers.Full_Calendar import Full_Calendar

        full_calendar = Full_Calendar(headless=headless)
        full_calendar.load_page()

        events = []
        for event in calendar_data:
            start = event.get('start').get('date')
            end = event.get('end').get('date')
            if start is None:
                start = event.get('start').get('dateTime')
                end = event.get('end').get('dateTime')
            events.append({
                "title": event.get('summary'),
                "start": start,
                "end": end
            })

        Dev.pprint(events)
        # events = gcalendar.next_10()
        full_calendar.invoke_js('show_calendar', events)
        full_calendar.browser_width(1000, 700)
        return full_calendar.send_screenshot_to_slack(team_id=team_id,
                                                      channel=channel)
Example #6
0
    def test_fixed__bug_cache_issue_in_lambdas(self):
        payload = {"params": ["go_js", "graph_MKF", "default"]}
        self.png_data = Lambda('browser.lambda_browser').invoke(payload)
        Dev.pprint(self.png_data)

        self.png_data = Lambda('browser.lambda_browser').invoke(payload)
        Dev.pprint(self.png_data)
Example #7
0
 def test_get_graph_data(self):
     graph_name = 'graph_MKF'  # small          ( 20 nodes,  27 edges)
     #graph_name = 'graph_YT4'            # large one      (199 nodes, 236 edges)
     #graph_name = 'graph_VZ5'            # very large one (367 nodes, 653 edges)
     result = self.vis_js.get_graph_data(graph_name)
     Dev.pprint("{0} nodes, {1} edges".format(len(result.get('nodes')),
                                              len(result.get('edges'))))
Example #8
0
 def test_zip_files(self):
     target_file = '/tmp/test_zip.zip'
     Files.delete(target_file)
     assert Files.exists(target_file) is False
     Dev.pprint(Files.zip_files('..', '*.py', '/tmp/test_zip.zip'))
     assert Files.exists(target_file) is True
     Files.delete(target_file)
     assert Files.exists(target_file) is False
 def test_update_and_invoke(self):
     file_id = '1yDxu5YxL9FxY5wQ1EEQlAYGt3flIsm2VTyWwPny5RLA'
     result = self.simple_test.invoke(
         {'queryStringParameters': {
             'file_id': file_id
         }})
     message = Misc.json_load(result.get('body'))
     Dev.pprint(message)
 async def sync__await_for_element(self, selector, timeout=10000):
     page = await self.page()
     try:
         await page.waitForSelector(selector, {'timeout': timeout })
         return True
     except Exception as error:
         Dev.print("[Errpr][sync__await_for_element] {0}".format(error))
         return False
Example #11
0
    def test__delete_temp_png_files(self):
        s3_bucket = 'gs-lambda-tests'

        tmp_files = S3().find_files(s3_bucket, S3().tmp_file_folder)
        for tmp_file in tmp_files:
            S3().file_delete(s3_bucket, tmp_file)

        Dev.pprint(S3().find_files(s3_bucket, S3().tmp_file_folder))
 def test_screenshot(self):
     team_id = 'T7F3AUXGV'
     channel = 'DDKUZTK6X'
     url = 'https://www.google.co.uk/aaa'
     #url = 'https://news.bbc.co.uk/aaa'
     #url = 'http://visjs.org/'
     payload = {"params": ['screenshot', url,], 'data': {'channel':channel, 'team_id': team_id}}
     result = self.lambda_browser.invoke(payload)
     Dev.pprint(result)
Example #13
0
    def test_build_start(self):
        build_id = self.code_build.build_start()
        build_info = self.code_build.build_wait_for_completion(build_id, 1, 60)
        build_phases = build_info.get('phases')

        phase = build_phases.pop(-2)

        Dev.pprint(phase.get('phaseType'), phase.get('phaseStatus'),
                   phase.get('contexts')[0].get('message'))
 def test_viva_graph(self):
     graph_name = 'graph_XKW'
     graph_name = 'graph_7AN'  # 74 nodes
     #graph_name = 'graph_HDS' # very large graph
     #graph_name = 'graph_37V' # with `1617` nodes and `2907` edges,
     #graph_name = 'graph_VQW'
     params = [graph_name, 'default']
     result = self.browser_commands.viva_graph(params=params)
     Dev.pprint(result)
Example #15
0
 def resolve_command_method(self, command):
     try:
         method_name = command.split(' ')[0].split('\n')[0]
         method_name = self.resolve_command_shortcuts(method_name)
         from osbot.api.GS_Bot_Commands import GS_Bot_Commands
         return getattr(GS_Bot_Commands, method_name)
     except AttributeError as error:
         Dev.pprint(error)
         return None
Example #16
0
 def test_show_jira_graph(self):
     label_key = 'Issue Type'
     label_key = 'Summary'
     graph_name = 'graph_MKF'
     #graph_name = 'graph_YT4'
     #graph_name = 'graph_XKW'
     result = self.vis_js.show_jira_graph(graph_name, label_key=label_key)
     #result = self.vis_js.send_screenshot_to_slack(None, None)
     Dev.print(result)
 def add_notification(source_arn):
     result = lambda_obj._lambda.client().permission_add(
         FunctionName=lambda_arn,
         StatementId='1',
         Action='lambda:InvokeFunction',
         Principal='s3.amazonaws.com',
         SourceArn=source_arn,
         SourceAccount=IAM().account_id())
     Dev.pprint(result)
Example #18
0
 def tearDown(self):
     if self.png_data:
         png_file = '/tmp/tmp-jira-screenshot.png'
         with open(png_file, "wb") as fh:
             fh.write(base64.decodebytes(self.png_data.encode()))
         Dev.pprint("Png data with size {0} saved to {1}".format(
             len(self.png_data), png_file))
     if self.result:
         Dev.print(self.result)
    def tearDown(self):
        if self.result is not None:
            Dev.pprint(self.result)

        if self.png_data:
            self.png_file = '/tmp/lambda_png_file.png'
            with open(self.png_file, "wb") as fh:
                fh.write(base64.decodebytes(self.png_data.encode()))
                Dev.pprint('Saved png file with size {0} to {1}'.format(
                    len(self.png_data), self.png_file))
Example #20
0
 def build_wait_for_completion(self, build_id, sleep_for=0.5, max_attempts=20, log_status=False):
     for i in range(0,max_attempts):
         build_info    = self.build_info(build_id)
         build_status  = build_info.get('buildStatus')
         current_phase = build_info.get('currentPhase')
         if log_status:
             Dev.pprint("[{0}] {1} {2}".format(i,build_status,current_phase))
         if build_status != 'IN_PROGRESS':
             return build_info
         sleep(sleep_for)
     return None
Example #21
0
    def exec_command(self):
        print('******* In Update_Sheet (test) **** [Start]')
        file_id = os.environ.get('file_id')
        command = os.environ.get('command')

        if file_id is None or command is None:
            Dev.pprint('**** missing file_id or command environment variables****')
        else:
            result = Run_Command(file_id).run(command)
            Dev.pprint('****** result*****', result)

        return ":point-right: Loaded data from jira completed ... (please check it)"
    def test_vis_js(self):
        nodes = [{'id': '123', 'label': 'vis js\n via lambda'},
                 {'id': 'aaa', 'label': 'another node'}]
        edges = [{'from': '123', 'to': 'aaa'}]

        options = {'nodes': {'shape': 'box'}}
        data = {'nodes': nodes, 'edges': edges, 'options': options }

        payload = { "params" : ['vis_js', json.dumps(data)]}
        png_data = self.lambda_browser.update_with_src().invoke(payload)
        Dev.pprint(png_data)
        self._save_png_file(png_data)
    def test_deploy_lambda_functions(self):
        targets = [
            'osbot_browser.lambdas.lambda_browser',
        ]
        result = ""
        for target in targets:
            Deploy(target).deploy()
            result += " • {0}\n".format(target)

        text = ":hotsprings: [osbot-gsuite] updated lambda functions"
        attachments = [{'text': result, 'color': 'good'}]
        slack_message(text, attachments)  # gs-bot-tests
        Dev.pprint(text, attachments)
    def test_update_and_invoke(self):
        deploy = Deploy()
        deploy.oss_setup.setup_test_environment()
        deploy.deploy_lambda_png_to_slack()

        png_file = '/tmp/lambda_png_file.png'
        png_data = base64.b64encode(open(png_file, 'rb').read()).decode()
        Dev.pprint(len(png_data))
        payload   = { "png_data": png_data, 'aws_secrets_id':'slack-gs-bot', 'channel': 'DDKUZTK6X'}

        result = self.png_to_slack.invoke(payload)

        Dev.pprint(result)
 def test_create_dashboard_for_graph(self):
     graph_name = 'graph_DGK'
     root_node = 'GSSP-6'
     #graph_name = 'graph_DAS'
     #root_node = 'GSSP-29'
     graph_name = 'graph_GSA'
     root_node ='GSSP-112'
     #graph_name = 'graph_OBY'
     #root_node ='GSSP-119'
     graph_name = 'graph_JIE'
     root_node = 'GSP-92'
     result = self.risk_dashboard.create_dashboard_for_graph(graph_name, root_node)
     Dev.pprint(result)
Example #26
0
    def test_update_and_invoke(self):
        png_file = '/tmp/lambda_png_file.png'
        png_data = base64.b64encode(open(png_file, 'rb').read()).decode()
        Dev.pprint(len(png_data))
        payload = {
            "png_data": png_data,
            'aws_secrets_id': 'slack-gs-bot',
            'channel': 'DDKUZTK6X'
        }

        result = self.png_to_slack.update_with_src().invoke(payload)

        Dev.pprint(result)
Example #27
0
    def test_create_table(self):
        self.datatable_js.load_page(True)
        headers = ['Header AAA','Header BBB']
        rows    = [['value 1'  , 'value 2'  ],
                   ['value 3'  , 'value 4'  ],
                   ['value 5'               ],
                   [                        ],
                   ['value 6'  , 'value 7'  ],
                   [None                    ],
                   [None,'value 8', 'AB'    ],
                   ['value 9'  , 'value 10' ]]

        html = self.datatable_js.create_table(headers,rows)
        Dev.print(html)
Example #28
0
    def tearDown(self):
        if self.result is not None:
            Dev.pprint(self.result)

        if self.png_data:
            png_file = '/tmp/tmp-jira-screenshot.png'
            with open(png_file, "wb") as fh:
                fh.write(base64.decodebytes(self.png_data.encode()))
            Dev.pprint("Png data with size {0} saved to {1}".format(
                len(self.png_data), png_file))

        if self.new_page:
            sleep(self.close_wait)
            self.web_jira.page.close()
Example #29
0
    def _test_sqs_to_lamdba_to_sqs(self):
        queue_1 = Queue('unit_tests_temp_queue__1').create()
        queue_2 = Queue('unit_tests_temp_queue__2').create()
        lambda_obj = Lambda_Package('osbot_aws.lambdas.pocs.send_event_data_to_queue')   #.update_with_root_folder()
        payload = {'queue_url': queue_2.url(), 'message': 'test 123'}

        #queue_1.attributes_update({'VisibilityTimeout': '61'}) # needs to be bigger than lambda timeout

        queue_1_arn  = queue_1.attributes().get('QueueArn')
        function_arn = lambda_obj._lambda.function_Arn()
        #Dev.pprint(lambda_obj.role_arn)            # needed to add the extra priv to pull SQS messages

        #result = lambda_obj._lambda.boto_lambda().list_event_source_mappings(EventSourceArn=queue_1_arn)
        # result = lambda_obj._lambda.boto_lambda().create_event_source_mapping(
        #     EventSourceArn=queue_1_arn,
        #     FunctionName=function_arn,
        #     Enabled=True,
        #     BatchSize=1
        # )

        queue_1.push('some message 1')
        queue_1.push('some message 2')
        queue_1.push('some message 3')
        queue_1.push('some message 4')
        #lambda_obj.invoke(payload)
        sleep(2)

        Dev.pprint(queue_2.pull())
        Dev.pprint(queue_2.pull())
        Dev.pprint(queue_2.pull())
        Dev.pprint(queue_2.pull())

        queue_1.delete()
        queue_2.delete()
    def mindmap(team_id=None, channel=None, params=None, root_node_text=None):
        (go_js, graph_data) = Go_Js_Views._get_graph_data(params, "mindmap",headless=True)
        go_js.load_page(False)
        (nodes, edges) = Go_Js_Views._get_nodes_and_edges(graph_data,text_field='Summary')
        data = { "class": "go.TreeModel", "nodeDataArray": []}
        width  = Misc.to_int(Misc.array_pop(params, 0))
        height = Misc.to_int(Misc.array_pop(params, 0))
        if width and height:
            go_js.browser().sync__browser_width(width,height)
        else:
            go_js.set_browser_width_based_on_nodes(nodes)

        nodes_indexed = {}
        if len(nodes) > 0:
            for index, node in enumerate(nodes):
                key  = node.get('key')
                #text = "{1} | {0}".format(key,node.get('text'))                            # need a better way to trigger this
                text = node.get('text')
                nodes_indexed[key] = {'index':index, 'text': text }

            #root_node_text = "{1} | {0}".format(nodes[0].get('key'), nodes[0].get('text')) # and this
            if root_node_text is None:
                root_node_text = nodes[0].get('text')
            data['nodeDataArray'].append({"key": 0, "text": root_node_text })                     # add root node first
            for edge in edges:
                from_key   = edge['from']
                to_key     = edge['to']
                from_issue = nodes_indexed.get(from_key)
                to_issue   = nodes_indexed.get(to_key)

                if from_issue:
                    parent = nodes_indexed.get(edge['from']).get('index')
                else:
                    parent = from_key
                if to_issue:
                    key    = nodes_indexed.get(edge['to'  ]).get('index')
                    text   = nodes_indexed.get(edge['to'  ]).get('text')
                else:
                    key    = to_key
                    text   = to_key
                item = {"key": key, "parent": parent, "text": text, "brush": Misc.get_random_color()}
                data['nodeDataArray'].append(item)

            go_js.invoke_js("create_graph_from_json", data)
            js_code = 'layoutAll()'
            go_js.api_browser.sync__await_for_element('#animationFinished')

            Dev.pprint(go_js.exec_js(js_code))
            return go_js.send_screenshot_to_slack(team_id=team_id, channel=channel)