How to use portrait method in robotframework-appiumlibrary

Best Python code snippet using robotframework-appiumlibrary_python

request.py

Source:request.py Github

copy

Full Screen

...20 """ This will update the data in case it has been changed in the API """21 photobooth = Photobooth.get()22 updated = figure.Photobooth.get(settings.RESIN_UUID)23 return photobooth.update_from_api_data(updated)24def upload_portrait(portrait):25 """ Upload a portrait to Figure API or save it to local file system if an error occurs"""26 files = {27 'picture_color': (portrait['filename'], portrait['picture']),28 'ticket': (portrait['filename'], portrait['ticket'])29 }30 data = {key: portrait[key] for key in ['code', 'taken', 'place', 'event', 'photobooth']}31 try:32 logger.info('Uploading portrait %s' % portrait['code'])33 figure.Portrait.create(data=data, files=files)34 logger.info('Portrait %s uploaded !' % portrait['code'])35 except Exception as e:36 logger.error(e)37 # Couldn't upload the portrait, save picture and ticket38 # to filesystem and add the portrait to local db for scheduled upload...

Full Screen

Full Screen

portrait.py

Source:portrait.py Github

copy

Full Screen

1from cone.app.browser.utils import make_url2from cone.ugm.model.user import User3from cone.ugm.utils import general_settings4from io import BytesIO5from plumber import Behavior6from plumber import default7from plumber import plumb8from pyramid.i18n import TranslationStringFactory9from pyramid.response import Response10from pyramid.view import view_config11from yafowil.base import factory12from yafowil.base import UNSET13_ = TranslationStringFactory('cone.ugm')14@view_config(15 name='portrait_image',16 context=User,17 permission='view_portrait')18def portrait_image(model, request):19 """XXX: needs polishing. Return configured default portrait if not set20 on user.21 """22 response = Response()23 settings = general_settings(model)24 response.body = model.attrs[settings.attrs.users_portrait_attr]25 response.headers['Content-Type'] = 'image/jpeg'26 response.headers['Cache-Control'] = 'max-age=0'27 return response28class PortraitForm(Behavior):29 """Plumbing behavior for setting user portrait image.30 """31 @default32 @property33 def portrait_support(self):34 settings = general_settings(self.model)35 return settings.attrs.users_portrait == 'True'36 @plumb37 def prepare(_next, self):38 """Hook after prepare and set 'portrait' as image widget to39 ``self.form``.40 """41 _next(self)42 if not self.portrait_support:43 return44 model = self.model45 request = self.request46 if request.has_permission('edit_user', model.parent):47 mode = 'edit'48 else:49 mode = 'display'50 settings = general_settings(model)51 image_attr = settings.attrs.users_portrait_attr52 image_accept = settings.attrs.users_portrait_accept53 image_width = int(settings.attrs.users_portrait_width)54 image_height = int(settings.attrs.users_portrait_height)55 image_data = model.attrs.get(image_attr)56 if image_data:57 image_value = {58 'file': BytesIO(image_data),59 'mimetype': 'image/jpeg',60 }61 image_url = make_url(request, node=model,62 resource='portrait_image')63 else:64 image_value = UNSET65 resource = 'cone.ugm.static/images/default_portrait.jpg'66 image_url = make_url(request, node=model.root, resource=resource)67 portrait_widget = factory(68 'field:label:error:image',69 name='portrait',70 value=image_value,71 props={72 'label': _('portrait', default='Portrait'),73 'src': image_url,74 'alt': _('portrait', default='Portrait'),75 'accept': image_accept,76 'minsize': (image_width, image_height),77 'crop': {78 'size': (image_width, image_height),79 'fitting': True,80 }81 },82 mode=mode)83 save_widget = self.form['save']84 self.form.insertbefore(portrait_widget, save_widget)85 @plumb86 def save(_next, self, widget, data):87 if not self.portrait_support or \88 not self.request.has_permission('edit_user', self.model.parent):89 _next(self, widget, data)90 return91 settings = general_settings(self.model)92 image_attr = settings.attrs.users_portrait_attr93 portrait = data.fetch('userform.portrait').extracted94 if portrait:95 if portrait['action'] in ['new', 'replace']:96 cropped = portrait['cropped']97 image_data = BytesIO()98 cropped.save(image_data, 'jpeg', quality=100)99 image_data.seek(0)100 self.model.attrs[image_attr] = image_data.read()101 if portrait['action'] == 'delete':102 del self.model.attrs[image_attr]...

Full Screen

Full Screen

test_browser_portrait.py

Source:test_browser_portrait.py Github

copy

Full Screen

...41 },42 roles={43 'manager': ['manager']44 })45 def test_portrait(self):46 root = get_root()47 users = root['users']48 user = users['user_1']49 # Portrait related config properties50 settings = general_settings(users)51 self.assertEqual(settings.attrs.users_portrait, 'True')52 self.assertEqual(settings.attrs.users_portrait_attr, 'portrait')53 self.assertEqual(settings.attrs.users_portrait_accept, 'image/jpeg')54 self.assertEqual(settings.attrs.users_portrait_width, '50')55 self.assertEqual(settings.attrs.users_portrait_height, '50')56 # Portrait enabled, widget is rendered57 request = self.layer.new_request()58 with self.layer.authenticated('manager'):59 res = render_tile(user, request, 'editform')...

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 robotframework-appiumlibrary 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