def issue_update_fields(self, issue_id, fields): path = 'issue/{0}'.format(issue_id) data = {"update": {}} fields_by_name = self.fields_by_name() for key, value in fields.items(): if key == 'Rating': key = 'Risk Rating' # move to special resolver method (needed because 'Risk Rating' was mapped as 'Rating' in ELK) field = fields_by_name.get(key) if field: field_id = field.get('id') schema_type = field.get('schema').get('type') if schema_type == 'option': data['update'][field_id] = [{"set": {'value': value}}] elif schema_type == 'string': data['update'][field_id] = [{"set": value}] elif schema_type == 'array': data['update'][field_id] = [{"set": value.split(',')}] elif schema_type == 'user': data['update'][field_id] = [{"set": {'name': value}}] else: data['update'][field_id] = [{"set": value}] #Dev.pprint(field)issue_update if len(set(data)) == 0: return False Dev.pprint(data) return self.request_put(path, data)
def test_file_update(self): file = '/tmp/puml_graph_W64.png' #file = '/tmp/puml_graph_09Q.png' file = '/tmp/puml_graph.png' id = '1H72nAFgqu1OSW_xm-gwDWml6tOzy5UZ_' result = self.gdrive.file_update(file, 'image/png', id) Dev.pprint(result)
def test_diff_sheet_data_with_jira_data(self): sheet_data = self.api_sync.get_sheet_data(self.api_sync.sheet_name()) backup_data = self.api_sync.get_sheet_data(self.api_sync.sheet_name_backup()) issues = self.api_sync.get_jira_issues_in_sheet_data(sheet_data) result = self.api_sync.diff_sheet_data_with_jira_data(sheet_data, backup_data, issues) #Json.save_json('/tmp/tmp_diff_data.json', result) Dev.pprint(result)
async def test_invoke_js_function(self): markdown = """ # changed title "via js function" some text and 'single quotes' """ result = await self.api.js_invoke_function('convert', markdown) Dev.pprint(result)
def test_delete_element__all_temp_created(self): file_id = self.gdrive.find_by_name('GSlides API tests').get('id') elements = self.gslides.slide_elements_indexed_by_id(file_id,1) for key,element in elements.items(): #Dev.pprint(key) if 'textbox_' in key.lower(): Dev.pprint(self.gslides.element_delete(file_id,key))
def test_execute_requests(self): sheet_id = self.get_target_file_id() # this is one wat to add values via the execute requests workflow requests = [{ 'updateCells': { 'start': {'sheetId': 0, 'rowIndex': 11, 'columnIndex': 0}, 'rows': [ { 'values': [ { 'userEnteredValue': {'numberValue': 1}, 'userEnteredFormat': {'backgroundColor': {'red': 1}} }, { 'userEnteredValue': {'numberValue': 2}, 'userEnteredFormat': {'backgroundColor': {'blue': 1}} }, { 'userEnteredValue': {'numberValue': 3}, 'userEnteredFormat': {'backgroundColor': {'green': 1}} } ] } ], 'fields': 'userEnteredValue,userEnteredFormat.backgroundColor' } }] result = self.gsheets.execute_requests(sheet_id,requests) Dev.pprint(result)
def test_sync__dashboard(self): #id = '9591ebd0-e65f-11e8-abb1-378e282672cc' goto_id = '549e8579f763bc82ed6cd69cf4c62954' result = self.elk.sync__dashboard(goto_id) result = self.elk.browser().sync__screenshot(file_screenshot='/tmp/lambda_png_file.png') Dev.print(result)
def test_run__ls(self): result = Process.run('ls') #assert result == {'runParams': ['ls'], 'stderr': '', 'stdout': 'Test_Process.py\naws\n'} Dev.pprint(result) result = Process.run('ls', ['-la', '..']) #assert '-rw-r--r--@ 1 dinis staff 6148 Oct 29 11:59 .DS_Store\n' in result['stdout'] Dev.pprint(result)
def test_sync__dashboard_project(self): #id = '9591ebd0-e65f-11e8-abb1-378e282672cc' key = 'GSSP-126' result = self.elk.sync__dashboard_project(key) result = self.elk.browser().sync__screenshot(file_screenshot='/tmp/lambda_png_file.png') Dev.print(result)
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'))))
def request_get(self, path): (server, username, password) = self.config() path = '{0}/rest/api/2/{1}'.format(server, path) response = requests.get(path, auth=(username, password)) if response.status_code == 200: return response.text Dev.pprint('[Error][request_get]: {0}'.format(response.text)) return None
def test_files_in_folder(self): folder_id = '16yOkKyi0TfOy3w4IMW40vo-pr--Wa1Y9' try: files = self.gdrive.files_in_folder(folder_id, size=2) for item in files: print('{0:22} - {1}'.format(item['name'], item['id'])) except Exception as error: Dev.pprint(error)
def send_messages_to_elk(self, label_id, label_name): messages = self.api_gmail.messages_from_label(label_id) for message in messages: message['label_id'] = label_id message['label_name'] = label_name count = self.elastic.add_bulk(messages, 'id') Dev.pprint('processed: {0} messages from {1}'.format( count, label_name))
def diff_cells(self): sheet_data = self.get_sheet_data(self.sheet_name()) backup_data = self.get_sheet_data(self.sheet_name_backup()) if backup_data is None: Dev.pprint("Error: Backup data is not setup, please load the data again") return None jira_issues = self.get_jira_issues_in_sheet_data(sheet_data) return self.diff_sheet_data_with_jira_data(sheet_data, backup_data, jira_issues)
def save_image(self, result, png_file): png_data = result.get('body') if (png_data): with open(png_file, "wb") as fh: fh.write(base64.decodebytes(png_data.encode())) Dev.pprint('Image saved to {0}'.format(png_file)) else: Dev.pprint(result)
def test_pump_to_png_via_local_server( self): # needs plantuml docker version to be running puml = "@startuml \n aaa->bbb \n @enduml" #puml = Files.contents('../../data/puml/simple.puml') png_file = self.plantuml.puml_to_png_via_local_server(puml) Dev.pprint(png_file) Show_Img.from_path(png_file)
def test_update_and_invoke(self): file_id = '1yDxu5YxL9FxY5wQ1EEQlAYGt3flIsm2VTyWwPny5RLA' result = self.simple_test.update_with_src().invoke( {'queryStringParameters': { 'file_id': file_id }}) message = Misc.json_load(result.get('body')) Dev.pprint(message)
def test_test_search_using_query___large_query(self): query = { "_source": ["Key", "Issue Links"], } result = list( self.elastic.set_index('sec_project').search_using_query(query)) Dev.pprint(len(result))
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))
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
def test_markdown(self): #payload = {"params": ['markdown'] } payload = { "params": ['markdown', '# Created from Lambda\n', "normal text"] } png_data = self.lambda_browser.update_with_src().invoke(payload) Dev.pprint(png_data) self._save_png_file(png_data)
def test_invoke___jira_issues_dot_file(self): dot = Files.contents('../../../data/jira-test.dot') Dev.pprint(dot) params = { "dot": dot , "channel": "DDKUZTK6X"} svg = self.dot_to_svg.update().invoke(params) #how_Img.from_svg_string(svg) Dev.pprint(svg)
def test_invoke_simple____dot_file(self): graph = pydot.Dot(graph_type='digraph') graph.add_edge(pydot.Edge("aaa","bbb")) params = {"dot": graph.to_string(), "channel": "DDKUZTK6X"} result = self.dot_to_svg.update().invoke(params) #result = self.dot_to_svg.invoke({"dot": 'digraph {\na -> b[label="hi", decorate];\n}'}) Dev.pprint(result)
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 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)
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)
def test_bug_cache_issue_in_lambdas(self): Lambdas('browser.lambda_browser').update_with_src() payload = {"params": ["go_js", "graph_MKF", "default"]} self.png_data = Lambdas('browser.lambda_browser').invoke(payload) Dev.pprint(self.png_data) self.png_data = Lambdas('browser.lambda_browser').invoke(payload) Dev.pprint(self.png_data)
def test_open_file_in_browser__markdown_with_js(self): js_code = { 'name': 'convert', 'params': '# aaaa \n 123 \n - bullet point \n - another one ![](http://visjs.org/images/gettingstartedSlide.png)' } result = self.view_examples.open_file_in_browser( '/examples/markdown.html', js_code) Dev.print(result('#md_html').html())
async def test_js_eval(self): markdown = """ # some title "with double quotes" some text and 'single quotes' """ encoded_text = base64.b64encode(markdown.encode()).decode() js_script = "convert(atob('{0}'))".format(encoded_text) result = await self.api.js_eval(js_script) Dev.pprint(result)
def list(self, labelIds=None, query='', max_results=100): response = self.service.users().messages().list( userId=self.user_id, q=query, labelIds=labelIds, maxResults=max_results).execute() if response.get('messages') is None: Dev.pprint('NO MESSAGES for {0} - {1}'.format(labelIds, response)) return [] return (message['id'] for message in response['messages'])