How to use send_invalid method in localstack

Best Python code snippet using localstack_python

users.py

Source:users.py Github

copy

Full Screen

...5354 return False555657def send_invalid(message, reddit):58 """Sends a invalid message to the user."""59 m = "Sorry, I couldn't understand the location, of you gave a invalid radius. Please try again with a new message."60 reddit.redditor(message.author.name).message("Invalid subscription!", m)61 return626364def read_messages(send_flag, reddit):65 """Reads new messages. Returns two list of User objects, to add and remove."""66 unsubscribe = list()67 subscribe = list()68 unread = list()6970 for m in reddit.inbox.unread(limit=None):71 if isinstance(m, praw.models.Message):72 if m.subject.lower().strip() == 'subscribe': # message to be treated73 text = m.body74 # country, city (radius)75 '''76 if "(" in text and ")" in text:77 radius = (text[text.find('(') + 1:text.find(")")]) # gets the radius78 try:79 radius = float(radius) # checks if the radius is a float.80 text = text[:text.find('(')]81 except ValueError: # checks if error82 send_invalid(m, reddit) # tell user he is wrong83 unread.append(m) # reads the message84 continue85 print(radius)86 elif "(" in text or ")" in text:87 send_invalid(m, reddit) # if it passes here, the radius is wrong88 unread.append(m)89 continue90 else:91 radius = -19293 if "," in text: # city!94 [country, city] = text.split(",")95 city = city.strip().upper()96 else:97 [country, city] = [text, None]98 '''99 if ')' in text and '(' in text: # radius is defined100 r = re.match('([a-zA-Z ]+),([a-zA-Z ]+)(\\([0-9]+\\))', text)101 if r is None: # invalid radius102 if not send_flag:103 print("invalid:", text)104 else:105 send_invalid(m, reddit)106 unread.append(m)107 continue108 country, city = text.split(',')109 radius = int(re.search('([0-9]+)', city).group(0)) # get the radius110 city = city.split('(')[0]111112 else: # no radius, only city or country113 if re.match('([a-zA-Z ]+),([a-zA-Z ]+)', text) is not None: # COUNTRY, CITY114 country, city = text.split(',')115 elif re.match('([a-zA-Z ]+)', text) is not None:116 country, city = text, None117 else:118 if not send_flag:119 print("invalid:", text)120 else:121 send_invalid(m, reddit)122 unread.append(m)123 continue124 radius = -1125126 country = country.strip().upper()127 city = city.strip().upper() if city is not None else city128129 u = User(m.author.name, city, country, radius)130 subscribe.append(u)131 if send_flag:132 unread.append(m)133134 elif m.subject.lower().strip() == 'unsubscribe':135 unsubscribe.append(m.author.name) ...

Full Screen

Full Screen

smtp_parameter_validation_test.py

Source:smtp_parameter_validation_test.py Github

copy

Full Screen

...7class SMTPParameterValidationTest(CommandParserTestCase):8 def last_server_message(self):9 last_code, last_message = self.command_parser.replies[-1]10 return last_message11 def send_invalid(self, command, data=None):12 return super(SMTPParameterValidationTest, self).send(command, data=data, expected_first_digit=5)13 def send_valid(self, command, data=None):14 return super(SMTPParameterValidationTest, self).send(command, data=data, expected_first_digit=2)15 # -------------------------------------------------------------------------16 # helo/ehlo17 def test_helo_accepts_exactly_one_parameter(self):18 self.send_invalid('helo')19 self.send_invalid('helo', 'foo bar')20 self.send_invalid('helo', '')21 def test_ehlo_accepts_exactly_one_parameter(self):22 self.send_invalid('ehlo')23 self.send_invalid('ehlo', 'foo bar')24 # -------------------------------------------------------------------------25 # commands without parameters26 def helo(self):27 self.send_valid('helo', 'fnord')28 def test_noop_does_not_accept_any_parameters(self):29 self.helo()30 self.send_invalid('noop', 'foo')31 def test_rset_does_not_accept_any_parameters(self):32 self.helo()33 self.send_invalid('rset', 'foo')34 def test_quit_does_not_accept_any_parameters(self):35 self.helo()36 self.send_invalid('quit', 'invalid')37 def test_data_does_not_accept_any_parameters(self):38 self.helo_and_mail_from()39 self.send_valid('rcpt to', 'foo@example.com')40 self.send_invalid('data', 'invalid')41 # -------------------------------------------------------------------------42 # MAIL FROM43 def test_mail_from_requires_an_email_address(self):44 self.helo()45 self.send_invalid('mail from')46 self.send_invalid('mail from', 'foo@@bar')47 def test_mail_from_must_not_have_extensions_for_plain_smtp(self):48 self.helo()49 self.send_invalid('mail from', '<foo@example.com> SIZE=100')50 assert_equals('No SMTP extensions allowed for plain SMTP.', self.last_server_message())51 def ehlo(self):52 self.send_valid('ehlo', 'fnord')53 def test_mail_from_validates_size_extension(self):54 self.ehlo()55 self.send_invalid('mail from', '<foo@example.com> SIZE=fnord')56 def test_mail_from_rejects_unknown_extension(self):57 self.send_valid('ehlo', 'fnord')58 self.send_invalid('mail from', '<foo@example.com> FNORD=INVALID')59 assert_equals('Invalid extension: "FNORD=INVALID"', self.last_server_message())60 def helo_and_mail_from(self):61 self.helo()62 self.send_valid('mail from', 'foo@example.com')63 # -------------------------------------------------------------------------64 # RCPT TO65 def test_rcpt_to_requires_an_email_address(self):66 self.helo_and_mail_from()67 self.send_invalid('rcpt to')68 self.send_invalid('rcpt to foo@@bar.com')69 self.send_invalid('rcpt to foo@bar.com invalid')70 def test_rcpt_to_accepts_a_valid_email_address(self):71 self.helo_and_mail_from()72 self.send_valid('rcpt to', 'foo@example.com')73 self.send_valid('rcpt to', '<foo@example.com>')74 # -------------------------------------------------------------------------75 # AUTH PLAIN76 def inject_authenticator(self):77 self.session._authenticator = DummyAuthenticator()78 def base64(self, value):79 return b64encode(value).strip()80 def test_auth_plain_accepts_correct_authentication(self):81 self.inject_authenticator()82 self.ehlo()83 self.send_valid('AUTH PLAIN', b64encode('\x00foo\x00foo'))84 def test_auth_plain_requires_exactly_one_parameter(self):85 self.inject_authenticator()86 self.ehlo()87 self.send_invalid('AUTH PLAIN')88 base64_credentials = self.base64('\x00foo\x00foo')89 self.send_invalid('AUTH PLAIN', base64_credentials + ' ' + base64_credentials)90 def test_auth_plain_detects_bad_base64_credentials(self):91 self.inject_authenticator()92 self.ehlo()93 self.send_invalid('AUTH PLAIN')94 self.send_invalid('AUTH PLAIN', 'invalid_base64')95 def test_auth_plain_reject_bad_credentials(self):96 self.inject_authenticator()97 self.ehlo()...

Full Screen

Full Screen

get_request_from_DM.py

Source:get_request_from_DM.py Github

copy

Full Screen

...26def send_help(thread):27 cl.direct_send(thread_ids = [thread.id], text = "==== How to use ====\n1. DM detection\nPlease send me one photo")28 cl.direct_send(thread_ids = [thread.id], text = "2. Feed detection\nPlease send me '/feed n'\n(Most recent feed number is 1)")29 cl.direct_send(thread_ids = [thread.id], text = "3. Story detection\nPlease send me '/story n'\n(Most recent story number is 1)")30def send_invalid(thread):31 cl.direct_send(thread_ids = [thread.id], text = "Invalid execution! If you need help, please send me '/help'")32def send_invalid_bound(thread):33 cl.direct_send(thread_ids = [thread.id], text = "Invalid bound! If you need help, please send me '/help'")34def download_DM(thread):35 download_path = make_directory_save_images(thread.messages[0])36 cl.photo_download(thread.messages[0].media.id, download_path)37def download_feed(thread, photo_number):38 if str(type(photo_number)) != 'int':39 send_invalid(thread)40 else:41 target_media_pk = cl.user_medias(thread.messages[0].user_id, photo_number)[photo_number-1].pk42 if target_media_pk == None:43 send_invalid_bound(thread)44 else:45 cl.photo_download(target_media_pk, download_path)46def download_story(thread, story_number):47 if str(type(story_number)) != 'int':48 send_invalid(thread)49 else:50 target_story_pk = cl.user_storys(thread.messages[0].user_id, story_number)[story_number-1].pk51 if target_story_pk == None:52 send_invalid_bound(thread)53 else:54 cl.story_download(target_story_pk, download_path)55def get_request_from_DM(thread):56 most_recent_message = thread.messages[0]57 check_help = parse('/{}', most_recent_message.text)[0]58 detection_mode = parse('/{} {}', most_recent_message.text)[0]59 if get_media_type_of_message(most_recent_message) == -1: # Check 'text'60 if check_help == 'help':61 send_help(thread)62 else:63 if detection_mode[0] == 'feed':64 download_feed(thread, detection_mode[1])65 elif detection_mode[0] == 'story':66 download_story(thread, detection_mode[1])67 else:68 send_invalid(thread)69 elif get_media_type_of_message(most_recent_message) == 1: # Photo70 download_DM(thread)71 else: # default case...

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