How to use _update_fields_from_row method in autotest

Best Python code snippet using autotest_python Github


Full Screen

...133 if differences:134 logging.warning(135 'initialized %s %s instance requery is updating: %s',136 type(self),, differences)137 self._update_fields_from_row(row)138 self._initialized = True139 @classmethod140 def _clear_instance_cache(cls):141 """Used for testing, clear the internal instance cache."""142 cls._instances_by_type_and_id.clear()143 def _fetch_row_from_db(self, row_id):144 fields = ', '.join(self._fields)145 sql = 'SELECT %s FROM %s WHERE ID=%%s' % (fields, self.__table)146 rows = _db.execute(sql, (row_id,))147 if not rows:148 raise DBError("row not found (table=%s, row id=%s)"149 % (self.__table, row_id))150 return rows[0]151 def _assert_row_length(self, row):152 assert len(row) == len(self._fields), (153 "table = %s, row = %s/%d, fields = %s/%d" % (154 self.__table, row, len(row), self._fields, len(self._fields)))155 def _compare_fields_in_row(self, row):156 """157 Given a row as returned by a SELECT query, compare it to our existing in158 memory fields. Fractional seconds are stripped from datetime values159 before comparison.160 @param row - A sequence of values corresponding to fields named in161 The class attribute _fields.162 @returns A dictionary listing the differences keyed by field name163 containing tuples of (current_value, row_value).164 """165 self._assert_row_length(row)166 differences = {}167 for field, row_value in itertools.izip(self._fields, row):168 current_value = getattr(self, field)169 if (isinstance(current_value, datetime.datetime)170 and isinstance(row_value, datetime.datetime)):171 current_value = current_value.strftime(time_utils.TIME_FMT)172 row_value = row_value.strftime(time_utils.TIME_FMT)173 if current_value != row_value:174 differences[field] = (current_value, row_value)175 return differences176 def _update_fields_from_row(self, row):177 """178 Update our field attributes using a single row returned by SELECT.179 @param row - A sequence of values corresponding to fields named in180 the class fields list.181 """182 self._assert_row_length(row)183 self._valid_fields = set()184 for field, value in itertools.izip(self._fields, row):185 setattr(self, field, value)186 self._valid_fields.add(field)187 self._valid_fields.remove('id')188 def update_from_database(self):189 assert is not None190 row = self._fetch_row_from_db( self._update_fields_from_row(row)192 def count(self, where, table = None):193 if not table:194 table = self.__table195 rows = _db.execute("""196 SELECT count(*) FROM %s197 WHERE %s198 """ % (table, where))199 assert len(rows) == 1200 return int(rows[0][0])201 def update_field(self, field, value):202 assert field in self._valid_fields203 if getattr(self, field) == value:204 return205 query = "UPDATE %s SET %s = %%s WHERE id = %%s" % (self.__table, field)...

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:


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?