<s> """<STR_LIT>""" <EOL> from pages . models import Page <EOL> from pages . tests . testcase import TestCase <EOL> from pages import settings <EOL> from django . core . urlresolvers import reverse <EOL> from django . test import LiveServerTestCase <EOL> from django . contrib import auth <EOL> from selenium import webdriver <EOL> from selenium . webdriver . common . by import By <EOL> from selenium . webdriver . support . ui import WebDriverWait <EOL> from selenium . webdriver . support import expected_conditions as EC <EOL> screenshot_nb = <NUM_LIT:1> <EOL> class SeleniumTestCase ( TestCase , LiveServerTestCase ) : <EOL> def setUp ( self ) : <EOL> self . browser = webdriver . PhantomJS ( ) <EOL> client = self . get_admin_client ( ) <EOL> auth . models . User . objects . create_superuser ( <EOL> username = '<STR_LIT>' , <EOL> password = '<STR_LIT>' , <EOL> email = '<STR_LIT>' <EOL> ) <EOL> self . browser . get ( '<STR_LIT>' % ( self . live_server_url , reverse ( "<STR_LIT>" ) ) ) <EOL> super ( SeleniumTestCase , self ) . setUp ( ) <EOL> def screenshot ( self ) : <EOL> global screenshot_nb <EOL> if settings . PAGE_TESTS_SAVE_SCREENSHOTS : <EOL> self . browser . save_screenshot ( '<STR_LIT>' % screenshot_nb ) <EOL> screenshot_nb += <NUM_LIT:1> <EOL> def select_option ( self , select , option_id ) : <EOL> for option in select . find_elements_by_tag_name ( '<STR_LIT>' ) : <EOL> if option . get_attribute ( '<STR_LIT:value>' ) == str ( option_id ) : <EOL> option . click ( ) <EOL> def visit ( self , url ) : <EOL> url = '<STR_LIT>' % ( self . live_server_url , url ) <EOL> self . browser . get ( url ) <EOL> def click ( self , selector ) : <EOL> return self . browser . find_element_by_css_selector ( selector ) . click ( ) <EOL> def wait ( self , id ) : <EOL> return WebDriverWait ( self . browser , <NUM_LIT:3> ) . until ( <EOL> EC . presence_of_element_located ( ( By . ID , id ) ) ) <EOL> def login ( self ) : <EOL> self . visit ( reverse ( "<STR_LIT>" ) ) <EOL> username = self . browser . find_element_by_id ( "<STR_LIT>" ) <EOL> username . send_keys ( "<STR_LIT>" ) <EOL> password = self . browser . find_element_by_id ( "<STR_LIT>" ) <EOL> password . send_keys ( "<STR_LIT>" ) <EOL> self . click ( "<STR_LIT>" ) <EOL> def tearDown ( self ) : <EOL> self . browser . quit ( ) <EOL> super ( SeleniumTestCase , self ) . tearDown ( ) <EOL> def url_change ( self , id ) : <EOL> return reverse ( '<STR_LIT>' , args = [ id ] ) <EOL> def test_admin_select ( self ) : <EOL> self . login ( ) <EOL> page = self . new_page ( ) <EOL> self . visit ( self . url_change ( page . id ) ) <EOL> status = self . browser . find_element_by_id ( '<STR_LIT>' ) <EOL> self . assertEqual ( status . get_attribute ( '<STR_LIT:value>' ) , str ( page . status ) ) <EOL> self . select_option ( status , str ( Page . DRAFT ) ) <EOL> self . assertEqual ( status . get_attribute ( '<STR_LIT:value>' ) , str ( Page . DRAFT ) ) <EOL> src = self . browser . find_element_by_css_selector ( '<STR_LIT>' <EOL> ) . find_element_by_tag_name ( '<STR_LIT>' <EOL> ) . get_attribute ( '<STR_LIT:src>' ) <EOL> self . assertTrue ( src . endswith ( '<STR_LIT>' ) ) <EOL> def test_admin_move_page ( self ) : <EOL> self . login ( ) <EOL> page_1 = self . new_page ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> page_2 = self . new_page ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . visit ( reverse ( '<STR_LIT>' ) ) <EOL> h1 = self . browser . find_element_by_css_selector ( '<STR_LIT>' ) <EOL> self . assertEqual ( h1 . text , '<STR_LIT>' ) <EOL> rows = self . browser . find_elements_by_css_selector ( '<STR_LIT>' ) <EOL> row_1 = rows [ <NUM_LIT:0> ] <EOL> row_2 = rows [ <NUM_LIT:1> ] <EOL> self . assertEqual ( row_1 . get_attribute ( '<STR_LIT:id>' ) , '<STR_LIT>' % page_1 . id ) <EOL> self . assertEqual ( row_2 . get_attribute ( '<STR_LIT:id>' ) , '<STR_LIT>' % page_2 . id ) <EOL> page_3 = self . new_page ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . click ( '<STR_LIT>' % page_2 . id ) <EOL> self . click ( '<STR_LIT>' % page_1 . id ) <EOL> self . wait ( '<STR_LIT>' % page_3 . id ) <EOL> rows = self . browser . find_elements_by_css_selector ( '<STR_LIT>' ) <EOL> row_1 = rows [ <NUM_LIT:0> ] <EOL> row_2 = rows [ <NUM_LIT:1> ] <EOL> row_3 = rows [ <NUM_LIT:2> ] <EOL> self . screenshot ( ) <EOL> self . assertEqual ( row_1 . get_attribute ( '<STR_LIT:id>' ) , '<STR_LIT>' % page_2 . id ) <EOL> self . assertEqual ( row_2 . get_attribute ( '<STR_LIT:id>' ) , '<STR_LIT>' % page_1 . id ) <EOL> self . assertEqual ( row_3 . get_attribute ( '<STR_LIT:id>' ) , '<STR_LIT>' % page_3 . id ) </s>
