Best Python code snippet using autotest_python
models.py
Source:models.py  
...233                               second_join_condition,234                               'LEFT JOIN',235                               alias=second_join_alias)236        return query_set.filter(filter_object)237    def _add_attribute_join(self, query_set, join_condition='', suffix=None,238                            exclude=False):239        join_condition = self.escape_user_sql(join_condition)240        if suffix is None:241            suffix = self._get_include_exclude_suffix(exclude)242        return self.add_join(query_set, 'test_attributes',243                              join_key='test_idx',244                              join_condition=join_condition,245                              suffix=suffix, exclude=exclude)246    def _get_label_ids_from_names(self, label_names):247        if not label_names:248            return []249        query = TestLabel.objects.filter(name__in=label_names).values('id')250        return [str(label['id']) for label in query]251    def get_query_set_with_joins(self, filter_data, include_host_labels=False):252        include_labels = filter_data.pop('include_labels', [])253        exclude_labels = filter_data.pop('exclude_labels', [])254        query_set = self.get_query_set()255        joined = False256        # TODO: make this check more thorough if necessary257        extra_where = filter_data.get('extra_where', '')258        if 'test_labels' in extra_where:259            query_set = self._add_label_joins(query_set)260            joined = True261        include_label_ids = self._get_label_ids_from_names(include_labels)262        if include_label_ids:263            # TODO: Factor this out like what's done with attributes264            condition = ('test_labels_tests_include.testlabel_id IN (%s)' %265                         ','.join(include_label_ids))266            query_set = self.add_join(query_set, 'test_labels_tests',267                                       join_key='test_id',268                                       suffix='_include',269                                       join_condition=condition)270            joined = True271        exclude_label_ids = self._get_label_ids_from_names(exclude_labels)272        if exclude_label_ids:273            condition = ('test_labels_tests_exclude.testlabel_id IN (%s)' %274                         ','.join(exclude_label_ids))275            query_set = self.add_join(query_set, 'test_labels_tests',276                                       join_key='test_id',277                                       suffix='_exclude',278                                       join_condition=condition,279                                       exclude=True)280            joined = True281        include_attributes_where = filter_data.pop('include_attributes_where',282                                                   '')283        exclude_attributes_where = filter_data.pop('exclude_attributes_where',284                                                   '')285        if include_attributes_where:286            query_set = self._add_attribute_join(287                query_set, join_condition=include_attributes_where)288            joined = True289        if exclude_attributes_where:290            query_set = self._add_attribute_join(291                query_set, join_condition=exclude_attributes_where,292                exclude=True)293            joined = True294        if not joined:295            filter_data['no_distinct'] = True296        if include_host_labels or 'test_attributes_host_labels' in extra_where:297            query_set = self._add_attribute_join(298                query_set, suffix='_host_labels',299                join_condition='test_attributes_host_labels.attribute = '300                               '"host-labels"')301        return query_set302    def query_test_ids(self, filter_data):303        dicts = self.model.query_objects(filter_data).values('test_idx')304        return [item['test_idx'] for item in dicts]305    def query_test_label_ids(self, filter_data):306        query_set = self.model.query_objects(filter_data)307        query_set = self._add_label_joins(query_set, suffix='_list')308        rows = self._custom_select_query(query_set, ['test_labels_list.id'])309        return [row[0] for row in rows if row[0] is not None]310    def escape_user_sql(self, sql):311        sql = super(TestViewManager, self).escape_user_sql(sql)...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!!
