Best Python code snippet using autotest_python
json_handler.py
Source:json_handler.py
...84 content in json file:85 {"team":{"number":10,"tester":"grady"}}86 '''87 filePath = os.path.join(projectPath, json_file_path)88 def get_updated_content(jsonContent):89 return json_set(jsonContent, jsonPath, new_value)90 write_JsonFile(filePath, get_updated_content)91def jsonFile_delete(jsonFilePath, jsonPath):92 filePath = os.path.join(projectPath, jsonFilePath)93 def get_updated_content(jsonContent):94 return json_delete(jsonContent, jsonPath)95 write_JsonFile(filePath, get_updated_content)96def write_JsonFile(filePath, getUpdateContentFun):97 with open(filePath, "r+") as jsonFile:98 jsonFile = open(filePath, "r+")99 jsonContent = json.load(jsonFile)100 newJsonContent = getUpdateContentFun(jsonContent)101 jsonFile.seek(0)102 jsonFile.write(json.dumps(newJsonContent, indent=4))103 jsonFile.truncate()104 jsonFile.close()105def json_set(jsonContent, jsonPath, newvalue):106 jsonPath_expr = parser(jsonPath)107 jsonPath_expr.update(jsonContent, newvalue)...
widgets.py
Source:widgets.py
...54 from braces.views import AjaxResponseMixin, JSONResponseMixin55 # pylama:ignore=C0111,R020156 class PartialResponse(JSONResponseMixin, AjaxResponseMixin, View):57 def get_data(self):58 return widget.get_updated_content()59 def get(self, request, *args, **kwargs):60 return self.get_ajax(request, *args, **kwargs)61 def get_ajax(self, request, *args, **kwargs):62 return self.render_json_response(self.get_data())63 PartialResponse.url_name = url_name64 PartialResponse.url_regex = url_regex65 PartialResponse.time_interval = time_interval66 REALTIME_WIDGETS.append(PartialResponse)67 if not hasattr(widget, 'url_name'):68 widget.url_name = url_name69 if not hasattr(widget, 'url_regex'):70 widget.url_regex = url_regex71 if not hasattr(widget, 'time_interval'):72 widget.time_interval = time_interval73 return widget74class Widget(object):75 """Widget class."""76 def __init__(self,77 html_id=None,78 name=None,79 content=None,80 template=None,81 classes=None,82 **kwargs):83 """84 Init method.85 Args:86 html_id (str): an ID to set on the HTML item.87 name (str): the name of the item, displayed in HTML.88 content (): suitable content according to chosen display.89 template (str): the template responsible for display.90 classes (str): additional classes to pass to the HTML item.91 """92 if html_id is not None:93 try:94 self.html_id = html_id95 except AttributeError:96 self._html_id = html_id97 if name is not None:98 try:99 self.name = name100 except AttributeError:101 self._name = name102 if content is not None:103 try:104 self.content = content105 except AttributeError:106 self._content = content107 if template is not None:108 try:109 self.template = template110 except AttributeError:111 self._template = template112 if classes is not None:113 try:114 self.classes = classes115 except AttributeError:116 self._classes = classes117 if not hasattr(self, 'template'):118 raise AttributeError('template is a required widget attribute')119 for kw, arg in kwargs.items():120 setattr(self, kw, arg)121 def get_updated_content(self):122 """Return updated content (for real-time widgets)."""...
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!!