<s> from django . conf import settings <EOL> from django . core . urlresolvers import reverse <EOL> from django . test import TestCase , override_settings <EOL> import aristotle_mdr . models as models <EOL> import aristotle_mdr . perms as perms <EOL> import aristotle_mdr . tests . utils as utils <EOL> from django . test . utils import setup_test_environment <EOL> setup_test_environment ( ) <EOL> class BulkWorkgroupActionsPage ( utils . LoggedInViewPages , TestCase ) : <EOL> def setUp ( self ) : <EOL> super ( BulkWorkgroupActionsPage , self ) . setUp ( ) <EOL> self . item1 = models . ObjectClass . objects . create ( name = "<STR_LIT>" , workgroup = self . wg1 ) <EOL> self . item2 = models . ObjectClass . objects . create ( name = "<STR_LIT>" , workgroup = self . wg1 ) <EOL> self . item3 = models . ObjectClass . objects . create ( name = "<STR_LIT>" , workgroup = self . wg1 ) <EOL> self . item4 = models . Property . objects . create ( name = "<STR_LIT>" , workgroup = self . wg2 ) <EOL> def test_bulk_add_favourite_on_permitted_items ( self ) : <EOL> self . login_editor ( ) <EOL> self . assertEqual ( self . editor . profile . favourites . count ( ) , <NUM_LIT:0> ) <EOL> response = self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ self . item1 . id , self . item2 . id ] , <EOL> } <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( self . editor . profile . favourites . count ( ) , <NUM_LIT:2> ) <EOL> def test_bulk_add_favourite_on_forbidden_items ( self ) : <EOL> self . login_editor ( ) <EOL> self . assertEqual ( self . editor . profile . favourites . count ( ) , <NUM_LIT:0> ) <EOL> response = self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ self . item1 . id , self . item4 . id ] , <EOL> } , <EOL> follow = True <EOL> ) <EOL> self . assertEqual ( self . editor . profile . favourites . count ( ) , <NUM_LIT:1> ) <EOL> self . assertFalse ( self . item4 in self . editor . profile . favourites . all ( ) ) <EOL> self . assertTrue ( "<STR_LIT>" % self . item4 . id in response . content ) <EOL> self . assertEqual ( len ( response . redirect_chain ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( response . redirect_chain [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT> ) <EOL> def test_bulk_change_workgroup_for_superuser ( self ) : <EOL> self . new_workgroup = models . Workgroup . objects . create ( name = "<STR_LIT>" ) <EOL> self . new_workgroup . submitters . add ( self . editor ) <EOL> self . login_superuser ( ) <EOL> response = self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ self . item1 . id , self . item2 . id ] , <EOL> '<STR_LIT>' : [ self . new_workgroup . id ] , <EOL> "<STR_LIT>" : True <EOL> } <EOL> ) <EOL> self . assertTrue ( self . item1 . concept in self . new_workgroup . items . all ( ) ) <EOL> self . assertTrue ( self . item2 . concept in self . new_workgroup . items . all ( ) ) <EOL> self . logout ( ) <EOL> self . login_editor ( ) <EOL> response = self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ self . item1 . id , self . item2 . id ] , <EOL> '<STR_LIT>' : [ self . wg1 . id ] , <EOL> "<STR_LIT>" : True <EOL> } , <EOL> follow = True <EOL> ) <EOL> self . assertTrue ( self . item1 . concept in self . new_workgroup . items . all ( ) ) <EOL> self . assertTrue ( self . item2 . concept in self . new_workgroup . items . all ( ) ) <EOL> self . assertTrue ( "<STR_LIT>" in response . content ) <EOL> @ override_settings ( ARISTOTLE_SETTINGS = dict ( settings . ARISTOTLE_SETTINGS , WORKGROUP_CHANGES = [ '<STR_LIT>' ] ) ) <EOL> def test_bulk_change_workgroup_for_editor__for_some_items ( self ) : <EOL> self . new_workgroup = models . Workgroup . objects . create ( name = "<STR_LIT>" ) <EOL> self . new_workgroup . submitters . add ( self . editor ) <EOL> self . login_editor ( ) <EOL> self . assertTrue ( self . item1 . concept not in self . new_workgroup . items . all ( ) ) <EOL> self . assertTrue ( self . item2 . concept not in self . new_workgroup . items . all ( ) ) <EOL> self . assertTrue ( self . item4 . concept not in self . new_workgroup . items . all ( ) ) <EOL> response = self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ self . item1 . id , self . item2 . id , self . item4 . id ] , <EOL> '<STR_LIT>' : [ self . new_workgroup . id ] , <EOL> "<STR_LIT>" : True <EOL> } , <EOL> follow = True <EOL> ) <EOL> self . assertTrue ( self . item1 . concept in self . new_workgroup . items . all ( ) ) <EOL> self . assertTrue ( self . item2 . concept in self . new_workgroup . items . all ( ) ) <EOL> self . assertTrue ( self . item4 . concept not in self . new_workgroup . items . all ( ) ) <EOL> self . assertTrue ( "<STR_LIT>" % { <EOL> '<STR_LIT>' : "<STR_LIT:U+002C>" . join ( map ( str , [ self . item4 . pk ] ) ) <EOL> } in response . content ) <EOL> self . logout ( ) <EOL> self . login_superuser ( ) <EOL> response = self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ self . item1 . id , self . item2 . id , self . item4 . id ] , <EOL> '<STR_LIT>' : [ self . wg1 . id ] , <EOL> "<STR_LIT>" : True <EOL> } , <EOL> follow = True <EOL> ) <EOL> self . assertTrue ( self . item1 . concept in self . wg1 . items . all ( ) ) <EOL> self . assertTrue ( self . item2 . concept in self . wg1 . items . all ( ) ) <EOL> self . assertTrue ( self . item4 . concept in self . wg1 . items . all ( ) ) <EOL> self . assertTrue ( "<STR_LIT>" not in response . content ) <EOL> def test_bulk_remove_favourite ( self ) : <EOL> self . login_editor ( ) <EOL> self . assertEqual ( self . editor . profile . favourites . count ( ) , <NUM_LIT:0> ) <EOL> response = self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ self . item1 . id , self . item2 . id ] , <EOL> } <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( self . editor . profile . favourites . count ( ) , <NUM_LIT:2> ) <EOL> response = self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ self . item1 . id , self . item2 . id ] , <EOL> } <EOL> ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> self . assertEqual ( self . editor . profile . favourites . count ( ) , <NUM_LIT:0> ) <EOL> def test_bulk_status_change_on_permitted_items ( self ) : <EOL> self . login_registrar ( ) <EOL> self . item1 . readyToReview = True <EOL> self . item2 . readyToReview = True <EOL> self . item1 . save ( ) <EOL> self . item2 . save ( ) <EOL> self . assertTrue ( perms . user_can_change_status ( self . registrar , self . item1 ) ) <EOL> self . assertFalse ( self . item1 . is_registered ) <EOL> response = self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:state>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : [ self . item1 . id , self . item2 . id ] , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : [ self . ra . id ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> ) <EOL> self . assertTrue ( self . item1 . is_registered ) <EOL> self . assertTrue ( self . item2 . is_registered ) <EOL> def test_bulk_status_change_on_forbidden_items ( self ) : <EOL> self . login_registrar ( ) <EOL> self . item1 . readyToReview = True <EOL> self . item4 . readyToReview = True <EOL> self . item1 . save ( ) <EOL> self . item4 . save ( ) <EOL> self . assertTrue ( perms . user_can_change_status ( self . registrar , self . item1 ) ) <EOL> self . assertFalse ( self . item1 . is_registered ) <EOL> self . assertFalse ( self . item2 . is_registered ) <EOL> self . assertFalse ( self . item4 . is_registered ) <EOL> response = self . client . post ( <EOL> reverse ( '<STR_LIT>' ) , <EOL> { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT:state>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : [ self . item1 . id , self . item2 . id , self . item4 . id ] , <EOL> '<STR_LIT>' : "<STR_LIT>" , <EOL> '<STR_LIT>' : <NUM_LIT:0> , <EOL> '<STR_LIT>' : [ self . ra . id ] , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } , <EOL> follow = True <EOL> ) <EOL> self . assertEqual ( <NUM_LIT:200> , response . status_code ) <EOL> self . assertTrue ( self . item1 . is_registered ) <EOL> self . assertFalse ( self . item2 . is_registered ) <EOL> self . assertFalse ( self . item4 . is_registered ) <EOL> from django . utils . html import escape <EOL> err1 = "<STR_LIT>" <EOL> err2 = "<STR_LIT>" % '<STR_LIT:U+002C>' . join ( sorted ( [ str ( self . item2 . id ) , str ( self . item4 . id ) ] ) ) <EOL> self . assertTrue ( err1 in response . content ) <EOL> self . assertTrue ( err2 in response . content ) <EOL> self . assertEqual ( len ( response . redirect_chain ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( response . redirect_chain [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <NUM_LIT> ) </s>
