How to use add_filter method in autotest

Best Python code snippet using autotest_python

test_solr_query.py

Source:test_solr_query.py Github

copy

Full Screen

...14 self.sq = connections['solr'].get_query()15 def test_build_query_all(self):16 self.assertEqual(self.sq.build_query(), '*:*')17 def test_build_query_single_word(self):18 self.sq.add_filter(SQ(content='hello'))19 self.assertEqual(self.sq.build_query(), '(hello)')20 def test_build_query_boolean(self):21 self.sq.add_filter(SQ(content=True))22 self.assertEqual(self.sq.build_query(), '(true)')23 def test_build_query_datetime(self):24 self.sq.add_filter(SQ(content=datetime.datetime(2009, 5, 8, 11, 28)))25 self.assertEqual(self.sq.build_query(), '(2009-05-08T11:28:00Z)')26 def test_build_query_multiple_words_and(self):27 self.sq.add_filter(SQ(content='hello'))28 self.sq.add_filter(SQ(content='world'))29 self.assertEqual(self.sq.build_query(), '((hello) AND (world))')30 def test_build_query_multiple_words_not(self):31 self.sq.add_filter(~SQ(content='hello'))32 self.sq.add_filter(~SQ(content='world'))33 self.assertEqual(self.sq.build_query(), '(NOT ((hello)) AND NOT ((world)))')34 def test_build_query_multiple_words_or(self):35 self.sq.add_filter(~SQ(content='hello'))36 self.sq.add_filter(SQ(content='hello'), use_or=True)37 self.assertEqual(self.sq.build_query(), '(NOT ((hello)) OR (hello))')38 def test_build_query_multiple_words_mixed(self):39 self.sq.add_filter(SQ(content='why'))40 self.sq.add_filter(SQ(content='hello'), use_or=True)41 self.sq.add_filter(~SQ(content='world'))42 self.assertEqual(self.sq.build_query(), u'(((why) OR (hello)) AND NOT ((world)))')43 def test_build_query_phrase(self):44 self.sq.add_filter(SQ(content='hello world'))45 self.assertEqual(self.sq.build_query(), '(hello AND world)')46 self.sq.add_filter(SQ(content__exact='hello world'))47 self.assertEqual(self.sq.build_query(), u'((hello AND world) AND ("hello world"))')48 def test_build_query_boost(self):49 self.sq.add_filter(SQ(content='hello'))50 self.sq.add_boost('world', 5)51 self.assertEqual(self.sq.build_query(), "(hello) world^5")52 def test_correct_exact(self):53 self.sq.add_filter(SQ(content=Exact('hello world')))54 self.assertEqual(self.sq.build_query(), '("hello world")')55 def test_build_query_multiple_filter_types(self):56 self.sq.add_filter(SQ(content='why'))57 self.sq.add_filter(SQ(pub_date__lte=Exact('2009-02-10 01:59:00')))58 self.sq.add_filter(SQ(author__gt='daniel'))59 self.sq.add_filter(SQ(created__lt=Exact('2009-02-12 12:13:00')))60 self.sq.add_filter(SQ(title__gte='B'))61 self.sq.add_filter(SQ(id__in=[1, 2, 3]))62 self.sq.add_filter(SQ(rating__range=[3, 5]))63 self.assertEqual(self.sq.build_query(), u'((why) AND pub_date:([* TO "2009-02-10 01:59:00"]) AND author:({"daniel" TO *}) AND created:({* TO "2009-02-12 12:13:00"}) AND title:(["B" TO *]) AND id:("1" OR "2" OR "3") AND rating:(["3" TO "5"]))')64 def test_build_complex_altparser_query(self):65 self.sq.add_filter(SQ(content=AltParser('dismax', "Don't panic", qf='text')))66 self.sq.add_filter(SQ(pub_date__lte=Exact('2009-02-10 01:59:00')))67 self.sq.add_filter(SQ(author__gt='daniel'))68 self.sq.add_filter(SQ(created__lt=Exact('2009-02-12 12:13:00')))69 self.sq.add_filter(SQ(title__gte='B'))70 self.sq.add_filter(SQ(id__in=[1, 2, 3]))71 self.sq.add_filter(SQ(rating__range=[3, 5]))72 query = self.sq.build_query()73 self.assertTrue(u'(_query_:"{!dismax qf=text}Don\'t panic")' in query)74 self.assertTrue(u'pub_date:([* TO "2009-02-10 01:59:00"])' in query)75 self.assertTrue(u'author:({"daniel" TO *})' in query)76 self.assertTrue(u'created:({* TO "2009-02-12 12:13:00"})' in query)77 self.assertTrue(u'title:(["B" TO *])' in query)78 self.assertTrue(u'id:("1" OR "2" OR "3")' in query)79 self.assertTrue(u'rating:(["3" TO "5"])' in query)80 def test_build_query_multiple_filter_types_with_datetimes(self):81 self.sq.add_filter(SQ(content='why'))82 self.sq.add_filter(SQ(pub_date__lte=datetime.datetime(2009, 2, 10, 1, 59, 0)))83 self.sq.add_filter(SQ(author__gt='daniel'))84 self.sq.add_filter(SQ(created__lt=datetime.datetime(2009, 2, 12, 12, 13, 0)))85 self.sq.add_filter(SQ(title__gte='B'))86 self.sq.add_filter(SQ(id__in=[1, 2, 3]))87 self.sq.add_filter(SQ(rating__range=[3, 5]))88 self.assertEqual(self.sq.build_query(), u'((why) AND pub_date:([* TO "2009-02-10T01:59:00Z"]) AND author:({"daniel" TO *}) AND created:({* TO "2009-02-12T12:13:00Z"}) AND title:(["B" TO *]) AND id:("1" OR "2" OR "3") AND rating:(["3" TO "5"]))')89 def test_build_query_in_filter_multiple_words(self):90 self.sq.add_filter(SQ(content='why'))91 self.sq.add_filter(SQ(title__in=["A Famous Paper", "An Infamous Article"]))92 self.assertEqual(self.sq.build_query(), u'((why) AND title:("A Famous Paper" OR "An Infamous Article"))')93 def test_build_query_in_filter_datetime(self):94 self.sq.add_filter(SQ(content='why'))95 self.sq.add_filter(SQ(pub_date__in=[datetime.datetime(2009, 7, 6, 1, 56, 21)]))96 self.assertEqual(self.sq.build_query(), u'((why) AND pub_date:("2009-07-06T01:56:21Z"))')97 def test_build_query_in_with_set(self):98 self.sq.add_filter(SQ(content='why'))99 self.sq.add_filter(SQ(title__in=set(["A Famous Paper", "An Infamous Article"])))100 query = self.sq.build_query()101 self.assertTrue(u'(why)' in query)102 # Because ordering in Py3 is now random.103 if 'title:("A ' in query:104 self.assertTrue(u'title:("A Famous Paper" OR "An Infamous Article")' in query)105 else:106 self.assertTrue(u'title:("An Infamous Article" OR "A Famous Paper")' in query)107 def test_build_query_with_contains(self):108 self.sq.add_filter(SQ(content='circular'))109 self.sq.add_filter(SQ(title__contains='haystack'))110 self.assertEqual(self.sq.build_query(), u'((circular) AND title:(*haystack*))')111 def test_build_query_with_endswith(self):112 self.sq.add_filter(SQ(content='circular'))113 self.sq.add_filter(SQ(title__endswith='haystack'))114 self.assertEqual(self.sq.build_query(), u'((circular) AND title:(*haystack))')115 def test_build_query_wildcard_filter_types(self):116 self.sq.add_filter(SQ(content='why'))117 self.sq.add_filter(SQ(title__startswith='haystack'))118 self.assertEqual(self.sq.build_query(), u'((why) AND title:(haystack*))')119 def test_build_query_fuzzy_filter_types(self):120 self.sq.add_filter(SQ(content='why'))121 self.sq.add_filter(SQ(title__fuzzy='haystack'))122 self.assertEqual(self.sq.build_query(), u'((why) AND title:(haystack~))')123 def test_clean(self):124 self.assertEqual(self.sq.clean('hello world'), 'hello world')125 self.assertEqual(self.sq.clean('hello AND world'), 'hello and world')126 self.assertEqual(self.sq.clean('hello AND OR NOT TO + - && || ! ( ) { } [ ] ^ " ~ * ? : \ / world'), 'hello and or not to \\+ \\- \\&& \\|| \\! \\( \\) \\{ \\} \\[ \\] \\^ \\" \\~ \\* \\? \\: \\\\ \\/ world')127 self.assertEqual(self.sq.clean('so please NOTe i am in a bAND and bORed'), 'so please NOTe i am in a bAND and bORed')128 def test_build_query_with_models(self):129 self.sq.add_filter(SQ(content='hello'))130 self.sq.add_model(MockModel)131 self.assertEqual(self.sq.build_query(), '(hello)')132 self.sq.add_model(AnotherMockModel)133 self.assertEqual(self.sq.build_query(), u'(hello)')134 def test_set_result_class(self):135 # Assert that we're defaulting to ``SearchResult``.136 self.assertTrue(issubclass(self.sq.result_class, SearchResult))137 # Custom class.138 class IttyBittyResult(object):139 pass140 self.sq.set_result_class(IttyBittyResult)141 self.assertTrue(issubclass(self.sq.result_class, IttyBittyResult))142 # Reset to default.143 self.sq.set_result_class(None)144 self.assertTrue(issubclass(self.sq.result_class, SearchResult))145 def test_in_filter_values_list(self):146 self.sq.add_filter(SQ(content='why'))147 self.sq.add_filter(SQ(title__in=MockModel.objects.values_list('id', flat=True)))148 self.assertEqual(self.sq.build_query(), u'((why) AND title:("1" OR "2" OR "3"))')149 def test_narrow_sq(self):150 sqs = SearchQuerySet(using='solr').narrow(SQ(foo='moof'))151 self.assertTrue(isinstance(sqs, SearchQuerySet))152 self.assertEqual(len(sqs.query.narrow_queries), 1)153 self.assertEqual(sqs.query.narrow_queries.pop(), 'foo:(moof)')154 def test_query__in(self):155 sqs = SearchQuerySet(using='solr').filter(id__in=[1,2,3])156 self.assertEqual(sqs.query.build_query(), u'id:("1" OR "2" OR "3")')157 def test_query__in_empty_list(self):158 """Confirm that an empty list avoids a Solr exception"""159 sqs = SearchQuerySet(using='solr').filter(id__in=[])...

