How to use test_arn method in localstack

Best Python code snippet using localstack_python

test_Misc.py

Source:test_Misc.py Github

copy

Full Screen

1import unittest2from misc import Misc3from misc.Logger import logger4class TestMiscMethods(unittest.TestCase):5 def test_str2bool_true(self):6 self.assertTrue(Misc.str2bool("true"))7 self.assertTrue(Misc.str2bool("True"))8 self.assertTrue(Misc.str2bool("t"))9 self.assertTrue(Misc.str2bool("1"))10 self.assertTrue(Misc.str2bool("yes"))11 def test_str2bool_false(self):12 self.assertFalse(Misc.str2bool("false"))13 self.assertFalse(Misc.str2bool("False"))14 self.assertFalse(Misc.str2bool("f"))15 self.assertFalse(Misc.str2bool("0"))16 self.assertFalse(Misc.str2bool("no"))17 self.assertFalse(Misc.str2bool("ILIKECARS"))18 def test_dict_flatten_correct_path(self):19 should_be = {'a_b': 1, 'a_a': 2, 'b': {'a': 3}}20 start = {'a': {'b': 1, 'a': 2}, 'b': {'a': 3}}21 result = Misc.merge_flatten_dict(dictionary=start, key='a')22 self.assertDictEqual(should_be, result)23 def test_dict_flatten_incorrect_path(self):24 should_be = {'a': {'b': 1, 'a': 2}, 'b': {'a': 3}}25 start = {'a': {'b': 1, 'a': 2}, 'b': {'a': 3}}26 result = Misc.merge_flatten_dict(dictionary=start, key='c')27 self.assertDictEqual(should_be, result)28 def test_dict_flatten_correct_path_no_action(self):29 should_be = {'a': {'b': 1, 'a': 2}, 'b': 3}30 start = {'a': {'b': 1, 'a': 2}, 'b': 3}31 result = Misc.merge_flatten_dict(dictionary=start, key='b')32 self.assertDictEqual(should_be, result)33 def test_remove_last_n_chars_default(self):34 string = "12345"35 should_be = "1234"36 result = Misc.remove_last_n_char(string=string)37 self.assertEqual(result, should_be)38 def test_remove_last_n_chars_more_chars(self):39 string = "12345"40 should_be = "123"41 result = Misc.remove_last_n_char(string=string, char_num=2)42 self.assertEqual(result, should_be)43 def test_remove_last_n_chars_non_int(self):44 string = "12345"45 should_be = "12345"46 result = Misc.remove_last_n_char(string=string, char_num="a")47 self.assertEqual(result, should_be)48 def test_join_string_to_list_default(self):49 list = ['a', 'b']50 should_be = "a,b"51 result = Misc.join_list_to_string(list=list)52 self.assertEqual(should_be, result)53 def test_join_string_to_list_special_char(self):54 list = ['a', 'b']55 should_be = "a_b"56 result = Misc.join_list_to_string(list=list, join_with="_")57 self.assertEqual(should_be, result)58 def test_join_string_to_list_invalid_list(self):59 list = "abs"60 should_be = "a_b_s"61 result = Misc.join_list_to_string(list=list, join_with="_")62 self.assertEqual(should_be, result)63 def test_string_to_array_default(self):64 string = "test.test2.test3"65 should_be = ['test', 'test2', 'test3']66 result = Misc.string_to_array(string=string)67 self.assertEqual(should_be, result)68 def test_string_to_array_special_char(self):69 string = "test_test2_test3"70 should_be = ['test', 'test2', 'test3']71 result = Misc.string_to_array(string=string, split_char="_")72 self.assertEqual(should_be, result)73 def test_string_to_array_nothing_to_split(self):74 string = "test"75 should_be = ['test']76 result = Misc.string_to_array(string=string)77 self.assertEqual(should_be, result)78 def test_list_to_multiline_default(self):79 list = ["test", "test2"]80 should_be = "test\ntest2"81 result = Misc.list_to_multiline_string(list=list)82 self.assertEqual(should_be, result)83 def test_list_to_multiline_non_list(self):84 list = "test"85 should_be = "t\ne\ns\nt"86 result = Misc.list_to_multiline_string(list=list)87 self.assertEqual(should_be, result)88 def test_get_value_from_array_hash(self):89 array_hash = [{'Key': 'test', 'Value': 'test_value'}, {'Key': 'test2', 'Value': 'test2_value'}]90 result = Misc.get_value_from_array_hash(dictlist=array_hash, key="test2")91 self.assertEqual("test2_value", result)92 def test_get_value_from_array_hash_invalid_key(self):93 array_hash = [{'Key': 'test', 'Value': 'test_value'}, {'Key': 'test2', 'Value': 'test2_value'}]94 result = Misc.get_value_from_array_hash(dictlist=array_hash, key="test3")95 self.assertEqual(None, result)96 def test_get_value_from_array_hash_empty_array(self):97 array_hash = []98 result = Misc.get_value_from_array_hash(dictlist=array_hash, key="test3")99 self.assertEqual(None, result)100 def test_merge_dicts(self):101 dict_a = {'a': 1, 'b': 2}102 dict_b = {'c': 3, 'd': 4}103 should_be = {'a': 1, 'b': 2, 'c': 3, 'd': 4}104 result = Misc.merge_dicts(dict1=dict_a, dict2=dict_b)105 self.assertDictEqual(should_be, result)106 def test_merge_dicts_overlapping_key_same_value(self):107 dict_a = {'a': 1, 'b': 2}108 dict_b = {'b': 2, 'd': 4}109 should_be = {'a': 1, 'b': 2, 'd': 4}110 result = Misc.merge_dicts(dict1=dict_a, dict2=dict_b)111 self.assertDictEqual(should_be, result)112 def test_merge_dicts_overlapping_key_different_value(self):113 dict_a = {'a': 1, 'b': 2}114 dict_b = {'b': 3, 'd': 4}115 with self.assertRaises(Exception) as cm:116 Misc.merge_dicts(dict1=dict_a, dict2=dict_b)117 self.assertTrue('Conflict at b' in cm.exception)118 def test_parse_service_columns_empty(self):119 columns = ""120 keys = Misc.ec2_columns.keys()121 self.assertListEqual(keys, Misc.parse_service_columns(service="ec2",columns=columns))122 def test_parse_service_columns_2_column(self):123 columns = "id,vpc_id,notexist"124 keys = ["id", "vpc_id"]125 self.assertListEqual(keys, Misc.parse_service_columns(service="ec2",columns=columns))126 def test_parse_service_columns_all_column(self):127 keys = Misc.ec2_columns.keys()128 columns = ",".join(keys)129 self.assertListEqual(keys, Misc.parse_service_columns(service="ec2",columns=columns))130 def test_parse_service_columns_with_services_cloudformation(self):131 columns = ""132 keys = Misc.get_supported_columns(service="cloudformation").keys()133 self.assertListEqual(keys, Misc.parse_service_columns(service="cloudformation",columns=columns))134 def test_parse_service_columns_with_services_elb(self):135 columns = ""136 keys = Misc.get_supported_columns(service="elb").keys()137 self.assertListEqual(keys, Misc.parse_service_columns(service="elb",columns=columns))138 def test_format_boto3_filter(self):139 filters = "tag-value:test"140 should_be = [{'Name': 'tag-value', 'Values': ['test']}]141 self.assertEqual(should_be, Misc.format_boto3_filter(filters=filters))142 def test_format_boto3_filter_invalid_filter(self):143 filters = "tag:value:test"144 with self.assertRaises(ValueError) as cm:145 Misc.format_boto3_filter(filters=filters)146 self.assertTrue('too many values to unpack' in cm.exception)147 def test_format_boto3_filter_multiple_values(self):148 filters = "tag-value:test,tag-test:test2"149 should_be = [{'Name': 'tag-value', 'Values': ['test']}, {'Name': 'tag-test', 'Values': ['test2']}]150 self.assertEqual(should_be, Misc.format_boto3_filter(filters=filters))151 def test_parse_arn_base_resource(self):152 test_arn = "arn:partition:service:region:account-id:resource"153 should_be = {'arn': 'arn', 'partition': 'partition', 'service': 'service', 'region': 'region',154 'account-id': 'account-id', 'resource': 'resource'}155 result = Misc.parse_arn(arn=test_arn)156 self.assertDictEqual(should_be, result)157 def test_parse_arn_base_resource_sub_resouce(self):158 test_arn = "arn:partition:service:region:account-id:resource/resource"159 should_be = {'arn': 'arn', 'partition': 'partition', 'service': 'service', 'region': 'region',160 'account-id': 'account-id', 'resource': 'resource/resource'}161 result = Misc.parse_arn(arn=test_arn)162 self.assertDictEqual(should_be, result)163 def test_parse_arn_base_resource_extra_column(self):164 test_arn = "arn:partition:service:region:account-id:resource:resource_sub"165 should_be = {'arn': 'arn', 'partition': 'partition', 'service': 'service', 'region': 'region',166 'account-id': 'account-id', 'resource': 'resource', 'resource_sub': 'resource_sub'}167 result = Misc.parse_arn(arn=test_arn)168 self.assertDictEqual(should_be, result)169 def test_parse_arn_base_resource_invalid_arn(self):170 test_arn = "yes"171 should_be = None172 result = Misc.parse_arn(arn=test_arn)173 self.assertEqual(should_be, result)174 def test_random3digit(self):175 random = Misc.random3digit()176 self.assertRegexpMatches(random,"\d{1,3}")177 def test_get_supported_columns_for_ec2(self):178 should_be = Misc.ec2_columns179 result = Misc.get_supported_columns(service="ec2")180 self.assertEqual(should_be,result)181 def test_get_supported_columns_for_cloudformation(self):182 should_be = Misc.cloudformation_columns183 result = Misc.get_supported_columns(service="cloudformation")184 self.assertEqual(should_be,result)185 def test_get_supported_columns_for_empty(self):186 should_be = None187 result = Misc.get_supported_columns(service="NotExistService")188 self.assertEqual(should_be,result)189# To remove warning and error printing...

