How to use prepare_attachment method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

RandomPostAction.py

Source:RandomPostAction.py Github

copy

Full Screen

...62 code_logger.info(f'In RandomPostAction.choose_post. Random offset: {random_offset}')63 one_post = helpers.make_request_vk('wall.get', personal=True, chat_owner=self.chat_owner, count=1,64 offset=random_offset, owner_id=self.workgroup)['response']['items'][0]65 return one_post66 def prepare_attachment(self, one_post):67 one_post_id = one_post['id']68 code_logger.info(f'ID of the post that will be sent: {one_post_id}')69 attachment = 'wall' + self.workgroup + '_' + str(one_post_id)70 return attachment71 def process(self):72 self.workgroup = '-' + str(self.setting_db_object.random_post_group_id)73 code_logger.info(f'In RandomPostAction.process. ID of the workgroup: {self.workgroup}')74 post_quantity = self.get_post_quantity()75 code_logger.debug(76 f'In RandomPostAction.process. Number of posts on the workgroup wall: {post_quantity}')77 if post_quantity == 0:78 raise PrerequisitesError(self.input_message, bot_response="Стена пуста.")79 one_post = self.choose_post(post_quantity)80 attachment = self.prepare_attachment(one_post)81 return BotAnswer("RANDOM_POST_SENT", self.input_message,82 bot_response={83 "attachment": attachment, "peer_id": self.chat_id,84 # /post command can be called from user chat, that's why we have to use chat_id...

Full Screen

Full Screen

email_dispatch.py

Source:email_dispatch.py Github

copy

Full Screen

...42 #process attachments if present43 if attachments != None:44 try:45 for attachment in attachments:46 att = prepare_attachment(attachment)47 if att != None:48 msg.attach(att)49 except:50 att = prepare_attachment(attachments)51 if att != None:52 msg.attach(att)53 try:54 with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:55 smtp.login(config.get_email_address(), config.get_email_pass())56 smtp.send_message(msg)57 smtp.close()58 clear_error(config.CONFIG_DIR)59 return True60 except:61 if config.can_debug():62 print('Email send failed') #COuld not connected to the email server, make sure connected to interet63 write_error(config.CONFIG_DIR)64 return False65def prepare_attachment(att):66 """67 Packages the file at the provided path and returns it as an attachment68 Returns None if the parameter is not a file69 """70 if not Path(att).is_file:71 return None72 m_type, encoding = mimetypes.guess_type(att)73 if m_type is None or encoding is not None:74 m_type = "application/octet-stream"75 maintype, subtype = m_type.split("/", 1)76 if maintype == "text":77 with open(att) as file:78 attachment = MIMEText(file.read(), _subtype=subtype)79 elif maintype == "image":...

Full Screen

Full Screen

nsendfilebyemail.py

Source:nsendfilebyemail.py Github

copy

Full Screen

...70 file_pointer = open(filename, "rb")71 data = file_pointer.read()72 file_pointer.close()73 return data74def prepare_attachment(filename):75 data = load_data_from_file(filename)76 attachment = MIMEBase("application", "octet-stream")77 attachment.set_payload(data)78 encoders.encode_base64(attachment)79 attachment.add_header('Content-Disposition', 'attachment', filename=filename)80 return attachment81def prepare_email(fromaddr, recvaddr, filename):82 message = MIMEMultipart()83 message['Subject'] = filename84 message['To'] = recvaddr85 message['From'] = fromaddr86 attachment = prepare_attachment(filename)87 message.attach(attachment)88 return message89def send_email(message, smtp_address, username, password, tls=True, debug=False):90 server = SMTP(smtp_address)91 server.set_debuglevel(debug)92 if tls:93 server.starttls()94 server.login(username, password)95 server.sendmail(fromaddr, destaddr, message.as_string())96 server.quit()97print "Prepared to send messages..."98for file_num in xrange(0, len(filenames)):99 print "(%d/%d) Sending" % (file_num+1, len(filenames)), filenames[file_num], ": ",100 sys.stdout.flush()...

Full Screen

Full Screen

attachment_service.py

Source:attachment_service.py Github

copy

Full Screen

...6from models.employee_model import EmployeeType7from repositories import attachment_repository, employee_repository, Attachment8from . import default_page_size9from .employee_service import prepare_employee10def prepare_attachment(attachment: Attachment) -> dict:11 result = attachment.get_dict()12 result["author"] = prepare_employee(attachment.author_ref)13 result["size"] = attachment_repository.get_attachment_size(attachment.id)14 result["filename"] = attachment_repository.get_attachment_path_and_filename(attachment.id)[1]15 result["post"] = attachment.post16 result["id"] = attachment.id17 return result18def save_attachment(employee_id: str, attachment_file: FileStorage) -> dict:19 attachment = Attachment()20 attachment.author = employee_id21 attachment.post = None22 attachment.id = str(uuid4())23 return prepare_attachment(attachment_repository.add_attachment(attachment, attachment_file))24def get_attachment(attachment_id: str) -> Response:25 if not attachment_repository.get_attachment_by_id(attachment_id):26 abort(404, "Attachment not found")27 return send_from_directory(28 attachment_repository.path_from_id(attachment_id),29 attachment_repository.get_attachment_path_and_filename(attachment_id)[1],30 as_attachment=True31 )32def delete_attachment(employee_id: str, attachment_id: str) -> None:33 attachment = attachment_repository.get_attachment_by_id(attachment_id)34 if not attachment:35 abort(404, "Attachment not found")36 if attachment.author != employee_id:37 employee = employee_repository.get_employee_by_id(employee_id)38 if not employee or employee.user_type != EmployeeType.admin.value:39 abort(403, "You can not remove attachments of other users")40 attachment_repository.delete_attachment(attachment)41def attachments_pages_count(employee_id: str) -> int:42 return ceil(attachment_repository.get_user_attachments_count(employee_id) / default_page_size)43def get_all_attachments(employee_id: str, page: int) -> Dict[str, List[Dict] or int]:44 if not employee_repository.get_employee_by_id(employee_id):45 abort(404, "Employee not found")46 pages_count = attachments_pages_count(employee_id)47 if page <= pages_count:48 attachments = attachment_repository.get_user_attachments(employee_id, page, default_page_size)49 else:50 attachments = []51 return {52 "attachments": [prepare_attachment(attachment) for attachment in attachments],53 "pages_count": pages_count...

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 Lemoncheesecake 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