Full Screen

Full Screen

test_whoosh_query.py

Source:test_whoosh_query.py Github

copy

Full Screen

...13 self.sq = connections['whoosh'].get_query()14 def test_build_query_all(self):15 self.assertEqual(self.sq.build_query(), '*')16 def test_build_query_single_word(self):17 self.sq.add_filter(SQ(content='hello'))18 self.assertEqual(self.sq.build_query(), '(hello)')19 def test_build_query_multiple_words_and(self):20 self.sq.add_filter(SQ(content='hello'))21 self.sq.add_filter(SQ(content='world'))22 self.assertEqual(self.sq.build_query(), u'((hello) AND (world))')23 def test_build_query_multiple_words_not(self):24 self.sq.add_filter(~SQ(content='hello'))25 self.sq.add_filter(~SQ(content='world'))26 self.assertEqual(self.sq.build_query(), u'(NOT ((hello)) AND NOT ((world)))')27 def test_build_query_multiple_words_or(self):28 self.sq.add_filter(SQ(content='hello') | SQ(content='world'))29 self.assertEqual(self.sq.build_query(), u'((hello) OR (world))')30 def test_build_query_multiple_words_mixed(self):31 self.sq.add_filter(SQ(content='why') | SQ(content='hello'))32 self.sq.add_filter(~SQ(content='world'))33 self.assertEqual(self.sq.build_query(), u'(((why) OR (hello)) AND NOT ((world)))')34 def test_build_query_phrase(self):35 self.sq.add_filter(SQ(content='hello world'))36 self.assertEqual(self.sq.build_query(), u'(hello AND world)')37 self.sq.add_filter(SQ(content__exact='hello world'))38 self.assertEqual(self.sq.build_query(), u'((hello AND world) AND ("hello world"))')39 def test_build_query_boost(self):40 self.sq.add_filter(SQ(content='hello'))41 self.sq.add_boost('world', 5)42 self.assertEqual(self.sq.build_query(), "(hello) world^5")43 def test_correct_exact(self):44 self.sq.add_filter(SQ(content=Exact('hello world')))45 self.assertEqual(self.sq.build_query(), '("hello world")')46 def test_build_query_multiple_filter_types(self):47 self.sq.add_filter(SQ(content='why'))48 self.sq.add_filter(SQ(pub_date__lte=datetime.datetime(2009, 2, 10, 1, 59)))49 self.sq.add_filter(SQ(author__gt='daniel'))50 self.sq.add_filter(SQ(created__lt=datetime.datetime(2009, 2, 12, 12, 13)))51 self.sq.add_filter(SQ(title__gte='B'))52 self.sq.add_filter(SQ(id__in=[1, 2, 3]))53 self.sq.add_filter(SQ(rating__range=[3, 5]))54 self.assertEqual(self.sq.build_query(), u'((why) AND pub_date:([to 20090210015900]) AND author:({daniel to}) AND created:({to 20090212121300}) AND title:([B to]) AND id:(1 OR 2 OR 3) AND rating:([3 to 5]))')55 def test_build_query_in_filter_multiple_words(self):56 self.sq.add_filter(SQ(content='why'))57 self.sq.add_filter(SQ(title__in=["A Famous Paper", "An Infamous Article"]))58 self.assertEqual(self.sq.build_query(), u'((why) AND title:("A Famous Paper" OR "An Infamous Article"))')59 def test_build_query_in_filter_datetime(self):60 self.sq.add_filter(SQ(content='why'))61 self.sq.add_filter(SQ(pub_date__in=[datetime.datetime(2009, 7, 6, 1, 56, 21)]))62 self.assertEqual(self.sq.build_query(), u'((why) AND pub_date:(20090706015621))')63 def test_build_query_in_with_set(self):64 self.sq.add_filter(SQ(content='why'))65 self.sq.add_filter(SQ(title__in=set(["A Famous Paper", "An Infamous Article"])))66 query = self.sq.build_query()67 self.assertTrue(u'(why)' in query)68 # Because ordering in Py3 is now random.69 if 'title:("A ' in query:70 self.assertTrue(u'title:("A Famous Paper" OR "An Infamous Article")' in query)71 else:72 self.assertTrue(u'title:("An Infamous Article" OR "A Famous Paper")' in query)73 def test_build_query_wildcard_filter_types(self):74 self.sq.add_filter(SQ(content='why'))75 self.sq.add_filter(SQ(title__startswith='haystack'))76 self.assertEqual(self.sq.build_query(), u'((why) AND title:(haystack*))')77 def test_build_query_fuzzy_filter_types(self):78 self.sq.add_filter(SQ(content='why'))79 self.sq.add_filter(SQ(title__fuzzy='haystack'))80 self.assertEqual(self.sq.build_query(), u'((why) AND title:(haystack~))')81 def test_build_query_with_contains(self):82 self.sq.add_filter(SQ(content='circular'))83 self.sq.add_filter(SQ(title__contains='haystack'))84 self.assertEqual(self.sq.build_query(), u'((circular) AND title:(*haystack*))')85 def test_build_query_with_endswith(self):86 self.sq.add_filter(SQ(content='circular'))87 self.sq.add_filter(SQ(title__endswith='haystack'))88 self.assertEqual(self.sq.build_query(), u'((circular) AND title:(*haystack))')89 def test_clean(self):90 self.assertEqual(self.sq.clean('hello world'), 'hello world')91 self.assertEqual(self.sq.clean('hello AND world'), 'hello and world')92 self.assertEqual(self.sq.clean('hello AND OR NOT TO + - && || ! ( ) { } [ ] ^ " ~ * ? : \ world'), 'hello and or not to \'+\' \'-\' \'&&\' \'||\' \'!\' \'(\' \')\' \'{\' \'}\' \'[\' \']\' \'^\' \'"\' \'~\' \'*\' \'?\' \':\' \'\\\' world')93 self.assertEqual(self.sq.clean('so please NOTe i am in a bAND and bORed'), 'so please NOTe i am in a bAND and bORed')94 def test_build_query_with_models(self):95 self.sq.add_filter(SQ(content='hello'))96 self.sq.add_model(MockModel)97 self.assertEqual(self.sq.build_query(), '(hello)')98 self.sq.add_model(AnotherMockModel)99 self.assertEqual(self.sq.build_query(), u'(hello)')100 def test_build_query_with_datetime(self):101 self.sq.add_filter(SQ(pub_date=datetime.datetime(2009, 5, 9, 16, 20)))102 self.assertEqual(self.sq.build_query(), u'pub_date:(20090509162000)')103 def test_build_query_with_sequence_and_filter_not_in(self):104 self.sq.add_filter(SQ(id=[1, 2, 3]))105 self.assertEqual(self.sq.build_query(), u'id:(1,2,3)')106 def test_set_result_class(self):107 # Assert that we're defaulting to ``SearchResult``.108 self.assertTrue(issubclass(self.sq.result_class, SearchResult))109 # Custom class.110 class IttyBittyResult(object):111 pass112 self.sq.set_result_class(IttyBittyResult)113 self.assertTrue(issubclass(self.sq.result_class, IttyBittyResult))114 # Reset to default.115 self.sq.set_result_class(None)116 self.assertTrue(issubclass(self.sq.result_class, SearchResult))117 def test_in_filter_values_list(self):118 self.sq.add_filter(SQ(content='why'))119 self.sq.add_filter(SQ(title__in=MockModel.objects.values_list('id', flat=True)))120 self.assertEqual(self.sq.build_query(), u'((why) AND title:(1 OR 2 OR 3))')121 def test_narrow_sq(self):122 sqs = SearchQuerySet(using='whoosh').narrow(SQ(foo='moof'))123 self.assertTrue(isinstance(sqs, SearchQuerySet))124 self.assertEqual(len(sqs.query.narrow_queries), 1)...