Full Screen

Full Screen

devicefarm.py

Source:devicefarm.py Github

copy

Full Screen

1'''2Uploads an APK and a test APK to AWS Device Farm and runs the Espresso tests.3Exit code is 0 if all tests pass, 1 otherwise. See README.md for details.4'''5from time import sleep6import argparse7import boto38import requests9'''10Parser11'''12parser = argparse.ArgumentParser(13 prog='Device Farm Runner',14 description='Runs the Espresso tests on AWS Device Farm.',15 formatter_class=argparse.ArgumentDefaultsHelpFormatter,16 add_help=True)17parser.add_argument('--project-arn',18 type=str, help='The project ARN (Amazon Resource Name)')19parser.add_argument('--device-pool-arn',20 type=str, help='The device pool ARN (Amazon Resource Name)')21parser.add_argument('--app-apk-path',22 type=str, help='Path to the app APK')23parser.add_argument('--test-apk-path',24 type=str, help='Path to the tests APK')25args = vars(parser.parse_args())26project_arn = args.get('project_arn')27device_pool_arn = args.get('device_pool_arn')28app_apk_path = args.get('app_apk_path')29test_apk_path = args.get('test_apk_path')30# Check31if not project_arn or not device_pool_arn:32 raise Exception('You need to set both the project and the device pool ARN.')33elif not app_apk_path or not test_apk_path:34 raise Exception('You need to set both the app and test APK path.')35'''36The AWS Device Farm client37'''38client = boto3.client('devicefarm', region_name='us-west-2')39'''40Methods41'''42def upload_apk(apk_name, apk_path, apk_type):43 print 'Starting upload: %s' % apk_type44 result = client.create_upload(45 projectArn=project_arn, name=apk_name, type=apk_type)46 presigned_url = result.get('upload').get('url')47 upload_arn = result.get('upload').get('arn')48 # PUT the file content and wait49 put_file(apk_path=apk_path, presigned_url=presigned_url)50 wait_for_upload(upload_arn=upload_arn)51 return upload_arn52def put_file(apk_path, presigned_url):53 print 'Uploading: %s' % apk_path54 with open(apk_path, 'rb') as f:55 data = f.read()56 result = requests.put(presigned_url, data=data)57 if result.status_code != 200:58 raise Exception(59 'PUT failed with status code: %s' % result.status_code)60def wait_for_upload(upload_arn):61 print 'Checking if the upload succeeded.'62 succeeded = False63 while not succeeded:64 result = client.get_upload(arn=upload_arn)65 status = result.get('upload').get('status')66 succeeded = (status == 'SUCCEEDED')67 if status == 'FAILED':68 raise Exception('Upload failed.')69 elif not succeeded:70 print 'Upload is not ready (status is %s), waiting for 5 seconds.' % status71 sleep(5)72def schedule_run(app_arn, test_arn):73 print 'Scheduling a run.'74 result = client.schedule_run(75 projectArn=project_arn,76 appArn=app_arn,77 devicePoolArn=device_pool_arn,78 name='automated_run',79 test={ 'type': 'INSTRUMENTATION', 'testPackageArn': test_arn})80 run_arn = result.get('run').get('arn')81 return_code = wait_for_run(run_arn=run_arn)82 return return_code83def wait_for_run(run_arn):84 print 'Checking if the run succeeded.'85 return_code = ''86 succeeded = False87 while not succeeded:88 result = client.get_run(arn=run_arn)89 status = result.get('run').get('status')90 return_code = result.get('run').get('result')91 succeeded = (status == 'COMPLETED')92 if not succeeded:93 print 'Run not completed (status is %s), waiting for 60 seconds.' % status94 sleep(60)95 return return_code96'''97Main flow98'''99# 1. Upload the app APK100app_arn = upload_apk(101 apk_name='app-debug-unaligned.apk',102 apk_path=app_apk_path,103 apk_type='ANDROID_APP')104# 2. Upload the test APK105test_arn = upload_apk(106 apk_name='app-debug-androidTest-unaligned.apk',107 apk_path=test_apk_path,108 apk_type='INSTRUMENTATION_TEST_PACKAGE')109# 3. Schedule the run110return_code = schedule_run(app_arn=app_arn, test_arn=test_arn)111exit_code = 0 if return_code == 'PASSED' else 1112print 'Run completed: %s' % return_code...

