<s> from __future__ import unicode_literals , absolute_import <EOL> import os <EOL> import time <EOL> import pytest <EOL> import tempfile <EOL> from PIL import Image <EOL> from splinter . element_list import ElementList <EOL> from selenium . webdriver . common . keys import Keys <EOL> from django . db . models import get_model <EOL> from fancypages . test . fixtures import admin_user <EOL> from fancypages . test import TEMP_MEDIA_ROOT , factories <EOL> from fancypages . test . testcases import SplinterTestCase <EOL> TextBlock = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ImageAsset = get_model ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> class TestTheEditorPanel ( SplinterTestCase ) : <EOL> is_staff = True <EOL> is_logged_in = True <EOL> home_page_url = '<STR_LIT:/>' <EOL> def test_can_be_opened_by_clicking_the_handle ( self ) : <EOL> self . goto ( self . home_page_url ) <EOL> body_tag = self . browser . find_by_css ( '<STR_LIT:body>' ) . first <EOL> self . assertTrue ( body_tag . has_class ( '<STR_LIT>' ) ) <EOL> self . find_and_click_by_css ( self . browser , '<STR_LIT>' ) <EOL> self . assertFalse ( body_tag . has_class ( '<STR_LIT>' ) ) <EOL> try : <EOL> value = self . browser . driver . get_cookie ( '<STR_LIT>' ) [ '<STR_LIT:value>' ] <EOL> except ( KeyError , TypeError ) : <EOL> self . fail ( "<STR_LIT>" ) <EOL> self . assertEqual ( value , '<STR_LIT:true>' ) <EOL> def test_can_be_closed_by_clicking_the_x ( self ) : <EOL> self . assertEqual ( <EOL> self . browser . driver . get_cookie ( '<STR_LIT>' ) , None ) <EOL> self . goto ( self . home_page_url ) <EOL> self . find_and_click_by_css ( self . browser , '<STR_LIT>' ) <EOL> body_tag = self . browser . find_by_css ( '<STR_LIT:body>' ) . first <EOL> self . assertFalse ( body_tag . has_class ( '<STR_LIT>' ) ) <EOL> self . find_and_click_by_css ( self . browser , '<STR_LIT>' ) <EOL> body_tag = self . browser . find_by_css ( '<STR_LIT:body>' ) . first <EOL> self . assertTrue ( body_tag . has_class ( '<STR_LIT>' ) ) <EOL> try : <EOL> value = self . browser . driver . get_cookie ( '<STR_LIT>' ) [ '<STR_LIT:value>' ] <EOL> except ( KeyError , TypeError ) : <EOL> self . fail ( "<STR_LIT>" ) <EOL> self . assertEqual ( value , u'<STR_LIT:false>' ) <EOL> def test_remains_opened_when_reloading_the_page ( self ) : <EOL> self . goto ( self . home_page_url ) <EOL> self . find_and_click_by_css ( self . browser , '<STR_LIT>' ) <EOL> body_tag = self . browser . find_by_css ( '<STR_LIT:body>' ) . first <EOL> self . assertFalse ( body_tag . has_class ( '<STR_LIT>' ) ) <EOL> self . goto ( self . home_page_url ) <EOL> body_tag = self . browser . find_by_css ( '<STR_LIT:body>' ) . first <EOL> self . assertFalse ( body_tag . has_class ( '<STR_LIT>' ) ) <EOL> class TestTabBlock ( SplinterTestCase ) : <EOL> is_staff = True <EOL> is_logged_in = True <EOL> home_page_url = '<STR_LIT:/>' <EOL> def setUp ( self ) : <EOL> super ( TestTabBlock , self ) . setUp ( ) <EOL> self . page = factories . FancyPageFactory ( ) <EOL> def test_tabs_can_be_added_and_removed ( self ) : <EOL> self . block = factories . TabBlockFactory ( <EOL> container = self . page . containers . all ( ) [ <NUM_LIT:0> ] ) <EOL> self . goto ( self . page . get_absolute_url ( ) ) <EOL> self . find_and_click_by_css ( self . browser , '<STR_LIT>' ) <EOL> self . assertEqual ( len ( self . browser . find_by_css ( '<STR_LIT>' ) ) , <NUM_LIT:1> ) <EOL> self . find_and_click_by_css ( self . browser , '<STR_LIT>' ) <EOL> self . wait_for_editor_reload ( ) <EOL> self . assertEqual ( len ( self . browser . find_by_css ( '<STR_LIT>' ) ) , <NUM_LIT:2> ) <EOL> second_tab = self . browser . find_by_css ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> second_tab_id = second_tab [ '<STR_LIT>' ] <EOL> second_tab . click ( ) <EOL> self . wait_for_editor_reload ( ) <EOL> self . assertEqual ( len ( self . browser . find_by_css ( '<STR_LIT>' ) ) , <NUM_LIT:1> ) <EOL> tab_removed = self . browser . is_element_not_present_by_css ( <EOL> "<STR_LIT>" . format ( second_tab_id ) ) <EOL> if not tab_removed : <EOL> self . fail ( "<STR_LIT>" ) <EOL> def ensure_element ( element_or_list , index = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( element_or_list , ElementList ) : <EOL> return element_or_list [ index ] <EOL> return element_or_list <EOL> def find_and_click_by_css ( browser , selector , wait_time = <NUM_LIT:3> ) : <EOL> browser . is_element_present_by_css ( selector , wait_time ) <EOL> elem = ensure_element ( browser . find_by_css ( selector ) ) <EOL> return elem . click ( ) <EOL> def open_editor_panel ( browser ) : <EOL> find_and_click_by_css ( browser , '<STR_LIT>' ) <EOL> if not browser . is_element_present_by_css ( '<STR_LIT>' , <NUM_LIT:2> ) : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> def wait_for_editor_reload ( wait_for = <NUM_LIT:3> ) : <EOL> time . sleep ( wait_for ) <EOL> @ pytest . mark . browser <EOL> def test_text_block_can_be_added_to_a_container ( admin_user , browser , <EOL> live_server ) : <EOL> fancypage = factories . FancyPageFactory ( ) <EOL> title = "<STR_LIT>" <EOL> text = "<STR_LIT>" <EOL> factories . TitleTextBlockFactory ( <EOL> container = fancypage . containers . all ( ) [ <NUM_LIT:0> ] , title = title , text = text ) <EOL> browser . visit ( live_server . url + fancypage . get_absolute_url ( ) ) <EOL> browser . is_text_present ( title ) <EOL> browser . is_text_present ( text ) <EOL> open_editor_panel ( browser ) <EOL> find_and_click_by_css ( browser , '<STR_LIT>' ) <EOL> wait_for_editor_reload ( ) <EOL> title_update = "<STR_LIT>" <EOL> browser . find_by_css ( '<STR_LIT>' ) . type ( title_update ) <EOL> browser . is_text_present ( title + title_update ) <EOL> browser . is_text_present ( text ) <EOL> text_update = "<STR_LIT>" <EOL> rte = browser . find_by_css ( '<STR_LIT>' ) <EOL> rte . type ( text_update ) <EOL> browser . is_text_present ( text + text_update ) <EOL> browser . is_text_present ( title + title_update ) <EOL> @ pytest . mark . browser <EOL> def test_text_block_can_be_deleted_from_a_container ( admin_user , browser , <EOL> live_server ) : <EOL> fancypage = factories . FancyPageFactory ( ) <EOL> title = "<STR_LIT>" <EOL> text = "<STR_LIT>" <EOL> factories . TitleTextBlockFactory ( <EOL> container = fancypage . containers . all ( ) [ <NUM_LIT:0> ] , title = title , text = text ) <EOL> browser . visit ( live_server . url + fancypage . get_absolute_url ( ) ) <EOL> browser . is_text_present ( title ) <EOL> browser . is_text_present ( text ) <EOL> open_editor_panel ( browser ) <EOL> find_and_click_by_css ( browser , '<STR_LIT>' ) <EOL> wait_for_editor_reload ( ) <EOL> assert factories . TitleTextBlockFactory . _meta . model . objects . count ( ) == <NUM_LIT:0> <EOL> @ pytest . mark . browser <EOL> def test_text_block_can_be_added_to_container ( admin_user , browser , <EOL> live_server ) : <EOL> fancypage = factories . FancyPageFactory ( ) <EOL> browser . visit ( live_server . url + fancypage . get_absolute_url ( ) ) <EOL> find_and_click_by_css ( browser , '<STR_LIT>' ) <EOL> find_and_click_by_css ( browser , "<STR_LIT>" ) <EOL> wait_for_editor_reload ( ) <EOL> find_and_click_by_css ( browser , "<STR_LIT>" ) <EOL> find_and_click_by_css ( browser , "<STR_LIT>" ) <EOL> wait_for_editor_reload ( ) <EOL> default_text = '<STR_LIT>' <EOL> if not browser . is_text_present ( default_text , <NUM_LIT:2> ) : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> if not browser . is_element_present_by_css ( '<STR_LIT>' , <NUM_LIT:2> ) : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> find_and_click_by_css ( browser , '<STR_LIT>' ) <EOL> wait_for_editor_reload ( ) <EOL> text_sel = '<STR_LIT>' <EOL> if not browser . is_element_present_by_css ( text_sel , <NUM_LIT:2> ) : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> new_text = "<STR_LIT>" <EOL> rte = browser . find_by_css ( '<STR_LIT>' ) <EOL> rte . type ( Keys . ARROW_RIGHT * ( len ( default_text ) + <NUM_LIT:1> ) ) <EOL> rte . type ( Keys . BACKSPACE * ( len ( default_text ) + <NUM_LIT:1> ) ) <EOL> rte . type ( new_text ) <EOL> find_and_click_by_css ( browser , '<STR_LIT>' ) <EOL> wait_for_editor_reload ( ) <EOL> if not browser . is_text_present ( new_text , <NUM_LIT:2> ) : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> assert TextBlock . objects . count ( ) == <NUM_LIT:1> <EOL> assert TextBlock . objects . all ( ) [ <NUM_LIT:0> ] . text == new_text + '<STR_LIT>' <EOL> @ pytest . mark . browser <EOL> def test_can_be_added_with_new_image_and_link ( admin_user , live_server , <EOL> browser ) : <EOL> fancypage = factories . FancyPageFactory ( ) <EOL> im = Image . new ( "<STR_LIT>" , ( <NUM_LIT> , <NUM_LIT> ) , "<STR_LIT>" ) <EOL> __ , filename = tempfile . mkstemp ( suffix = '<STR_LIT>' , dir = TEMP_MEDIA_ROOT ) <EOL> im . save ( filename , "<STR_LIT>" ) <EOL> image_filename = os . path . basename ( filename ) <EOL> ImageAsset . objects . create ( <EOL> name = '<STR_LIT>' , image = image_filename , creator = admin_user ) <EOL> second_page = factories . FancyPageFactory ( <EOL> node__name = '<STR_LIT>' , node__slug = '<STR_LIT>' ) <EOL> browser . visit ( live_server . url + fancypage . get_absolute_url ( ) ) <EOL> find_and_click_by_css ( browser , '<STR_LIT>' ) <EOL> find_and_click_by_css ( browser , "<STR_LIT>" ) <EOL> find_and_click_by_css ( browser , "<STR_LIT>" ) <EOL> find_and_click_by_css ( browser , "<STR_LIT>" ) <EOL> wait_for_editor_reload ( ) <EOL> default_image_text = '<STR_LIT>' <EOL> if not browser . is_text_present ( default_image_text , <NUM_LIT:2> ) : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> if not browser . is_element_present_by_css ( '<STR_LIT>' , <NUM_LIT:2> ) : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> find_and_click_by_css ( browser , '<STR_LIT>' ) <EOL> wait_for_editor_reload ( ) <EOL> find_and_click_by_css ( browser , '<STR_LIT>' ) <EOL> wait_for_editor_reload ( ) <EOL> with browser . get_iframe ( <NUM_LIT:0> ) as iframe : <EOL> wait_for_editor_reload ( ) <EOL> find_and_click_by_css ( iframe , '<STR_LIT>' ) <EOL> wait_for_editor_reload ( ) <EOL> find_and_click_by_css ( browser , '<STR_LIT>' ) <EOL> find_and_click_by_css ( browser , '<STR_LIT>' . format ( second_page . slug ) ) <EOL> find_and_click_by_css ( browser , '<STR_LIT>' ) <EOL> wait_for_editor_reload ( ) <EOL> shows_image = browser . is_element_present_by_css ( <EOL> "<STR_LIT>" . format ( image_filename ) ) <EOL> if not shows_image : <EOL> raise AssertionError ( '<STR_LIT>' ) <EOL> link_exists = browser . is_element_present_by_css ( <EOL> "<STR_LIT>" . format ( second_page . slug ) ) <EOL> if not link_exists : <EOL> raise AssertionError ( <EOL> '<STR_LIT>' ) </s>