Full Screen

Full Screen

filters_mixin.py

Source:filters_mixin.py Github

copy

Full Screen

...8 def add_filters(self, dialog):9 filter_text = Gtk.FileFilter()10 filter_text.set_name("Text files")11 filter_text.add_mime_type("text/plain")12 dialog.add_filter(filter_text)13 14 filter_any = Gtk.FileFilter()15 filter_any.set_name("Any files")16 filter_any.add_pattern("*")17 dialog.add_filter(filter_any)18 19 filter_py = Gtk.FileFilter()20 filter_py.set_name("Python files")21 filter_py.add_mime_type("text/x-python")22 dialog.add_filter(filter_py)23 24 filter_perl = Gtk.FileFilter()25 filter_perl.set_name("Perl files")26 filter_perl.add_mime_type("application/x-perl")27 dialog.add_filter(filter_perl)28 29 filter_c = Gtk.FileFilter()30 filter_c.set_name("C/C++ files")31 filter_c.add_mime_type("text/x-c")32 dialog.add_filter(filter_c)33 34 filter_makefile = Gtk.FileFilter()35 filter_makefile.set_name("Makefile files")36 filter_makefile.add_mime_type("text/x-makefile")37 dialog.add_filter(filter_makefile)38 39 filter_js = Gtk.FileFilter()40 filter_js.set_name("Javascript files")41 filter_js.add_mime_type("application/javascript")42 dialog.add_filter(filter_js)43 44 filter_html = Gtk.FileFilter()45 filter_html.set_name("HTML files")46 filter_html.add_mime_type("text/html")47 dialog.add_filter(filter_html)48 49 filter_css = Gtk.FileFilter()50 filter_css.set_name("CSS files")51 filter_css.add_mime_type("text/css")52 dialog.add_filter(filter_css)53 54 filter_json = Gtk.FileFilter()55 filter_json.set_name("JSON files")56 filter_json.add_mime_type("application/json")57 dialog.add_filter(filter_json)58 59 filter_xml = Gtk.FileFilter()60 filter_xml.set_name("XML files")61 filter_xml.add_mime_type("text/xml")62 dialog.add_filter(filter_xml) 63 64 filter_readme = Gtk.FileFilter()65 filter_readme.set_name("README files")66 filter_readme.add_mime_type("text/x-readme")67 dialog.add_filter(filter_readme)68 69 filter_dart = Gtk.FileFilter()70 filter_dart.set_name("Dart files")71 filter_dart.add_mime_type("application/vnd.dart")72 dialog.add_filter(filter_dart)73 74 filter_ruby = Gtk.FileFilter()75 filter_ruby.set_name("Ruby files")76 filter_ruby.add_mime_type("application/x-ruby")77 dialog.add_filter(filter_ruby)78 79 filter_latex = Gtk.FileFilter()80 filter_latex.set_name("Latex files")81 filter_latex.add_mime_type("application/x-latex")82 dialog.add_filter(filter_latex)83 84 filter_bib = Gtk.FileFilter()85 filter_bib.set_name("Bib files")86 filter_bib.add_mime_type("text/x-bibtex")87 dialog.add_filter(filter_bib)88 89 filter_sql = Gtk.FileFilter()90 filter_sql.set_name("SQL files")91 filter_sql.add_mime_type("application/x-sql")92 dialog.add_filter(filter_sql)93 94 filter_appache = Gtk.FileFilter()95 filter_appache.set_name("Appcache files")96 filter_appache.add_mime_type("text/cache-manifest")97 dialog.add_filter(filter_appache)98 filter_log = Gtk.FileFilter()99 filter_log.set_name("Log files")100 filter_log.add_mime_type("text/x-log")101 dialog.add_filter(filter_log)102 103 filter_cal = Gtk.FileFilter()104 filter_cal.set_name("Calendar files")105 filter_cal.add_mime_type("text/calendar")106 dialog.add_filter(filter_cal)107 108 filter_csv = Gtk.FileFilter()109 filter_csv.set_name("CSV files")110 filter_csv.add_mime_type("text/csv")111 filter_csv.add_mime_type("text/x-comma-separated-values")112 dialog.add_filter(filter_csv)113 114 filter_asm = Gtk.FileFilter()115 filter_asm.set_name("Assembly files")116 filter_asm.add_mime_type("text/x-asm")117 dialog.add_filter(filter_asm) 118 119 filter_fortran = Gtk.FileFilter()120 filter_fortran.set_name("Fortran files")121 filter_fortran.add_mime_type("text/x-fortran")122 dialog.add_filter(filter_fortran)123 124 filter_haskell = Gtk.FileFilter()125 filter_haskell.set_name("Haskell files")126 filter_haskell.add_mime_type("text/x-haskell")127 dialog.add_filter(filter_haskell)128 129 filter_java = Gtk.FileFilter()130 filter_java.set_name("Java files")131 filter_java.add_mime_type("text/x-java")132 dialog.add_filter(filter_java)133 134 filter_elisp = Gtk.FileFilter()135 filter_elisp.set_name("Emacs-Lisp files")136 filter_elisp.add_mime_type("text/x-emacs-lisp")137 dialog.add_filter(filter_elisp)138 139 filter_glade = Gtk.FileFilter()140 filter_glade.set_name("Glade files")141 filter_glade.add_mime_type("application/x-glade")142 dialog.add_filter(filter_glade)143 144 145 ...

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