Full Screen

Full Screen

arn_test.py

Source:arn_test.py Github

copy

Full Screen

1from tests import mock, unittest2from tests.models import arn3ARN = arn.ARN4INVALID_ARN_ERROR_MSG_TEMPLATE = arn.INVALID_ARN_ERROR_MSG_TEMPLATE5TEST_ARN = 'arn:aws:lambda:us-west-2:000000000000:function:test-function-name'6class ArnTest(unittest.TestCase):7 def setUp(self):8 self.target = ARN9 def test_should_return_an_error_if_incorrect_arn_passed(self):10 error = None11 error_msg = None12 try:13 ARN('ABC')14 except Exception as e:15 error = e16 error_msg = str(e)17 self.assertIsNotNone(error)18 self.assertIsNotNone(error_msg)19 self.assertEquals(error_msg, INVALID_ARN_ERROR_MSG_TEMPLATE.format('ABC'))20 21 def test_should_return_a_valid_object_if_correct_arn_passed(self):22 obj = ARN(TEST_ARN)23 self.assertIsNotNone(obj)24 self.assertEquals(obj.__class__.__module__, 'aws_lambda_client.models.arn')25 26 27 def test_should_parse_and_return_partition(self):28 obj = ARN(TEST_ARN)29 self.assertIsNotNone(obj)30 self.assertEquals(obj.get_partition(), 'aws')31 32 def test_should_parse_and_return_account(self):33 obj = ARN(TEST_ARN)34 self.assertIsNotNone(obj)35 self.assertEquals(obj.get_account(), '000000000000')36 37 def test_should_parse_and_return_region(self):38 obj = ARN(TEST_ARN)39 self.assertIsNotNone(obj)40 self.assertEquals(obj.get_region(), 'us-west-2')41 def test_should_parse_and_return_function_name(self):42 obj = ARN(TEST_ARN)43 self.assertIsNotNone(obj)44 self.assertEquals(obj.get_resource_name(), 'test-function-name')45 46 def test_should_parse_and_return_resource(self):47 obj = ARN(TEST_ARN)48 self.assertIsNotNone(obj)49 self.assertEquals(obj.get_resource(), 'function')50 def test_should_parse_and_return_service(self):51 obj = ARN(TEST_ARN)52 self.assertIsNotNone(obj)53 self.assertEquals(obj.get_service(), 'lambda')54 def test_should_parse_and_return_all_details(self):55 obj = ARN(TEST_ARN)56 details = obj.get_details()57 self.assertIsNotNone(obj)58 self.assertIsNotNone(details)59 self.assertEquals(details.get('service'), 'lambda')60 self.assertEquals(details.get('resource_name'), 'test-function-name')61 self.assertEquals(details.get('resource'), 'function')62 self.assertEquals(details.get('region'), 'us-west-2')63 self.assertEquals(details.get('account'), '000000000000')64 self.assertEquals(details.get('partition'), 'aws')65 66 def test_should_return_original_arn_as_str_representation(self):67 test_arn = TEST_ARN68 obj = ARN(test_arn)69 self.assertIsNotNone(obj)70 self.assertEquals(str(obj), test_arn)...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful