How to use _save_changes method in tempest

Best Python code snippet using tempest_python

change_recipe_view.py

Source:change_recipe_view.py Github

copy

Full Screen

1from tkinter import ttk, constants2from services.recipe_service import RecipeService3import tkinter4class ChangeRecipeView:5 """Muutettavan reseptin valinnasta vastaava näkymä"""6 def __init__(self, root, handle_back):7 """Luokan konstruktori. Luo uuden näkymän reseptin muuttamiselle.8 Args:9 root: TKinter-elementti, jonka sisään näkymä alustetaan.10 handle_back: Kutsuttava arvo, jota kutsutaan, kun siirrytään takaisin päänäkymään.11 """12 self._root = root13 self._handle_back = handle_back14 self._frame = None15 self._name = None16 self._name_entry = None17 self._save_changes = None18 self._directions_label = None19 self._directions_text = None20 self._new_url_entry = None21 self._new_name_entry = None22 self._drop_menu = None23 self.recipe_service = RecipeService()24 self._initialize()25 def pack(self):26 """Näyttää näkymän."""27 self._frame.pack(fill=constants.X)28 def destroy(self):29 """Tuhoaa näkymän."""30 self._frame.destroy()31 def _handle_remove(self):32 """Poistaa reseptin."""33 self._remove_comment()34 self.recipe_service.remove_recipe(self._name)35 comment_label = ttk.Label(master=self._frame, text="Recipe removed.")36 comment_label.grid(row=3, column=0, sticky=constants.W, padx=5, pady=5)37 def _handle_change_directions(self):38 """Muuttaa reseptin ohjeen."""39 self._remove_comment()40 recipe_directions = self._directions_text.get("1.0", "end")41 if recipe_directions == "\n":42 comment_label = ttk.Label(master=self._frame, text=f"Directions must at least one character long.")43 comment_label.grid(row=3, sticky=constants.W, padx=5, pady=5)44 else:45 self.recipe_service.change_directions(self._name, recipe_directions)46 comment_label = ttk.Label(master=self._frame, text=f"Directions changed.")47 comment_label.grid(row=3, sticky=constants.W, padx=5, pady=5)48 def _handle_change_url(self):49 """Muuttaa reseptin osoitteen."""50 self._remove_comment()51 new_url = self._new_url_entry.get()52 if new_url == "\n":53 comment_label = ttk.Label(master=self._frame, text=f"URL must at least one character long.")54 comment_label.grid(row=3, sticky=constants.W, padx=5, pady=5)55 else:56 self.recipe_service.change_url(self._name, new_url)57 comment_label = ttk.Label(master=self._frame, text=f"URL changed.")58 comment_label.grid(row=3, sticky=constants.W, padx=5, pady=5)59 def _handle_change_name(self):60 """Muuttaa reseptin nimen."""61 self._remove_comment()62 new_name = self._new_name_entry.get()63 if new_name == "":64 comment_label = ttk.Label(master=self._frame, text=f"Name must at least one character long.")65 comment_label.grid(row=3, sticky=constants.W, padx=5, pady=5)66 else:67 new_recipe_id = self.recipe_service.get_recipe_id(new_name)68 if new_recipe_id is not None:69 comment_label = ttk.Label(master=self._frame, text=f"New name {new_name} exists already.")70 comment_label.grid(row=3, sticky=constants.W, padx=5, pady=5)71 else:72 recipe_id = self.recipe_service.get_recipe_id(self._name)73 self.recipe_service.change_name(recipe_id, new_name)74 comment_label = ttk.Label(master=self._frame, text=f"Name changed.")75 comment_label.grid(row=3, sticky=constants.W, padx=5, pady=5)76 self._name = new_name77 def _remove_comment(self):78 remove_label = ttk.Label(master=self._frame, text="")79 remove_label.grid(row=3, sticky=constants.EW)80 def _destroy_widgets(self):81 if self._new_name_entry is not None:82 self._new_name_entry.destroy()83 if self._drop_menu is not None:84 self._drop_menu.destroy()85 if self._new_url_entry is not None:86 self._new_url_entry.destroy()87 if self._directions_label is not None:88 self._directions_label.destroy()89 if self._directions_text is not None:90 self._directions_text.destroy()91 if self._save_changes is not None:92 self._save_changes.destroy()93 def _show_changes(self, selection):94 self._destroy_widgets()95 self._remove_comment()96 if selection == "Name":97 self._directions_label = ttk.Label(master=self._frame, text=f"New name:")98 self._new_name_entry = ttk.Entry(master=self._frame)99 self._directions_label.grid(row=5, sticky=constants.W, padx=5, pady=5)100 self._new_name_entry.grid(row=6, column=0, sticky=(constants.W, constants.E), padx=5)101 self._save_changes = ttk.Button(102 master=self._frame,103 text="Save changes",104 command=self._handle_change_name105 )106 self._save_changes.grid(row=7, column=0, padx=5, pady=5)107 elif selection == "Directions":108 self._directions_label = ttk.Label(master=self._frame, text=f"Directions:")109 self._directions_label.grid(row=5, sticky=constants.W, padx=5, pady=5)110 recipe_directions = self.recipe_service.get_recipe_directions(self._name)111 self._directions_text = tkinter.Text(master=self._frame)112 text = recipe_directions113 self._directions_text.insert(tkinter.END, text)114 self._directions_text.grid(row=6, column=0, padx=5, pady=5)115 self._save_changes = ttk.Button(116 master=self._frame,117 text="Save changes",118 command=self._handle_change_directions119 )120 self._save_changes.grid(row=7, column=0, padx=5, pady=5)121 elif selection == "URL":122 self._directions_label = ttk.Label(master=self._frame, text=f"New URL:")123 self._new_url_entry = ttk.Entry(master=self._frame)124 self._directions_label.grid(row=5, sticky=constants.W, padx=5, pady=5)125 self._new_url_entry.grid(row=6, column=0, sticky=(constants.W, constants.E), padx=5)126 self._save_changes = ttk.Button(127 master=self._frame,128 text="Save changes",129 command=self._handle_change_url130 )131 self._save_changes.grid(row=7, column=0, padx=5, pady=5)132 else:133 self._save_changes = ttk.Button(134 master=self._frame,135 text="Save changes",136 command=self._handle_remove137 )138 self._save_changes.grid(row=7, column=0, padx=5, pady=5)139 def _print_options(self):140 self._destroy_widgets()141 self._remove_comment()142 self._name = self._name_entry.get()143 if self._name == "":144 comment_label = ttk.Label(master=self._frame, text="Name cannot be empty.")145 comment_label.grid(row=3, sticky=constants.W, padx=5, pady=5)146 else:147 recipe_id = self.recipe_service.get_recipe_id(self._name)148 if recipe_id is not None:149 recipe_url = self.recipe_service.get_url(self._name)150 if recipe_url != "":151 choose_change_box = tkinter.StringVar()152 options = [153 "Name",154 "URL",155 "Remove the recipe"]156 choose_change_box.set("What do you want to change")157 self._drop_menu = tkinter.OptionMenu(self._frame, choose_change_box, *options, command=self._show_changes)158 self._drop_menu.grid(row=4, padx=5, pady=5)159 else:160 choose_change_box = tkinter.StringVar()161 options = [162 "Name",163 "Directions",164 "Remove the recipe"]165 choose_change_box.set("What do you want to change")166 self._drop_menu = tkinter.OptionMenu(self._frame, choose_change_box, *options, command=self._show_changes)167 self._drop_menu.grid(row=4, padx=5, pady=5)168 else:169 comment_label = ttk.Label(master=self._frame, text=f"Cannot find recipe '{self._name}'.")170 comment_label.grid(row=3, sticky=constants.W, padx=5, pady=5) 171 def _initialize(self):172 self._frame = ttk.Frame(master=self._root)173 self._name_entry = ttk.Entry(master=self._root)174 back_button = ttk.Button(175 master=self._frame,176 text="Back",177 command=self._handle_back178 )179 change_label = ttk.Label(master=self._frame, text="Name of the recipe you want to change:")180 self._name_entry = ttk.Entry(master=self._frame)181 search_recipe_button = ttk.Button(182 master=self._frame,183 text="Search",184 command=self._print_options185 )186 back_button.grid(row=0, column=0, padx=5, pady=5)187 change_label.grid(row=1, column=0, padx=5, pady=5)188 self._name_entry.grid(row=2, column=0, sticky=(constants.E, constants.W), padx=5)...

Full Screen

Full Screen

messages_tab.py

Source:messages_tab.py Github

copy

Full Screen

1#!/usr/bin/env python2from webdriver_testing.pages.site_pages.teams import ATeamPage3class MessagesTab(ATeamPage):4 """Actions for the Messages tab of the Team Settings Page.5 """6 _URL = 'teams/%s/settings/messages/' #provide the team slug7 #MESSAGES FIELDS8 _INVITATION_MESSAGE = 'textarea#id_messages_invite'9 _APPLICATION_MESSAGE = 'textarea#id_messages_application'10 _NEW_MANAGER_MESSAGE = 'textarea#id_messages_manager'11 _NEW_ADMIN_MESSAGE = 'textarea#id_messages_admin'12 _NEW_MEMBER_MESSAGE = 'textarea#id_messages_joins'13 _MESSAGES = ['INVITATION', 'APPLICATION', 'NEW_MANAGER', 'NEW_ADMIN', 'NEW_MEMBER'] 14 15 #GUIDELINES FIELDS16 _SUBTITLE_GUIDELINES = 'textarea#id_guidelines_subtitle'17 _TRANSLATE_GUIDELINES = 'textarea#id_guidelines_translate'18 _REVIEW_GUIDELINES = 'textarea#id_guidelines_review'19 _GUIDELINES = ['SUBTITLE', 'TRANSLATE', 'REVIEW']20 _SAVE_CHANGES = 'div.submit input.submit'21 def open_messages_tab(self, team):22 """Open the messages tag for the given team slug.23 """24 self.open_page(self._URL % team)25 self.wait_for_element_present(self._INVITATION_MESSAGE)26 27 def _customize_messages(self, **messages):28 """Enter the message text in the message field.29 """30 for message_field, text in messages.iteritems():31 field = getattr(self, '_'.join(['', message_field, 'MESSAGE']))32 self.logger.info(field)33 self.type_by_css(field, text)34 def _stored_message_text(self):35 """Return the stored text for all message fields'36 """37 current_messages = dict()38 for message_field in self._MESSAGES:39 css_field = getattr(self, 40 '_'.join(['', message_field, 'MESSAGE']))41 displayed_text = self.get_text_by_css(css_field)42 current_messages[message_field] = displayed_text43 return current_messages44 def _stored_guideline_text(self):45 """Return the stored text for all guidelines fields'46 """47 current_guidelines = dict()48 for guideline_field in self._GUIDELINES:49 css_field = getattr(self, 50 '_'.join(['', guideline_field, 'GUIDELINES']))51 self.logger.info(css_field)52 displayed_text = self.get_text_by_css(css_field)53 current_guidelines[guideline_field] = displayed_text54 return current_guidelines55 56 def _customize_guidelines(self, **guidelines):57 """Enter the message text in the message field.58 """59 for guideline_field, text in guidelines.iteritems():60 field = getattr(self, 61 '_'.join(['', guideline_field, 'GUIDELINES']))62 self.type_by_css(field, text)63 def edit_messages(self, messages):64 """Edit the text of the messages fields and save.65 Messages should be a dict of the fields and text.66 """67 self._customize_messages(**messages)68 self.submit_by_css(self._SAVE_CHANGES)69 def edit_guidelines(self, guidelines):70 """Edit the text of the guidelines fields and save.71 Guidelines should be a dict of the fields and text.72 """73 self._customize_guidelines(**guidelines)74 self.click_by_css(self._SAVE_CHANGES)75 def stored_messages(self):76 """Return a dict of the currenlty configured messages.77 """78 messages = self._stored_message_text()79 return messages80 def stored_guidelines(self):81 """Return a dict of the currently configured guidelines.82 """83 guidelines = self._stored_guideline_text()...

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