<s> from __future__ import absolute_import , unicode_literals <EOL> from django . core . urlresolvers import reverse <EOL> from django . test import TestCase <EOL> from wagtail . tests . testapp . models import EventIndex , EventPage , SimplePage <EOL> from wagtail . tests . utils import WagtailTestUtils <EOL> from wagtail . wagtailcore . models import Page <EOL> class TestChooserBrowse ( TestCase , WagtailTestUtils ) : <EOL> def setUp ( self ) : <EOL> self . root_page = Page . objects . get ( id = <NUM_LIT:2> ) <EOL> self . child_page = SimplePage ( title = "<STR_LIT>" , content = "<STR_LIT:hello>" ) <EOL> self . root_page . add_child ( instance = self . child_page ) <EOL> self . login ( ) <EOL> def get ( self , params = { } ) : <EOL> return self . client . get ( reverse ( '<STR_LIT>' ) , params ) <EOL> def test_simple ( self ) : <EOL> response = self . get ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> class TestCanChooseRootFlag ( TestCase , WagtailTestUtils ) : <EOL> def setUp ( self ) : <EOL> self . login ( ) <EOL> def get ( self , params = { } ) : <EOL> return self . client . get ( reverse ( '<STR_LIT>' ) , params ) <EOL> def test_cannot_choose_root_by_default ( self ) : <EOL> response = self . get ( ) <EOL> self . assertNotContains ( response , '<STR_LIT>' ) <EOL> def test_can_choose_root ( self ) : <EOL> response = self . get ( { '<STR_LIT>' : '<STR_LIT:true>' } ) <EOL> self . assertContains ( response , '<STR_LIT>' ) <EOL> class TestChooserBrowseChild ( TestCase , WagtailTestUtils ) : <EOL> def setUp ( self ) : <EOL> self . root_page = Page . objects . get ( id = <NUM_LIT:2> ) <EOL> self . child_page = SimplePage ( title = "<STR_LIT>" , content = "<STR_LIT:hello>" ) <EOL> self . root_page . add_child ( instance = self . child_page ) <EOL> self . login ( ) <EOL> def get ( self , params = { } ) : <EOL> return self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = ( self . root_page . id , ) ) , params ) <EOL> def get_invalid ( self , params = { } ) : <EOL> return self . client . get ( reverse ( '<STR_LIT>' , <EOL> args = ( <NUM_LIT> , ) ) , params ) <EOL> def test_simple ( self ) : <EOL> response = self . get ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> def test_get_invalid ( self ) : <EOL> self . assertEqual ( self . get_invalid ( ) . status_code , <NUM_LIT> ) <EOL> def test_with_page_type ( self ) : <EOL> event_page = EventPage ( <EOL> title = "<STR_LIT>" , <EOL> location = '<STR_LIT>' , audience = '<STR_LIT>' , <EOL> cost = '<STR_LIT>' , date_from = '<STR_LIT>' , <EOL> ) <EOL> self . root_page . add_child ( instance = event_page ) <EOL> event_index_page = EventIndex ( <EOL> title = "<STR_LIT>" , <EOL> ) <EOL> self . root_page . add_child ( instance = event_index_page ) <EOL> event_index_page . add_child ( instance = EventPage ( <EOL> title = "<STR_LIT>" , <EOL> location = '<STR_LIT>' , audience = '<STR_LIT>' , <EOL> cost = '<STR_LIT>' , date_from = '<STR_LIT>' , <EOL> ) ) <EOL> response = self . get ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> pages = { <EOL> page . id : page <EOL> for page in response . context [ '<STR_LIT>' ] . object_list <EOL> } <EOL> self . assertIn ( self . child_page . id , pages ) <EOL> self . assertTrue ( pages [ self . child_page . id ] . can_choose ) <EOL> self . assertFalse ( pages [ self . child_page . id ] . can_descend ) <EOL> self . assertNotIn ( event_page . id , pages ) <EOL> self . assertIn ( event_index_page . id , pages ) <EOL> self . assertFalse ( pages [ event_index_page . id ] . can_choose ) <EOL> self . assertTrue ( pages [ event_index_page . id ] . can_descend ) <EOL> def test_with_blank_page_type ( self ) : <EOL> response = self . get ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> def test_with_multiple_page_types ( self ) : <EOL> event_page = EventPage ( <EOL> title = "<STR_LIT>" , <EOL> location = '<STR_LIT>' , audience = '<STR_LIT>' , <EOL> cost = '<STR_LIT>' , date_from = '<STR_LIT>' , <EOL> ) <EOL> self . root_page . add_child ( instance = event_page ) <EOL> response = self . get ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> pages = { <EOL> page . id : page <EOL> for page in response . context [ '<STR_LIT>' ] . object_list <EOL> } <EOL> self . assertIn ( self . child_page . id , pages ) <EOL> self . assertTrue ( pages [ self . child_page . id ] . can_choose ) <EOL> self . assertIn ( event_page . id , pages ) <EOL> self . assertTrue ( pages [ self . child_page . id ] . can_choose ) <EOL> def test_with_unknown_page_type ( self ) : <EOL> response = self . get ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_with_bad_page_type ( self ) : <EOL> response = self . get ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_with_invalid_page_type ( self ) : <EOL> response = self . get ( { '<STR_LIT>' : '<STR_LIT:foo>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def setup_pagination_test_data ( self ) : <EOL> for i in range ( <NUM_LIT:100> ) : <EOL> new_page = SimplePage ( <EOL> title = "<STR_LIT>" , <EOL> slug = "<STR_LIT>" % i , <EOL> content = "<STR_LIT:hello>" , <EOL> ) <EOL> self . root_page . add_child ( instance = new_page ) <EOL> def test_pagination_basic ( self ) : <EOL> self . setup_pagination_test_data ( ) <EOL> response = self . get ( ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] . paginator . num_pages , <NUM_LIT:5> ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] . number , <NUM_LIT:1> ) <EOL> def test_pagination_another_page ( self ) : <EOL> self . setup_pagination_test_data ( ) <EOL> response = self . get ( { '<STR_LIT:p>' : <NUM_LIT:2> } ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] . number , <NUM_LIT:2> ) <EOL> def test_pagination_invalid_page ( self ) : <EOL> self . setup_pagination_test_data ( ) <EOL> response = self . get ( { '<STR_LIT:p>' : '<STR_LIT:foo>' } ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] . number , <NUM_LIT:1> ) <EOL> def test_pagination_out_of_range_page ( self ) : <EOL> self . setup_pagination_test_data ( ) <EOL> response = self . get ( { '<STR_LIT:p>' : <NUM_LIT:100> } ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] . number , <NUM_LIT:5> ) <EOL> class TestChooserSearch ( TestCase , WagtailTestUtils ) : <EOL> def setUp ( self ) : <EOL> self . root_page = Page . objects . get ( id = <NUM_LIT:2> ) <EOL> self . child_page = SimplePage ( title = "<STR_LIT>" , content = "<STR_LIT:hello>" ) <EOL> self . root_page . add_child ( instance = self . child_page ) <EOL> self . login ( ) <EOL> def get ( self , params = None ) : <EOL> return self . client . get ( reverse ( '<STR_LIT>' ) , params or { } ) <EOL> def test_simple ( self ) : <EOL> response = self . get ( { '<STR_LIT:q>' : "<STR_LIT>" } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def test_search_no_results ( self ) : <EOL> response = self . get ( { '<STR_LIT:q>' : "<STR_LIT>" } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def test_with_page_type ( self ) : <EOL> event_page = EventPage ( <EOL> title = "<STR_LIT:foo>" , <EOL> location = '<STR_LIT>' , audience = '<STR_LIT>' , <EOL> cost = '<STR_LIT>' , date_from = '<STR_LIT>' , <EOL> ) <EOL> self . root_page . add_child ( instance = event_page ) <EOL> response = self . get ( { '<STR_LIT:q>' : "<STR_LIT:foo>" , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> pages = { <EOL> page . id : page <EOL> for page in response . context [ '<STR_LIT>' ] <EOL> } <EOL> self . assertIn ( self . child_page . id , pages ) <EOL> self . assertNotIn ( event_page . id , pages ) <EOL> def test_with_blank_page_type ( self ) : <EOL> response = self . get ( { '<STR_LIT:q>' : "<STR_LIT>" , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def test_with_multiple_page_types ( self ) : <EOL> event_page = EventPage ( <EOL> title = "<STR_LIT:foo>" , <EOL> location = '<STR_LIT>' , audience = '<STR_LIT>' , <EOL> cost = '<STR_LIT>' , date_from = '<STR_LIT>' , <EOL> ) <EOL> self . root_page . add_child ( instance = event_page ) <EOL> response = self . get ( { '<STR_LIT:q>' : "<STR_LIT:foo>" , '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> self . assertEqual ( response . context [ '<STR_LIT>' ] , '<STR_LIT>' ) <EOL> pages = { <EOL> page . id : page <EOL> for page in response . context [ '<STR_LIT>' ] <EOL> } <EOL> self . assertIn ( self . child_page . id , pages ) <EOL> self . assertIn ( event_page . id , pages ) <EOL> def test_with_unknown_page_type ( self ) : <EOL> response = self . get ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_with_bad_page_type ( self ) : <EOL> response = self . get ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_with_invalid_page_type ( self ) : <EOL> response = self . get ( { '<STR_LIT>' : '<STR_LIT:foo>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> class TestChooserExternalLink ( TestCase , WagtailTestUtils ) : <EOL> def setUp ( self ) : <EOL> self . login ( ) <EOL> def get ( self , params = { } ) : <EOL> return self . client . get ( reverse ( '<STR_LIT>' ) , params ) <EOL> def post ( self , post_data = { } ) : <EOL> return self . client . post ( reverse ( '<STR_LIT>' ) , post_data ) <EOL> def test_simple ( self ) : <EOL> response = self . get ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> def test_get_with_param ( self ) : <EOL> self . assertEqual ( self . get ( { '<STR_LIT>' : '<STR_LIT:foo>' } ) . status_code , <NUM_LIT:200> ) <EOL> def test_create_link ( self ) : <EOL> response = self . post ( { '<STR_LIT:url>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def test_invalid_url ( self ) : <EOL> response = self . post ( { '<STR_LIT:url>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> def test_allow_local_url ( self ) : <EOL> response = self . post ( { '<STR_LIT:url>' : '<STR_LIT>' } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> self . assertContains ( response , "<STR_LIT>" ) <EOL> class TestChooserEmailLink ( TestCase , WagtailTestUtils ) : <EOL> def setUp ( self ) : <EOL> self . login ( ) <EOL> def get ( self , params = { } ) : <EOL> return self . client . get ( reverse ( '<STR_LIT>' ) , params ) <EOL> def post ( self , post_data = { } ) : <EOL> return self . client . post ( reverse ( '<STR_LIT>' ) , post_data ) <EOL> def test_simple ( self ) : <EOL> response = self . get ( ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> self . assertTemplateUsed ( response , '<STR_LIT>' ) <EOL> def test_get_with_param ( self ) : <EOL> self . assertEqual ( self . get ( { '<STR_LIT>' : '<STR_LIT:foo>' } ) . status_code , <NUM_LIT:200> ) <EOL> def test_create_link ( self ) : <EOL> request = self . post ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertContains ( request , "<STR_LIT>" ) <EOL> self . assertContains ( request , "<STR_LIT>" ) </s>
