<s> import json <EOL> from django . db . models import get_model <EOL> from django . core . urlresolvers import reverse <EOL> from django . utils . translation import get_language <EOL> from fancypages . test import factories <EOL> from fancypages . test import testcases <EOL> from fancypages . utils import get_node_model , get_page_model <EOL> PageType = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> PageNode = get_node_model ( ) <EOL> FancyPage = get_page_model ( ) <EOL> Container = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> TextBlock = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> TabBlock = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ContentBlock = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TestTheBlockTypeApi ( testcases . FancyPagesWebTest ) : <EOL> is_staff = True <EOL> def setUp ( self ) : <EOL> super ( TestTheBlockTypeApi , self ) . setUp ( ) <EOL> self . container = Container . objects . create ( name = "<STR_LIT:test>" ) <EOL> def test_is_not_available_to_anonymous_users ( self ) : <EOL> self . app . get ( reverse ( '<STR_LIT>' ) , status = <NUM_LIT> ) <EOL> def test_returns_a_block_type_form_for_container ( self ) : <EOL> page = self . get ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> params = { '<STR_LIT>' : self . container . uuid } ) <EOL> response = json . loads ( page . content ) <EOL> self . assertIn ( '<STR_LIT>' , response ) <EOL> def test_returns_error_when_no_container_specified ( self ) : <EOL> response = self . get ( reverse ( '<STR_LIT>' ) , status = <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , response . content ) <EOL> def test_returns_error_when_invalid_container_is_specified ( self ) : <EOL> response = self . get ( reverse ( '<STR_LIT>' ) , <EOL> params = { '<STR_LIT>' : <NUM_LIT:200> } , status = <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , response . content ) <EOL> class TestTheBlockApi ( testcases . FancyPagesWebTest ) : <EOL> is_staff = True <EOL> csrf_checks = False <EOL> def setUp ( self ) : <EOL> super ( TestTheBlockApi , self ) . setUp ( ) <EOL> self . prepare_template_file ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> self . page = factories . FancyPageFactory ( <EOL> node__name = "<STR_LIT>" , node__slug = '<STR_LIT>' ) <EOL> self . text_block = TextBlock . objects . create ( <EOL> container = self . page . get_container_from_name ( '<STR_LIT>' ) , <EOL> text = "<STR_LIT>" , <EOL> ) <EOL> self . other_text_block = TextBlock . objects . create ( <EOL> container = self . page . get_container_from_name ( '<STR_LIT>' ) , <EOL> text = "<STR_LIT>" , <EOL> ) <EOL> self . third_text_block = TextBlock . objects . create ( <EOL> container = self . page . get_container_from_name ( '<STR_LIT>' ) , <EOL> text = "<STR_LIT>" , <EOL> ) <EOL> self . assertEquals ( self . text_block . display_order , <NUM_LIT:0> ) <EOL> self . assertEquals ( self . other_text_block . display_order , <NUM_LIT:1> ) <EOL> self . assertEquals ( self . third_text_block . display_order , <NUM_LIT:2> ) <EOL> def test_is_not_available_to_anonymous_users ( self ) : <EOL> response = self . app . get ( reverse ( '<STR_LIT>' ) , status = <NUM_LIT> ) <EOL> self . assertIn ( '<STR_LIT>' , response . content ) <EOL> def test_can_be_added_to_a_container ( self ) : <EOL> container = self . page . get_container_from_name ( '<STR_LIT>' ) <EOL> num_blocks = container . blocks . count ( ) <EOL> response = self . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> params = { '<STR_LIT>' : container . uuid , '<STR_LIT:code>' : self . text_block . code } ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> self . assertEquals ( container . blocks . count ( ) , num_blocks + <NUM_LIT:1> ) <EOL> block_id = json . loads ( response . content ) [ '<STR_LIT:id>' ] <EOL> ContentBlock . objects . get_subclass ( pk = block_id ) <EOL> def test_can_add_a_image_text_block_to_a_container ( self ) : <EOL> container = self . page . get_container_from_name ( '<STR_LIT>' ) <EOL> num_blocks = container . blocks . count ( ) <EOL> response = self . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> params = { '<STR_LIT>' : container . uuid , '<STR_LIT:code>' : '<STR_LIT:image>' } ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> self . assertEquals ( container . blocks . count ( ) , num_blocks + <NUM_LIT:1> ) <EOL> block_id = json . loads ( response . content ) [ '<STR_LIT:id>' ] <EOL> ContentBlock . objects . get_subclass ( pk = block_id ) <EOL> class TestTheBlockMoveApi ( testcases . FancyPagesWebTest ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> is_staff = True <EOL> csrf_checks = False <EOL> def setUp ( self ) : <EOL> super ( TestTheBlockMoveApi , self ) . setUp ( ) <EOL> self . prepare_template_file ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) <EOL> page_type = PageType . objects . create ( <EOL> name = "<STR_LIT>" , <EOL> template_name = self . template_name , <EOL> ) <EOL> self . page = factories . FancyPageFactory ( <EOL> node__name = "<STR_LIT>" , node__slug = '<STR_LIT>' , <EOL> page_type = page_type ) <EOL> self . left_container = self . page . get_container_from_name ( <EOL> '<STR_LIT>' ) <EOL> self . main_container = self . page . get_container_from_name ( <EOL> '<STR_LIT>' ) <EOL> self . left_blocks = [ ] <EOL> self . main_blocks = [ ] <EOL> for idx in range ( <NUM_LIT:0> , <NUM_LIT:3> ) : <EOL> main_block = TextBlock . objects . create ( <EOL> container = self . main_container , <EOL> text = "<STR_LIT>" % idx , <EOL> ) <EOL> self . main_blocks . append ( main_block ) <EOL> self . assertEquals ( main_block . display_order , idx ) <EOL> left_block = TextBlock . objects . create ( <EOL> container = self . left_container , <EOL> text = "<STR_LIT>" . format ( idx ) ) <EOL> self . left_blocks . append ( left_block ) <EOL> self . assertEquals ( left_block . display_order , idx ) <EOL> def test_moves_a_block_up_within_a_container ( self ) : <EOL> for idx , pos in [ ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:1> ) , ( <NUM_LIT:2> , <NUM_LIT:2> ) ] : <EOL> block = TextBlock . objects . get ( id = self . left_blocks [ idx ] . id ) <EOL> self . assertEquals ( block . display_order , pos ) <EOL> self . app . put ( <EOL> reverse ( '<STR_LIT>' , kwargs = { <EOL> '<STR_LIT>' : self . main_blocks [ <NUM_LIT:1> ] . uuid } ) , <EOL> params = { '<STR_LIT>' : self . left_container . uuid , '<STR_LIT:index>' : <NUM_LIT:1> } , <EOL> user = self . user ) <EOL> moved_block = TextBlock . objects . get ( id = self . main_blocks [ <NUM_LIT:1> ] . id ) <EOL> self . assertEquals ( <EOL> moved_block . container , <EOL> self . page . get_container_from_name ( '<STR_LIT>' ) ) <EOL> self . assertEquals ( moved_block . display_order , <NUM_LIT:1> ) <EOL> for idx , pos in [ ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:1> , <NUM_LIT:2> ) , ( <NUM_LIT:2> , <NUM_LIT:3> ) ] : <EOL> block = TextBlock . objects . get ( id = self . left_blocks [ idx ] . id ) <EOL> self . assertEquals ( block . display_order , pos ) <EOL> for idx , pos in [ ( <NUM_LIT:0> , <NUM_LIT:0> ) , ( <NUM_LIT:2> , <NUM_LIT:1> ) ] : <EOL> block = TextBlock . objects . get ( id = self . main_blocks [ idx ] . id ) <EOL> self . assertEquals ( block . display_order , pos ) <EOL> class TestOrderedContainer ( testcases . FancyPagesWebTest ) : <EOL> is_staff = True <EOL> csrf_checks = False <EOL> def test_can_be_created_with_valid_uuid ( self ) : <EOL> self . block = factories . TabBlockFactory ( ) <EOL> params = { <EOL> '<STR_LIT>' : self . block . uuid , <EOL> '<STR_LIT>' : get_language ( ) } <EOL> self . post ( reverse ( '<STR_LIT>' ) , params = params ) <EOL> self . assertEquals ( TabBlock . objects . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( self . block . tabs . count ( ) , <NUM_LIT:2> ) <EOL> def test_cannot_be_created_with_invalid_uuid ( self ) : <EOL> params = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : get_language ( ) } <EOL> response = self . post ( reverse ( '<STR_LIT>' ) , <EOL> params = params , status = <NUM_LIT> ) <EOL> self . assertEquals ( response . status_code , <NUM_LIT> ) <EOL> self . assertEquals ( ContentBlock . objects . count ( ) , <NUM_LIT:0> ) </s>
