<s> from urllib import urlencode <EOL> from hilbert . test import ViewTestMixin <EOL> from mezzanine . core . models import CONTENT_STATUS_PUBLISHED <EOL> from raspberryio . project . tests . base import ProjectBaseTestCase <EOL> class SearchViewTestCase ( ViewTestMixin , ProjectBaseTestCase ) : <EOL> """<STR_LIT>""" <EOL> url_name = '<STR_LIT>' <EOL> def setUp ( self ) : <EOL> super ( SearchViewTestCase , self ) . setUp ( ) <EOL> self . user = self . create_user ( data = { '<STR_LIT:password>' : '<STR_LIT:password>' } ) <EOL> self . project = self . create_project ( title = '<STR_LIT>' , user = self . user , <EOL> status = CONTENT_STATUS_PUBLISHED <EOL> ) <EOL> def get_query_params ( self , query = '<STR_LIT>' , object_type = None ) : <EOL> object_type = object_type or { } <EOL> query_dict = { <EOL> '<STR_LIT:q>' : query , <EOL> } <EOL> query_dict . update ( { <EOL> '<STR_LIT:type>' : object_type <EOL> } ) <EOL> return '<STR_LIT:?>' + urlencode ( query_dict ) <EOL> def test_empty_result ( self ) : <EOL> self . project . delete ( ) <EOL> self . user . delete ( ) <EOL> response = self . client . get ( self . url + self . get_query_params ( '<STR_LIT>' ) ) <EOL> results = response . context [ '<STR_LIT>' ] . object_list <EOL> self . assertEqual ( results , [ ] ) <EOL> def test_one_result ( self ) : <EOL> self . create_project ( <EOL> title = '<STR_LIT>' , user = self . user , status = CONTENT_STATUS_PUBLISHED <EOL> ) <EOL> query = self . get_query_params ( self . project . title ) <EOL> response = self . client . get ( self . url + query ) <EOL> results = response . context [ '<STR_LIT>' ] . object_list <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( results [ <NUM_LIT:0> ] . title , self . project . title ) <EOL> def test_many_results_one_type ( self ) : <EOL> project2 = self . create_project ( <EOL> title = '<STR_LIT>' , user = self . user , status = CONTENT_STATUS_PUBLISHED <EOL> ) <EOL> query = self . get_query_params ( '<STR_LIT>' ) <EOL> response = self . client . get ( self . url + query ) <EOL> results = response . context [ '<STR_LIT>' ] . object_list <EOL> result_titles = [ result . title for result in results ] <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( <EOL> set ( result_titles ) , set ( [ self . project . title , project2 . title ] ) <EOL> ) <EOL> def test_many_results_many_types ( self ) : <EOL> project2 = self . create_project ( <EOL> title = '<STR_LIT>' , user = self . user , status = CONTENT_STATUS_PUBLISHED <EOL> ) <EOL> user2 = self . create_user ( data = { '<STR_LIT:username>' : '<STR_LIT>' } ) <EOL> query = self . get_query_params ( '<STR_LIT>' ) <EOL> response = self . client . get ( self . url + query ) <EOL> results = response . context [ '<STR_LIT>' ] . object_list <EOL> result_urls = [ result . get_absolute_url ( ) for result in results ] <EOL> expected_results = set ( map ( lambda i : i . get_absolute_url ( ) , [ <EOL> self . project , project2 , user2 , <EOL> ] ) ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( set ( result_urls ) , expected_results ) <EOL> def test_query_type_malformed ( self ) : <EOL> project2 = self . create_project ( <EOL> title = '<STR_LIT>' , user = self . user , status = CONTENT_STATUS_PUBLISHED <EOL> ) <EOL> user2 = self . create_user ( data = { '<STR_LIT:username>' : '<STR_LIT>' } ) <EOL> query = self . get_query_params ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> response = self . client . get ( self . url + query ) <EOL> results = response . context [ '<STR_LIT>' ] . object_list <EOL> result_urls = [ result . get_absolute_url ( ) for result in results ] <EOL> expected_results = set ( map ( lambda i : i . get_absolute_url ( ) , [ <EOL> self . project , project2 , user2 <EOL> ] ) ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( set ( result_urls ) , expected_results ) <EOL> def test_query_unregistered_model ( self ) : <EOL> project2 = self . create_project ( <EOL> title = '<STR_LIT>' , user = self . user , status = CONTENT_STATUS_PUBLISHED <EOL> ) <EOL> user2 = self . create_user ( data = { '<STR_LIT:username>' : '<STR_LIT>' } ) <EOL> query = self . get_query_params ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> response = self . client . get ( self . url + query ) <EOL> results = response . context [ '<STR_LIT>' ] . object_list <EOL> result_urls = [ result . get_absolute_url ( ) for result in results ] <EOL> expected_results = set ( map ( lambda i : i . get_absolute_url ( ) , [ <EOL> self . project , project2 , user2 <EOL> ] ) ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:3> ) <EOL> self . assertEqual ( set ( result_urls ) , expected_results ) <EOL> def test_query_on_type ( self ) : <EOL> project2 = self . create_project ( <EOL> title = '<STR_LIT>' , user = self . user , status = CONTENT_STATUS_PUBLISHED <EOL> ) <EOL> self . create_user ( data = { '<STR_LIT:username>' : '<STR_LIT>' } ) <EOL> query = self . get_query_params ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> response = self . client . get ( self . url + query ) <EOL> results = response . context [ '<STR_LIT>' ] . object_list <EOL> result_urls = [ result . get_absolute_url ( ) for result in results ] <EOL> expected_results = set ( map ( lambda i : i . get_absolute_url ( ) , [ <EOL> self . project , project2 <EOL> ] ) ) <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( set ( result_urls ) , expected_results ) <EOL> def test_draft_removed ( self ) : <EOL> self . create_project ( title = '<STR_LIT>' , user = self . user ) <EOL> query = self . get_query_params ( '<STR_LIT>' ) <EOL> response = self . client . get ( self . url + query ) <EOL> results = response . context [ '<STR_LIT>' ] . object_list <EOL> self . assertEqual ( len ( results ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( results [ <NUM_LIT:0> ] . title , self . project . title ) </s>
