Best Python code snippet using localstack_python
sns.py
Source:sns.py
...80 deletedEndpoint = client.delete_endpoint(81 EndpointArn=endpointArn82 )83 return deletedEndpoint84 def delete_platform_application(self, client, platformApplicationArn):85 deletedPlatformApplication = client.delete_platform_application(86 PlatformApplicationArn=platformApplicationArn87 )88 return deletedPlatformApplication89 def push_apns(self, section, client, pushToken, message=None):90 key_str, cer_str, key_filename, cer_filename=('',)*491 config = configparser.ConfigParser()92 config.read(os.path.abspath(os.path.join(os.path.dirname(__file__), 'sns_config.ini')))93 if config.sections() != None:94 try:95 key_filename = config.get(section, 'apns_key_filename')96 cer_filename = config.get(section, 'apns_cer_filename')97 except:98 print("there's no filename to push notification.")99 return100 else:101 print("check your config...")102 return103 try:104 dir_name = os.path.dirname(__file__)105 key_path = os.path.abspath(os.path.join(dir_name, key_filename))106 cer_path = os.path.abspath(os.path.join(dir_name, cer_filename))107 key = open(key_path, 'r')108 cer = open(cer_path, 'r')109 key_str = key.read()110 cer_str = cer.read()111 if key_str == '' or cer_str == '':112 print('key file or cer file is invalid...')113 return114 except FileNotFoundError:115 print("please check if file is exist")116 return117 ### apns118 apns_attributes = {119 "PlatformCredential": key_str,120 "PlatformPrincipal": cer_str121 }122 #print (key_str + "---------")123 #print (cer_str + "---------")124 platform = 'APNS'125 responseAPNS = self.create_platform_application(client, platform, key_str, cer_str)126 print ("APNS: {}".format(responseAPNS))127 platformApplicationArn = responseAPNS['PlatformApplicationArn']128 platformEndpoint = self.create_endpoint(client, platformApplicationArn, pushToken)129 endpointArn = platformEndpoint['EndpointArn']130 print ("endpoint: {}".format(endpointArn))131 msg = self.get_push_message_apns(message)132 response = self.publish(client, endpointArn, msg)133 print ("published: {}".format(response))134 deletedEndpoint = self.delete_endpoint(client, endpointArn)135 print("delete endpoint: {}".format(deletedEndpoint))136 deletedPlatformApplication = self.delete_platform_application(client, platformApplicationArn)137 print("delete platform application: {}".format(deletedPlatformApplication))138 def push_gcm(self, section, client, registrationId, message=None):139 config = configparser.ConfigParser()140 config.read(os.path.abspath(os.path.join(os.path.dirname(__file__), 'sns_config.ini')))141 server_key = None142 if config.sections() != None:143 try:144 server_key = config.get(section, 'serverKey')145 print("serverKey: {}".format(server_key))146 except:147 print("there's no serverKey to create GCM application")148 return149 responseGCM = self.create_platform_application(client, 'GCM', server_key, '')150 print("PlatformApplicationArn: {}".format(responseGCM['PlatformApplicationArn']))151 platform_application_arn = responseGCM['PlatformApplicationArn']152 platformEndpoint = self.create_endpoint(client, platform_application_arn, registrationId)153 endpointArn = platformEndpoint['EndpointArn']154 print ("endpoint: {}".format(endpointArn))155 msg = self.get_push_message_gcm(message)156 response = self.publish(client, endpointArn, msg)157 print ("published: {}".format(response))158 deletedEndpoint = self.delete_endpoint(client, endpointArn)159 print("delete endpoint: {}".format(deletedEndpoint))160 deletedPlatformApplication = self.delete_platform_application(client, platform_application_arn)161 print("delete platform application: {}".format(deletedPlatformApplication))162if __name__ == "__main__":163 sns = SNSObject()164 client = boto3.client('sns')165 section = input("please insert sectdion name: ")166 selected = input("please insert your choice: (1 - GCM, 2 - APNS) ")167 pushToken = input('please insert your pushToken: ')168 message = input('please insert message. if you don\'t insert it, you\'ll get the default message: ')169 if selected == '2':170 if len(message) > 0:171 sns.push_apns(section, client, pushToken, message)172 else:173 sns.push_apns(section, client, pushToken)174 else:...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!