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 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_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))
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_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)
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_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 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 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 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_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__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_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_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_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_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)
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'])
def test_update_and_invoke(self): gdrive = GDrive() file_id = gdrive.find_by_name('GSlides API tests').get('id') pdf_bytes = gdrive.file_export(file_id) pdf_data = base64.b64encode(pdf_bytes).decode() payload = {"pdf_data": pdf_data, 'channel': 'DDKUZTK6X'} result = self.pdf_to_slack.update_with_src().invoke(payload) Dev.pprint(result)
def test_update_backup_data_with_new_jira_value(self): item = { 'backup_value': 'Test updated....xyz . DEMO TO GS', 'col_index': 1, 'field': 'Summary', 'jira_value': 'Test updated....xyz . DEMO TO GS', 'key': 'RISK-12', 'row_index': 1, 'sheet_value': 'Test updated....CHANGED', 'status': 'sheet_change'} result = self.api_sync.update_backup_data_with_new_jira_value(item) Dev.pprint(result)
def _save_png_file(self, png_data): try: png_file = '/tmp/lambda_png_file.png' if png_data: with open(png_file, "wb") as fh: fh.write(base64.decodebytes(png_data.encode())) Dev.pprint("Png data with size {0} saved to {1}".format( len(png_data), png_file)) except Exception as error: Dev.print("[_save_png_file][Error] {0}".format(error)) Dev.print(png_data)
def test_create_local_server_and_take_screenshot(self): Files.folder_delete_all(self.src_tmp) self.copy_html_files() web_root = self.src_tmp + '/html' proc = subprocess.Popen(["python", "-m", "SimpleHTTPServer", "1234"], cwd=web_root) Dev.pprint(proc) self.take_screenshot() html = requests.get('http://localhost:1234/map/').text proc.kill() Dev.pprint(html)
def test_issue_update_fields(self): issue_id = 'RISK-12' fields = { "Summary": "update from test... 12345", "Description": "The description.....123", "Risk Description": "The risk description", "Labels": "Risk,Unit-Test,ABC", #"Priority" : "Major" , "Risk Rating": "Low", "Assignee": "dinis.cruz" } result = self.api.issue_update_fields(issue_id, fields) Dev.pprint(result)
def request_put(self, path, data): json_data = Misc.json_dumps(data) (server, username, password) = self.config() path = '{0}/rest/api/2/{1}'.format(server, path) headers = {'Content-Type': 'application/json'} response = requests.put(path, json_data, headers=headers, auth=(username, password)) if 200 <= response.status_code < 300: return True Dev.pprint('[Error][request_put]: {0}'.format(response.text)) return False