<s> from __future__ import unicode_literals <EOL> import datetime <EOL> from django import test <EOL> from django . contrib . admin . tests import AdminSeleniumWebDriverTestCase <EOL> from django . contrib . auth import get_user_model <EOL> from django . contrib . auth . models import Permission <EOL> from django . core . urlresolvers import reverse <EOL> from django . utils . encoding import force_text <EOL> User = get_user_model ( ) <EOL> class TabularPermissionsLiveTest ( AdminSeleniumWebDriverTestCase ) : <EOL> available_apps = [ '<STR_LIT>' ] + AdminSeleniumWebDriverTestCase . available_apps <EOL> def setUp ( self ) : <EOL> User . objects . create ( pk = <NUM_LIT:1000> , <EOL> username = '<STR_LIT>' , first_name = '<STR_LIT>' , last_name = '<STR_LIT>' , email = '<STR_LIT>' , <EOL> password = '<STR_LIT>' , is_active = True , <EOL> is_superuser = True , <EOL> is_staff = True , last_login = datetime . datetime ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT:10> ) , <EOL> date_joined = datetime . datetime ( <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:30> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT:10> ) <EOL> ) <EOL> def goto_user_change ( self ) : <EOL> self . admin_login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . selenium . get ( '<STR_LIT>' % ( self . live_server_url , <EOL> reverse ( '<STR_LIT>' , args = ( <NUM_LIT:1000> , ) ) ) ) <EOL> def test_select_all_boxes ( self ) : <EOL> """<STR_LIT>""" <EOL> self . admin_login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . selenium . get ( '<STR_LIT>' % ( self . live_server_url , <EOL> reverse ( '<STR_LIT>' , args = ( <NUM_LIT:1000> , ) ) ) ) <EOL> test_classes = ( <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> ) <EOL> for elem_id , css_class in test_classes : <EOL> add_select_all = self . selenium . find_element_by_id ( <EOL> elem_id ) <EOL> add_select_all . click ( ) <EOL> add_checkboxes = self . selenium . find_elements_by_css_selector ( css_class ) <EOL> for e in add_checkboxes : <EOL> self . assertEqual ( e . get_attribute ( '<STR_LIT>' ) , '<STR_LIT:true>' ) <EOL> def test_initial_widget_is_hidden ( self ) : <EOL> """<STR_LIT>""" <EOL> self . admin_login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . selenium . get ( '<STR_LIT>' % ( self . live_server_url , <EOL> reverse ( '<STR_LIT>' , args = ( <NUM_LIT:1000> , ) ) ) ) <EOL> original_widget = self . selenium . find_element_by_css_selector ( '<STR_LIT>' ) <EOL> self . assertFalse ( original_widget . is_displayed ( ) ) <EOL> def test_initial_widget_is_visible_on_extra_permissions ( self ) : <EOL> """<STR_LIT>""" <EOL> Permission . objects . create ( codename = '<STR_LIT>' , content_type_id = <NUM_LIT:1> ) <EOL> self . goto_user_change ( ) <EOL> original_widget = self . selenium . find_element_by_css_selector ( '<STR_LIT>' ) <EOL> self . assertTrue ( original_widget . is_displayed ( ) ) <EOL> def test_save_table_permissions ( self ) : <EOL> """<STR_LIT>""" <EOL> self . goto_user_change ( ) <EOL> add_select_all = self . selenium . find_element_by_id ( '<STR_LIT>' ) <EOL> add_checkboxes = self . selenium . find_elements_by_css_selector ( '<STR_LIT>' ) <EOL> user_perms = [ ] <EOL> for e in add_checkboxes : <EOL> user_perms . append ( e . get_attribute ( '<STR_LIT>' ) ) <EOL> reminder_user_perms = list ( user_perms ) <EOL> add_select_all . click ( ) <EOL> save = self . selenium . find_element_by_css_selector ( '<STR_LIT>' ) <EOL> save . click ( ) <EOL> self . wait_page_loaded ( ) <EOL> user = User . objects . get ( pk = <NUM_LIT:1000> ) <EOL> user_saved_permissions = user . user_permissions . values_list ( '<STR_LIT:id>' , flat = True ) <EOL> user_saved_permissions = [ force_text ( x ) for x in user_saved_permissions ] <EOL> for perm in user_perms : <EOL> try : <EOL> user_saved_permissions . remove ( perm ) <EOL> reminder_user_perms . remove ( perm ) <EOL> except : <EOL> raise AssertionError <EOL> self . assertEqual ( len ( user_saved_permissions ) , <NUM_LIT:0> ) <EOL> self . assertEqual ( len ( reminder_user_perms ) , <NUM_LIT:0> ) <EOL> def test_visible_on_group_admin ( self ) : <EOL> """<STR_LIT>""" <EOL> self . admin_login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> self . selenium . get ( '<STR_LIT>' % ( self . live_server_url , <EOL> reverse ( '<STR_LIT>' ) ) ) <EOL> table = self . selenium . find_element_by_css_selector ( '<STR_LIT>' ) <EOL> self . assertEqual ( table . get_attribute ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_select_all_row ( self ) : <EOL> """<STR_LIT>""" <EOL> self . goto_user_change ( ) <EOL> first_row_checkbox = self . selenium . find_elements_by_css_selector ( '<STR_LIT>' ) [ <NUM_LIT:0> ] <EOL> first_row_checkbox . click ( ) <EOL> model_name = first_row_checkbox . get_attribute ( '<STR_LIT>' ) <EOL> related_checkboxes = self . selenium . find_elements_by_css_selector ( '<STR_LIT>' % model_name ) <EOL> for c in related_checkboxes : <EOL> self . assertTrue ( c . get_attribute ( '<STR_LIT>' ) ) </s>
