def ftp_transfer(get_delivery_status_url, delivery_id,delivery_stage, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password, local_manifest_file_path): test.log("ftp_transfer : ") test.log("get_delivery_status_url : " + get_delivery_status_url) test.log("delivery_id : " + delivery_id) test.log("delivery_stage : " + delivery_stage) test.log("delivery_stage : " + local_manifest_file_path) if(delivery_stage == "WAITING_ON_CONFIRMATION"): # get the ftp path and transfer parse success replace success file source(findFile("scripts", "connect_to_ftpserver.py")) complete_url = get_delivery_status_url + delivery_id ftp_delivery_path = get_delivery_ftp_path_complete_url(complete_url) check_contents_in_ftp_server_and_download_manifest(ftp_delivery_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) squish.snooze(30) copy_to_ftp_server(local_manifest_file_path, ftp_delivery_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) squish.snooze(90) delivery_stage = check_delivery_status_with_complete_url(complete_url) if(delivery_stage == "COMPLETE"): test.passes("Queued Delivery successfully completed") #change the flight end date to 30 seconds from now os.system("C:\\utils\\run_update_campaign_end_dates.bat 84062112") else: test.log("Queued Delivery failed : " + complete_url) test.fail("Queued Delivery failed : " + delivery_stage) else: test.fail("queued delivery has failed to complete the delivery")
def get_list_of_media_families(url, campaign_id): test.log("get_list_of_media_families :" + url + campaign_id) complete_url = url + campaign_id print complete_url open = urllib2.urlopen(complete_url) dict = json.load(open) squish.snooze(10) test.log("get_list_of_media_families : " + complete_url) #pprint(dict) number_of_results = dict['numberOfResults'] media_family_id = None if (number_of_results > 0): print number_of_results count = 0 for i in range(number_of_results): count = count + 1 dict_of_media_family_id_list = dict['results'][i] media_family_id = dict_of_media_family_id_list['id'] print media_family_id test.log("successfully retrieved the no of results :") if (number_of_results != count): test.fail("assets doesn't match the number of results retrieved") else: test.fail("No results exist for media family") if (media_family_id and media_family_id != None): test.log("media family id exists : ", media_family_id) test.passes("Media family exists") return media_family_id else: test.fail("Failed to retrieve media family id")
def revert_delivery(url, get_delivery_status_url, delivery_id): test.log("revert_delivery : " + url + delivery_id) squish.snooze(10) response = requests.put(url + delivery_id) squish.snooze(30) print response.status_code test.log("response code : " + str(response.status_code)) if (response.status_code == 200): test.passes("Revert delivery initiated: ") else: test.fail("Revert delivery initiating failed") snooze(40) complete_url = get_delivery_status_url + delivery_id source(findFile("scripts", "deliverywebservices.py")) revert_stage = check_revert_status_with_complete_url(complete_url) latest_revert_id = get_latest_revert_id_with_complete_url(complete_url) if (revert_stage == "REVERTING" and latest_revert_id != None and latest_revert_id): test.log("Reverting the delivery") return latest_revert_id else: test.fail("Failed to Revert the delivery")
def cancelling_delivery(check_delivery_status_url, cancel_delivery_url, delivery_id, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password): test.log("cancelling delivery") files_on_ftp = False delivery_stage = check_delivery_status(check_delivery_status_url, delivery_id) if(delivery_stage == "CREATED" or delivery_stage == "SUBMITTED" or delivery_stage == "STARTED" or delivery_stage == "IN_PROGRESS"): test.log("Delivery successfully cancelled") #cancel the delivery print delivery_stage source(findFile("scripts", "stop_cancel_delivery.py")) delivery_stage = stop_delivery(cancel_delivery_url, delivery_id) squish.snooze(30) delivery_stage = check_delivery_status_until_cancelled(check_delivery_status_url, delivery_id) source(findFile("scripts", "check_contents_on_ftp_after_cancel.py")) delivery_ftp_path = get_delivery_ftp_path(check_delivery_status_url, delivery_id) if(delivery_ftp_path or delivery_ftp_path != None): files_on_ftp = check_contents_in_ftp_server(delivery_ftp_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) if(files_on_ftp): test.passes("File transfer has been successfully cancelled and contents has been checked on FTP") elif(delivery_stage == "CANCELLED"): test.log("Delivery Cancelled") test.passes("Delivery has been successfully cancelled") else: test.fail("Failed to cancel delivery") return
def ftp_transfer(get_delivery_status_url, delivery_id, delivery_stage, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password, local_manifest_file_path): test.log("ftp_transfer : ") test.log("get_delivery_status_url : " + get_delivery_status_url) test.log("delivery_id : " + delivery_id) test.log("delivery_stage : " + delivery_stage) test.log("local_manifest_file_path : " + local_manifest_file_path) if (delivery_stage == "WAITING_ON_CONFIRMATION"): # get the ftp path and transfer parse success replace success file source(findFile("scripts", "connect_to_ftpserver.py")) complete_url = get_delivery_status_url + delivery_id ftp_delivery_path = get_delivery_ftp_path_complete_url(complete_url) check_contents_in_ftp_server_and_download_manifest( ftp_delivery_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) squish.snooze(30) copy_to_ftp_server(local_manifest_file_path, ftp_delivery_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) squish.snooze(90) delivery_stage = check_delivery_status_with_complete_url(complete_url) if (delivery_stage == "COMPLETE"): # change the flight end date to 30 seconds from now os.system("C:\\utils\\run_update_campaign_end_dates.bat 12735523") test.passes("Delivery successfully completed") else: test.log("Delivery failed : " + complete_url) test.fail("Delivery failed : " + delivery_stage) else: test.fail("delivery has failed to complete the delivery")
def get_list_of_media_families(url, campaign_id): test.log("get_list_of_media_families :" + url + campaign_id) complete_url = url + campaign_id print complete_url open = urllib2.urlopen(complete_url) dict = json.load(open) squish.snooze(10) test.log("get_list_of_media_families : " + complete_url) #pprint(dict) number_of_results = dict['numberOfResults'] media_family_id = None if(number_of_results > 0): print number_of_results count = 0 for i in range(number_of_results): count = count + 1 dict_of_media_family_id_list = dict['results'][i] media_family_id = dict_of_media_family_id_list['id'] print media_family_id test.log("successfully retrieved the no of results :") if(number_of_results != count): test.fail("assets doesn't match the number of results retrieved") else: test.fail("No results exist for media family") if(media_family_id and media_family_id != None): test.log("media family id exists : ", media_family_id) test.passes("Media family exists") return media_family_id else: test.fail("Failed to retrieve media family id")
def check_contents_in_ftp_server(ftp_delivery_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password): test.log("check_contents_in_ftp_server") test.log("ftp_delivery_path : " + ftp_delivery_path) squish.snooze(60) files = [] squish.snooze(60) try: session = ftplib.FTP(ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) #print session session.cwd(ftp_delivery_path) # Change working directory files = session.nlst() print files for filename in files: print filename if(len(files) == 3): test.fail("files are transferred to FTP server even though we have cancelled the delivery") return False elif(len(files) > 3): test.fail("no of files in the FTP server are more than 3 ") return False elif(len(files) < 3): test.passes("no of files in the FTP server are less than 3 ") return True session.quit() except Exception as e: print e s = str(e) print sys.exc_info() test.log("exception due to :" + s) test.fail("check_contents_in_ftp_server")
def revert_delivery(url, get_delivery_status_url, delivery_id): test.log("revert_delivery : " + url + delivery_id) squish.snooze(10) response = requests.put(url + delivery_id) squish.snooze(30) print response.status_code test.log("response code : " + str(response.status_code)) if(response.status_code == 200): test.passes("Revert delivery initiated: ") else: test.fail("Revert delivery initiating failed") snooze(40) complete_url = get_delivery_status_url + delivery_id source(findFile("scripts", "deliverywebservices.py")) revert_stage = check_revert_status_with_complete_url(complete_url) latest_revert_id = get_latest_revert_id_with_complete_url(complete_url) if(revert_stage == "REVERTING" and latest_revert_id != None and latest_revert_id): test.log("Reverting the delivery") return latest_revert_id else: test.fail("Failed to Revert the delivery")
def main(): test.log("Test Case Name: test_create_cancel_remove") data = testData.dataset("s_list_of_webservices.tsv")[0] create_delivery_data_success = { "serviceOriginName": "Dove UI", "callBackEndPoint": None, "callBackReferenceId": None, "requestTime": None, "sourceFile": 'hub://hub-t1/mirriad/storage/QA/GBUV71000779_I_AM_ARROWS_Another Picture Of You_no_P_logo_v2.mov', "deliveryFile": 'hub://hub-t1/mirriad/storage/QA/GBUV71000779_I_AM_ARROWS_Another Picture Of You_with_P_logo_v2.mov', "assetId": '12230', "campaignId": '27120900', "deliveryTargetService": 'VEVO', "revertOperation": False } create_delivery_url = testData.field( data, "create_save_delivery_using_post_url") get_delivery_status_url = testData.field(data, "get_delivery_status_url") cancel_delivery_url = testData.field(data, "cancel_delivery_using_post_url") remove_delivery_url = testData.field(data, "delete_delivery_using_delete_url") success = False '''t01 ftp connection login details''' ftp_vevo_host = "ftp.uk.mirriad.com" ftp_vevo_user = "******" ftp_vevo_password = "******" ftp_vevo_port = 21 ftp_vevo_vevo_user = "******" source(findFile("scripts", "test_create_cancel_remove.py")) success = create_cancel_remove_delivery( create_delivery_url, create_delivery_data_success, get_delivery_status_url, cancel_delivery_url, remove_delivery_url, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password, success) if (success): test.passes("test_create_cancel_remove passed") else: test.fail("test_create_cancel_remove failed") testdata = testData.create("shared", "status.failed") try: with open(testdata, "w+") as f: test.log("Failed so create a status file") except Exception as e: print e s = str(e) test.log(s)
def ftp_transfer(get_delivery_status_url, parent_delivery_id, latest_revert_id, delivery_stage, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password, local_manifest_file_path): test.log("ftp_transfer : ") test.log("get_delivery_status_url : " + get_delivery_status_url) test.log("latest_revert_id : " + latest_revert_id) test.log("delivery_stage : " + delivery_stage) test.log("delivery_stage : " + local_manifest_file_path) test.log( "list of revert stages : REVERTED,REVERTING,REVERT_FAILED,UNREVERTABLE,UNREVERTABLE_DUPLICATE,UNREVERTABLE_NO_SOURCE,UNREVERTED" ) if (delivery_stage == "WAITING_ON_CONFIRMATION"): # get the ftp path and transfer parse success replace success file source(findFile("scripts", "connect_to_ftpserver.py")) complete_url_of_parent = get_delivery_status_url + parent_delivery_id complete_url = get_delivery_status_url + latest_revert_id ftp_delivery_path = get_delivery_ftp_path_complete_url(complete_url) check_contents_in_ftp_server_and_download_manifest( ftp_delivery_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) squish.snooze(30) copy_to_ftp_server(local_manifest_file_path, ftp_delivery_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) squish.snooze(60) test.log("waiting for 60 more seconds :") squish.snooze(60) delivery_stage = check_delivery_status_with_complete_url(complete_url) revert_stage_of_parent = check_revert_status_with_complete_url( complete_url_of_parent) # REVERTED revert_stage = check_revert_status_with_complete_url( complete_url) # UNREVERTABLE if (delivery_stage == "COMPLETE" and revert_stage == "UNREVERTABLE" and revert_stage_of_parent == "REVERTED"): test.passes("Delivery successfully Reverted") test.log("revert_stage: " + revert_stage) test.log("revert_stage_of_parent: " + revert_stage_of_parent) else: test.log("delivery_stage: " + delivery_stage) test.log("revert_stage: " + revert_stage) test.log("revert_stage_of_parent: " + revert_stage_of_parent) test.log("Reverting Delivery failed : " + complete_url) test.fail("Reverting Delivery failed : " + delivery_stage) else: test.fail("Reverting delivery has failed to complete the delivery")
def main(): test.log("Test Case Name: test_create_restart_remove") data = testData.dataset("s_list_of_webservices.tsv")[0] create_failed_delivery_data = { "serviceOriginName": "Dove UI", "callBackEndPoint": None, "callBackReferenceId": None, "requestTime": None, "sourceFile": 'hub://hub-t1/mirriad/storage/QA/MP4.mp4', "deliveryFile": 'hub://hub-t1/mirriad/storage/QA/MP41.mp4', "assetId": '10006', "campaignId": '10450402', "deliveryTargetService": 'VEVO', "revertOperation": False } create_delivery_url = testData.field( data, "create_save_delivery_using_post_url") get_delivery_status_url = testData.field(data, "get_delivery_status_url") restart_delivery_url = testData.field(data, "restart_delivery_using_put_url") remove_delivery_url = testData.field(data, "delete_delivery_using_delete_url") success = False source(findFile("scripts", "test_create_restart_remove.py")) success = create_restart_remove_delivery(create_delivery_url, create_failed_delivery_data, get_delivery_status_url, restart_delivery_url, remove_delivery_url, success) if (success): test.passes("test_create_restart_remove delivery passed") else: test.fail("test_create_restart_remove delivery failed") testdata = testData.create("shared", "status.failed") try: with open(testdata, "w+") as f: test.log("Failed so create a status file") except Exception as e: print e s = str(e) test.log(s)
def main(): test.log("Test Case Name: test_create_cancel_remove") data = testData.dataset("s_list_of_webservices.tsv")[0] create_delivery_data_success = { "serviceOriginName": "Dove UI", "callBackEndPoint": None, "callBackReferenceId": None, "requestTime": None, "sourceFile": 'hub://hub-t1/mirriad/storage/QA/GBUV71000779_I_AM_ARROWS_Another Picture Of You_no_P_logo_v2.mov', "deliveryFile": 'hub://hub-t1/mirriad/storage/QA/GBUV71000779_I_AM_ARROWS_Another Picture Of You_with_P_logo_v2.mov', "assetId": '12230', "campaignId": '27120900', "deliveryTargetService": 'VEVO', "revertOperation": False } create_delivery_url = testData.field(data, "create_save_delivery_using_post_url") get_delivery_status_url = testData.field(data, "get_delivery_status_url") cancel_delivery_url = testData.field(data, "cancel_delivery_using_post_url") remove_delivery_url = testData.field(data, "delete_delivery_using_delete_url") success = False '''t01 ftp connection login details''' ftp_vevo_host = "ftp.uk.mirriad.com" ftp_vevo_user = "******" ftp_vevo_password = "******" ftp_vevo_port = 21 ftp_vevo_vevo_user = "******" source(findFile("scripts", "test_create_cancel_remove.py")) success = create_cancel_remove_delivery(create_delivery_url, create_delivery_data_success, get_delivery_status_url, cancel_delivery_url, remove_delivery_url, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password, success) if(success): test.passes("test_create_cancel_remove passed") else: test.fail("test_create_cancel_remove failed") testdata = testData.create("shared", "status.failed") try: with open(testdata, "w+") as f: test.log("Failed so create a status file") except Exception as e: print e s = str(e) test.log(s)
def attach_to_aut(application_folder_path, executable, arguments_for_aut="--uses-builtin-hook", squish_path=os.path.join(os.environ["SQUISH_PREFIX"])): squish_module_helper.import_squish_symbols() start_aut_bin = os.path.join(squish_path, "bin", "startaut") if sys.platform.startswith("win"): executable += ".exe" start_aut_bin += ".exe" application_under_test = os.path.join(application_folder_path, executable) # builds absolute path to testable application test.log("Application under test: " + str(application_folder_path) + "/" + executable) test.log(str(start_aut_bin)) if sys.platform.startswith("win"): start_aut_bin = start_aut_bin.replace("\\", "\\\\") application_under_test = application_under_test.replace("\\", "\\\\") start_aut_cmd = " ".join( [start_aut_bin, arguments_for_aut, application_under_test]) # creates string for launching aut start_aut_cmd = shlex.split( start_aut_cmd ) # Converts launch string to list as needed by Unix; Windows can use string or list. test.log("Subprocess call arguments", ' '.join(start_aut_cmd)) test.log(start_aut_cmd[0]) subprocess_handle = subprocess.Popen(start_aut_cmd, shell=False) if sys.platform.startswith("win"): snooze(5) else: snooze(1) # This delay is need to give time for application to start test.log("Attaching to application") testSettings.waitForObjectTimeout = 2000 # Attempts to attach to application under test, if it fails will close program. try: attachToApplication( "teest" ) # Note that name teest comes from Applications source code (all examples use this at least for now) except Exception as e: # Handles failing to attach to application eg. log and kill. test.fatal("FAIL: failed to attach to application", str(e)) subprocess_handle.kill() return None else: test.passes("Application successfully attached") return subprocess_handle
def bulk_revert_delivery(bulk_revert_url,get_delivery_status_url,parent_delivery_id): test.log("bulk_revert_delivery : " + bulk_revert_url) open = urllib2.urlopen(bulk_revert_url) response_code = open.getcode() dict = json.load(open) request_status = dict['requestStatus'] if(response_code == 200 and request_status == "OK"): squish.snooze(30) test.passes("Bulk Revert initiated:") else: test.fail("Bulk Revert initiation failed: " + response_code) squish.snooze(60) latest_revert_id = status_of_reverting_delivery(get_delivery_status_url, parent_delivery_id) return latest_revert_id
def get_campaign_service_call(url,campaign_id): test.log("get_campaign_service_call: campaignId" + url + campaign_id) open = urllib2.urlopen(url) dict = json.load(open) #pprint(dict) total_number_of_results = dict['numberOfResults'] if(total_number_of_results > 0): test.log("total campaign ids : ") else: test.fail("No campaign found") list_of_results = dict['results'] #count = 0 if(len(list_of_results) > 0): test.passes("Campaign service call returned open campaigns") else: test.fail("No campaign available ")
def get_campaign_service_call(url, campaign_id): test.log("get_campaign_service_call: campaignId" + url + campaign_id) open = urllib2.urlopen(url) dict = json.load(open) #pprint(dict) total_number_of_results = dict['numberOfResults'] if (total_number_of_results > 0): test.log("total campaign ids : ") else: test.fail("No campaign found") list_of_results = dict['results'] #count = 0 if (len(list_of_results) > 0): test.passes("Campaign service call returned open campaigns") else: test.fail("No campaign available ")
def bulk_revert_delivery(bulk_revert_url, get_delivery_status_url, parent_delivery_id): test.log("bulk_revert_delivery : " + bulk_revert_url) open = urllib2.urlopen(bulk_revert_url) response_code = open.getcode() dict = json.load(open) request_status = dict['requestStatus'] if (response_code == 200 and request_status == "OK"): squish.snooze(30) test.passes("Bulk Revert initiated:") else: test.fail("Bulk Revert initiation failed: " + response_code) squish.snooze(60) latest_revert_id = status_of_reverting_delivery(get_delivery_status_url, parent_delivery_id) return latest_revert_id
def ftp_transfer(get_delivery_status_url, parent_delivery_id, latest_revert_id, delivery_stage, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password, local_manifest_file_path): test.log("ftp_transfer : ") test.log("get_delivery_status_url : " + get_delivery_status_url) test.log("latest_revert_id : " + latest_revert_id) test.log("delivery_stage : " + delivery_stage) test.log("local_manifest_file_path : " + local_manifest_file_path) #test.log("list of revert stages : REVERTED,REVERTING,REVERT_FAILED,UNREVERTABLE,UNREVERTABLE_DUPLICATE,UNREVERTABLE_NO_SOURCE,UNREVERTED") if(delivery_stage == "WAITING_ON_CONFIRMATION"): # get the ftp path and transfer parse success replace success file source(findFile("scripts", "connect_to_ftpserver.py")) complete_url_of_parent = get_delivery_status_url + parent_delivery_id complete_url = get_delivery_status_url + latest_revert_id ftp_delivery_path = get_delivery_ftp_path_complete_url(complete_url) check_contents_in_ftp_server_and_download_manifest(ftp_delivery_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) squish.snooze(30) copy_to_ftp_server(local_manifest_file_path, ftp_delivery_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) squish.snooze(60) test.log("waiting for 60 more seconds :") squish.snooze(60) delivery_stage = check_delivery_status_with_complete_url(complete_url) revert_stage_of_parent = check_revert_status_with_complete_url(complete_url_of_parent) # REVERTED revert_stage = check_revert_status_with_complete_url(complete_url) # UNREVERTABLE if(delivery_stage == "COMPLETE" and revert_stage == "UNREVERTABLE" and revert_stage_of_parent == "REVERTED"): test.passes("Delivery successfully Reverted") test.log("revert_stage: " + revert_stage) test.log("revert_stage_of_parent: " + revert_stage_of_parent) else: test.log("delivery_stage: " + delivery_stage) test.log("revert_stage: " + revert_stage) test.log("revert_stage_of_parent: " + revert_stage_of_parent) test.log("Reverting Delivery failed : " + complete_url) test.fail("Reverting Delivery failed : " + delivery_stage) else: test.fail("Reverting delivery has failed to complete the delivery")
def main(): test.log("Test Case Name: test_create_restart_remove") data = testData.dataset("s_list_of_webservices.tsv")[0] create_failed_delivery_data = { "serviceOriginName": "Dove UI", "callBackEndPoint": None, "callBackReferenceId": None, "requestTime": None, "sourceFile": 'hub://hub-t1/mirriad/storage/QA/MP4.mp4', "deliveryFile": 'hub://hub-t1/mirriad/storage/QA/MP41.mp4', "assetId": '10006', "campaignId": '10450402', "deliveryTargetService": 'VEVO', "revertOperation": False } create_delivery_url = testData.field(data, "create_save_delivery_using_post_url") get_delivery_status_url = testData.field(data, "get_delivery_status_url") restart_delivery_url = testData.field(data, "restart_delivery_using_put_url") remove_delivery_url = testData.field(data, "delete_delivery_using_delete_url") success = False source(findFile("scripts", "test_create_restart_remove.py")) success = create_restart_remove_delivery(create_delivery_url, create_failed_delivery_data, get_delivery_status_url, restart_delivery_url, remove_delivery_url, success) if(success): test.passes("test_create_restart_remove delivery passed") else: test.fail("test_create_restart_remove delivery failed") testdata = testData.create("shared", "status.failed") try: with open(testdata, "w+") as f: test.log("Failed so create a status file") except Exception as e: print e s = str(e) test.log(s)
def attach_to_aut(application_folder_path, executable, arguments_for_aut = "--uses-builtin-hook", squish_path = os.path.join(os.environ["SQUISH_PREFIX"])): squish_module_helper.import_squish_symbols() start_aut_bin = os.path.join(squish_path, "bin", "startaut") if sys.platform.startswith("win"): executable += ".exe" start_aut_bin += ".exe" application_under_test = os.path.join(application_folder_path, executable) # builds absolute path to testable application test.log("Application under test: " + str(application_folder_path)+"/"+executable) test.log(str(start_aut_bin)) if sys.platform.startswith("win"): start_aut_bin = start_aut_bin.replace("\\", "\\\\") application_under_test = application_under_test.replace("\\", "\\\\") start_aut_cmd = " ".join([start_aut_bin,arguments_for_aut,application_under_test]) # creates string for launching aut start_aut_cmd = shlex.split(start_aut_cmd) # Converts launch string to list as needed by Unix; Windows can use string or list. test.log("Subprocess call arguments", ' '.join(start_aut_cmd)) test.log(start_aut_cmd[0]) subprocess_handle = subprocess.Popen(start_aut_cmd, shell=False) if sys.platform.startswith("win"): snooze(5) else: snooze(1) # This delay is need to give time for application to start test.log("Attaching to application") testSettings.waitForObjectTimeout = 2000 # Attempts to attach to application under test, if it fails will close program. try: attachToApplication("teest") # Note that name teest comes from Applications source code (all examples use this at least for now) except Exception as e: # Handles failing to attach to application eg. log and kill. test.fatal("FAIL: failed to attach to application", str(e)) subprocess_handle.kill() return None else: test.passes("Application successfully attached") return subprocess_handle
def get_list_of_assets(url, media_family_id): test.log("get_list_of_assets") test.log("url : " + url) test.log("media_family_id " + media_family_id) complete_url = url + media_family_id print complete_url open = urllib2.urlopen(complete_url) dict = json.load(open) squish.snooze(10) test.log("get_list_of_assets" + complete_url) number_of_results = dict['numberOfResults'] print number_of_results if (number_of_results > 0): count = 0 print number_of_results test.log("successfully retrieved list of assets :") for i in range(number_of_results): count = count + 1 assets_list = dict['results'][i] asset_id = assets_list['id'] print asset_id if (number_of_results != count): test.fail("assets doesn't match the number of results retrieved") else: test.passes("asset ids exist") else: test.fail( "No results exist for media family to get the list of assets") testdata = testData.create("shared", "status.failed") try: with open(testdata, "w+") as f: test.log("Failed so create a status file") except Exception as e: print e s = str(e) test.log(s)
def get_list_of_assets(url, media_family_id): test.log("get_list_of_assets") test.log("url : " + url) test.log("media_family_id " + media_family_id) complete_url = url + media_family_id print complete_url open = urllib2.urlopen(complete_url) dict = json.load(open) squish.snooze(10) test.log("get_list_of_assets" + complete_url) number_of_results = dict['numberOfResults'] print number_of_results if(number_of_results > 0): count = 0 print number_of_results test.log("successfully retrieved list of assets :") for i in range(number_of_results): count = count + 1 assets_list = dict['results'][i] asset_id = assets_list['id'] print asset_id if(number_of_results != count): test.fail("assets doesn't match the number of results retrieved") else: test.passes("asset ids exist") else: test.fail("No results exist for media family to get the list of assets") testdata = testData.create("shared", "status.failed") try: with open(testdata, "w+") as f: test.log("Failed so create a status file") except Exception as e: print e s = str(e) test.log(s)
def check_contents_in_ftp_server(ftp_delivery_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password): test.log("check_contents_in_ftp_server") test.log("ftp_delivery_path : " + ftp_delivery_path) squish.snooze(60) files = [] squish.snooze(60) try: session = ftplib.FTP(ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) #print session session.cwd(ftp_delivery_path) # Change working directory files = session.nlst() print files for filename in files: print filename if (len(files) == 3): test.fail( "files are transferred to FTP server even though we have cancelled the delivery" ) return False elif (len(files) > 3): test.fail("no of files in the FTP server are more than 3 ") return False elif (len(files) < 3): test.passes("no of files in the FTP server are less than 3 ") return True session.quit() except Exception as e: print e s = str(e) print sys.exc_info() test.log("exception due to :" + s) test.fail("check_contents_in_ftp_server")
def cancelling_delivery(check_delivery_status_url, cancel_delivery_url, delivery_id, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password): test.log("cancelling delivery") files_on_ftp = False delivery_stage = check_delivery_status(check_delivery_status_url, delivery_id) if (delivery_stage == "CREATED" or delivery_stage == "SUBMITTED" or delivery_stage == "STARTED" or delivery_stage == "IN_PROGRESS"): test.log("Delivery successfully cancelled") #cancel the delivery print delivery_stage source(findFile("scripts", "stop_cancel_delivery.py")) delivery_stage = stop_delivery(cancel_delivery_url, delivery_id) squish.snooze(30) delivery_stage = check_delivery_status_until_cancelled( check_delivery_status_url, delivery_id) source(findFile("scripts", "check_contents_on_ftp_after_cancel.py")) delivery_ftp_path = get_delivery_ftp_path(check_delivery_status_url, delivery_id) if (delivery_ftp_path or delivery_ftp_path != None): files_on_ftp = check_contents_in_ftp_server( delivery_ftp_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) if (files_on_ftp): test.passes( "File transfer has been successfully cancelled and contents has been checked on FTP" ) elif (delivery_stage == "CANCELLED"): test.log("Delivery Cancelled") test.passes("Delivery has been successfully cancelled") else: test.fail("Failed to cancel delivery") return
def main(): try: test.log("Test Case Name: tst_create_parse_success_delivery") test.log("create parse success delivery") create_delivery_data_success = { "serviceOriginName": "Dove UI", "callBackEndPoint": None, "callBackReferenceId": None, "requestTime": None, "sourceFile": 'hub://hub-t1/mirriad/storage/QA/GBUV71000779_I_AM_ARROWS_Another Picture Of You_no_P_logo_v2.mov', "deliveryFile": 'hub://hub-t1/mirriad/storage/QA/GBUV71000779_I_AM_ARROWS_Another Picture Of You_with_P_logo_v2.mov', "assetId": '12230', "campaignId": '27120900', "deliveryTargetService": 'VEVO', "revertOperation": False } videoISRC = "GBUV71000779" # I am Arrows data = testData.dataset("s_list_of_webservices.tsv")[0] hub_status_config_url = testData.field(data, "get_delivery_config_get_url") create_delivery_url = testData.field(data, "create_save_delivery_using_post_url") get_delivery_status_url = testData.field(data, "get_delivery_status_url") manifest_parse_success_replace_success = "vevo_status\\parse_success_replace_success\\status-manifest.xml" manifest_parse_success = "vevo_status\\parse_success\\status-manifest.xml" #manifest_parse_success_replace_success = findFile("testdata", "vevo_status\\parse_success_replace_success\\status-manifest.xml") #manifest_parse_success = findFile("testdata", "vevo_status\\parse_success\\status-manifest.xml") delivery_ftp_path = None '''t01 ftp connection login details''' ftp_vevo_host = "ftp.uk.mirriad.com" ftp_vevo_user = "******" ftp_vevo_password = "******" ftp_vevo_port = 21 ftp_vevo_vevo_user = "******" test.log("manifest_parse_success : " + manifest_parse_success) test.log("manifest_parse_success_replace_success : " + manifest_parse_success_replace_success) x = None count = 4 # using count for FTP transfer as a trigger delivery_id = None delivery_stage = None source(findFile("scripts", "create_delivery.py")) delivery_id = create_delivery_first_step(create_delivery_data_success, videoISRC, hub_status_config_url, create_delivery_url, get_delivery_status_url, manifest_parse_success, manifest_parse_success_replace_success, count, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) squish.snooze(60) if(delivery_id or delivery_id != None): source(findFile("scripts", "deliverywebservices.py")) squish.snooze(60) delivery_stage = check_delivery_status(get_delivery_status_url, delivery_id) delivery_ftp_path = get_delivery_ftp_path(get_delivery_status_url, delivery_id, count) '''remove the delivery as it is on waiting on confirmation, you cannot use the same delivery again transfer the file and change the status to completed''' if(delivery_stage == "WAITING_ON_CONFIRMATION"): test.passes("parse_success is successful") source(findFile("scripts", "connect_to_ftpserver.py")) manifest_parse_success_replace_success = findFile("testdata", manifest_parse_success_replace_success) squish.snooze(60) copy_to_ftp_server(manifest_parse_success_replace_success, delivery_ftp_path, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) source(findFile("scripts", "deliverywebservices.py")) squish.snooze(60) delivery_stage = check_delivery_status(get_delivery_status_url, delivery_id) if(delivery_stage == "COMPLETE"): test.passes("parse_success is successful and parse_success_replace_success is also successful") else: test.fail("parse_success_replace_success in parse success delivery has failed, deliveryStage : " + delivery_stage) elif(delivery_stage == "FAILED"): test.fail("Delivery stage is failed after copying parse success file so need not copy parse success replace success file") else: test.fail("parse_success delivery has failed") except Exception as e: print e s = str(e) print sys.exc_info() test.log(s) test.fail("parse_success has failed due to : " + s) testdata = testData.create("shared", "status.failed") try: with open(testdata, "w+") as f: test.log("Failed so create a status file") except Exception as e: print e s = str(e) test.log(s)
def main(): try: test.log("Test Case Name: tst_create_parse_success_replace_failure") test.log("create parse success replace failure delivery") create_delivery_data_success = { "serviceOriginName": "Dove UI", "callBackEndPoint": None, "callBackReferenceId": None, "requestTime": None, "sourceFile": 'hub://hub-t1/mirriad/storage/QA/GBUV71000779_I_AM_ARROWS_Another Picture Of You_no_P_logo_v2.mov', "deliveryFile": 'hub://hub-t1/mirriad/storage/QA/GBUV71000779_I_AM_ARROWS_Another Picture Of You_with_P_logo_v2.mov', "assetId": '12230', "campaignId": '27120900', "deliveryTargetService": 'VEVO', "revertOperation": False } videoISRC = "GBUV71000779" # I am Arrows data = testData.dataset("s_list_of_webservices.tsv")[0] hub_status_config_url = testData.field(data, "get_delivery_config_get_url") create_delivery_url = testData.field(data, "create_save_delivery_using_post_url") get_delivery_status_url = testData.field(data, "get_delivery_status_url") manifest_parse_success_replace_failure = "vevo_status\\parse_success_replace_failure\\status-manifest.xml" manifest_parse_success = "vevo_status\\parse_success\\status-manifest.xml" #manifest_parse_failure = findFile("testdata", "vevo_status\\parse_failure\\status-manifest.xml") #manifest_parse_success_replace_failure = findFile("testdata", "vevo_status\\parse_success_replace_failure\\status-manifest.xml") test.log("manifest_parse_success : " + manifest_parse_success) test.log("manifest_parse_success_replace_failure : " + manifest_parse_success_replace_failure) '''t01 ftp connection login details''' ftp_vevo_host = "ftp.uk.mirriad.com" ftp_vevo_user = "******" ftp_vevo_password = "******" ftp_vevo_port = 21 ftp_vevo_vevo_user = "******" x = None count = 2 # using count for FTP to transfer the status-manifest file as a trigger delivery_id = None initial_failure = False delivery_stage = None source(findFile("scripts", "create_delivery.py")) delivery_id = create_delivery_first_step(create_delivery_data_success, videoISRC, hub_status_config_url, create_delivery_url, get_delivery_status_url, manifest_parse_success, manifest_parse_success_replace_failure, count, ftp_vevo_host, ftp_vevo_user, ftp_vevo_password) squish.snooze(60) if(delivery_id or delivery_id != None): source(findFile("scripts", "deliverywebservices.py")) #wait for 30 seconds here because delivery stage = waiting on confirmation squish.snooze(60) delivery_stage = check_delivery_status(get_delivery_status_url, delivery_id) else: test.log("Initial Delivery Failed") initial_failure = True if(delivery_stage == "FAILED" and initial_failure == False): test.passes("parse_success_replace_failure is successful") else: test.fail("parse_success_replace_failure delivery has failed, deliveryStage : ") except Exception as e: print e s = str(e) print sys.exc_info() test.log(s) test.fail("parse_success_replace_failure has failed due to :" + s) testdata = testData.create("shared", "status.failed") try: with open(testdata, "w+") as f: test.log("Failed so create a status file") except Exception as e: print e s = str(e) test.log(s)