How to use gather_unique_dicts method in autotest

Best Python code snippet using autotest_python

rpc_utils.py

Source:rpc_utils.py Github

copy

Full Screen

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

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