Best Python code snippet using autotest_python
rpc_utils.py
Source: rpc_utils.py
...13 Prepare Python objects to be returned via RPC.14 """15 if (isinstance(objects, list) and len(objects) and16 isinstance(objects[0], dict) and 'id' in objects[0]):17 objects = gather_unique_dicts(objects)18 return _prepare_data(objects)19def prepare_rows_as_nested_dicts(query, nested_dict_column_names):20 """21 Prepare a Django query to be returned via RPC as a sequence of nested22 dictionaries.23 @param query - A Django model query object with a select_related() method.24 @param nested_dict_column_names - A list of column/attribute names for the25 rows returned by query to expand into nested dictionaries using26 their get_object_dict() method when not None.27 @returns An list suitable to returned in an RPC.28 """29 all_dicts = []30 for row in query.select_related():31 row_dict = row.get_object_dict()32 for column in nested_dict_column_names:33 if row_dict[column] is not None:34 row_dict[column] = getattr(row, column).get_object_dict()35 all_dicts.append(row_dict)36 return prepare_for_serialization(all_dicts)37def _prepare_data(data):38 """39 Recursively process data structures, performing necessary type40 conversions to values in data to allow for RPC serialization:41 -convert datetimes to strings42 -convert tuples and sets to lists43 """44 if isinstance(data, dict):45 new_data = {}46 for key, value in data.iteritems():47 new_data[key] = _prepare_data(value)48 return new_data49 elif (isinstance(data, list) or isinstance(data, tuple) or50 isinstance(data, set)):51 return [_prepare_data(item) for item in data]52 elif isinstance(data, datetime.date):53 if data is NULL_DATETIME or data is NULL_DATE:54 return None55 return str(data)56 else:57 return data58def raw_http_response(response_data, content_type=None):59 response = django.http.HttpResponse(response_data, mimetype=content_type)60 response['Content-length'] = str(len(response.content))61 return response62def gather_unique_dicts(dict_iterable):63 """\64 Pick out unique objects (by ID) from an iterable of object dicts.65 """66 id_set = set()67 result = []68 for obj in dict_iterable:69 if obj['id'] not in id_set:70 id_set.add(obj['id'])71 result.append(obj)72 return result73def extra_job_filters(not_yet_run=False, running=False, finished=False):74 """\75 Generate a SQL WHERE clause for job status filtering, and return it in76 a dict of keyword args to pass to query.extra(). No more than one of...
Check out the latest blogs from LambdaTest on this topic:
Before we discuss Scala testing, let us understand the fundamentals of Scala and how this programming language is a preferred choice for your development requirements.The popularity and usage of Scala are rapidly rising, evident by the ever-increasing open positions for Scala developers.
So, now that the first installment of this two fold article has been published (hence you might have an idea of what Agile Testing is not in my opinion), I’ve started feeling the pressure to explain what Agile Testing actually means to me.
Did you know that according to Statista, the number of smartphone users will reach 18.22 billion by 2025? Let’s face it, digital transformation is skyrocketing and will continue to do so. This swamps the mobile app development market with various options and gives rise to the need for the best mobile app testing tools
As a developer, checking the cross browser compatibility of your CSS properties is of utmost importance when building your website. I have often found myself excited to use a CSS feature only to discover that it’s still not supported on all browsers. Even if it is supported, the feature might be experimental and not work consistently across all browsers. Ask any front-end developer about using a CSS feature whose support is still in the experimental phase in most prominent web browsers. ????
The count of mobile users is on a steep rise. According to the research, by 2025, it is expected to reach 7.49 billion users worldwide. 70% of all US digital media time comes from mobile apps, and to your surprise, the average smartphone owner uses ten apps per day and 30 apps each month.
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!!