<s> from nose . tools import eq_ <EOL> from textwrap import dedent <EOL> from pyquery import PyQuery as pq <EOL> from kitsune . search import es_utils , synonym_utils <EOL> from kitsune . search . tests import ElasticTestCase , SynonymFactory <EOL> from kitsune . sumo . tests import LocalizingClient <EOL> from kitsune . sumo . tests import TestCase <EOL> from kitsune . sumo . urlresolvers import reverse <EOL> from kitsune . wiki . tests import DocumentFactory , RevisionFactory <EOL> from kitsune . search . tasks import update_synonyms_task <EOL> class TestSynonymModel ( TestCase ) : <EOL> def test_serialize ( self ) : <EOL> syn = SynonymFactory ( from_words = "<STR_LIT:foo>" , to_words = "<STR_LIT:bar>" ) <EOL> eq_ ( "<STR_LIT>" , unicode ( syn ) ) <EOL> class TestFilterGenerator ( TestCase ) : <EOL> def test_name ( self ) : <EOL> """<STR_LIT>""" <EOL> name , _ = es_utils . es_get_synonym_filter ( '<STR_LIT>' ) <EOL> eq_ ( name , '<STR_LIT>' ) <EOL> def test_no_synonyms ( self ) : <EOL> """<STR_LIT>""" <EOL> _ , body = es_utils . es_get_synonym_filter ( '<STR_LIT>' ) <EOL> eq_ ( body , { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] , <EOL> } ) <EOL> def test_with_some_synonyms ( self ) : <EOL> SynonymFactory ( from_words = '<STR_LIT:foo>' , to_words = '<STR_LIT:bar>' ) <EOL> SynonymFactory ( from_words = '<STR_LIT>' , to_words = '<STR_LIT>' ) <EOL> _ , body = es_utils . es_get_synonym_filter ( '<STR_LIT>' ) <EOL> expected = { <EOL> '<STR_LIT:type>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] , <EOL> } <EOL> eq_ ( body , expected ) <EOL> class TestSynonymParser ( TestCase ) : <EOL> def testItWorks ( self ) : <EOL> synonym_text = dedent ( """<STR_LIT>""" ) <EOL> synonyms = set ( [ <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ] ) <EOL> eq_ ( synonyms , synonym_utils . parse_synonyms ( synonym_text ) ) <EOL> def testTooManyArrows ( self ) : <EOL> try : <EOL> synonym_utils . parse_synonyms ( '<STR_LIT>' ) <EOL> except synonym_utils . SynonymParseError as e : <EOL> eq_ ( len ( e . errors ) , <NUM_LIT:1> ) <EOL> else : <EOL> assert False , "<STR_LIT>" <EOL> def testTooFewArrows ( self ) : <EOL> try : <EOL> synonym_utils . parse_synonyms ( '<STR_LIT>' ) <EOL> except synonym_utils . SynonymParseError as e : <EOL> eq_ ( len ( e . errors ) , <NUM_LIT:1> ) <EOL> else : <EOL> assert False , "<STR_LIT>" <EOL> class SearchViewWithSynonyms ( ElasticTestCase ) : <EOL> client_class = LocalizingClient <EOL> def test_synonyms_work_in_search_view ( self ) : <EOL> d1 = DocumentFactory ( title = '<STR_LIT>' ) <EOL> d2 = DocumentFactory ( title = '<STR_LIT>' ) <EOL> RevisionFactory ( document = d1 , is_approved = True ) <EOL> RevisionFactory ( document = d2 , is_approved = True ) <EOL> self . refresh ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) , { '<STR_LIT:q>' : '<STR_LIT>' } ) <EOL> doc = pq ( response . content ) <EOL> header = doc . find ( '<STR_LIT>' ) . text ( ) . strip ( ) <EOL> eq_ ( header , '<STR_LIT>' ) <EOL> SynonymFactory ( from_words = '<STR_LIT>' , to_words = '<STR_LIT>' ) <EOL> update_synonyms_task ( ) <EOL> self . refresh ( ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) , { '<STR_LIT:q>' : '<STR_LIT>' } ) <EOL> doc = pq ( response . content ) <EOL> header = doc . find ( '<STR_LIT>' ) . text ( ) . strip ( ) <EOL> eq_ ( header , '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) , { '<STR_LIT:q>' : '<STR_LIT>' } ) <EOL> doc = pq ( response . content ) <EOL> header = doc . find ( '<STR_LIT>' ) . text ( ) . strip ( ) <EOL> eq_ ( header , '<STR_LIT>' ) </s>
