<s> from django . test import TestCase <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 . contrib . auth . models import User <EOL> from django . core . urlresolvers import reverse <EOL> import datetime <EOL> from time import sleep <EOL> from django . test . utils import setup_test_environment <EOL> setup_test_environment ( ) <EOL> class CachingForRawPermissions ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . ra = models . RegistrationAuthority . objects . create ( name = "<STR_LIT>" ) <EOL> self . wg = models . Workgroup . objects . create ( name = "<STR_LIT>" ) <EOL> self . wg . registrationAuthorities = [ self . ra ] <EOL> self . wg . save ( ) <EOL> self . submitter = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . wg . submitters . add ( self . submitter ) <EOL> self . item = models . ObjectClass . objects . create ( name = "<STR_LIT>" , workgroup = self . wg ) <EOL> def test_can_edit_cache ( self ) : <EOL> self . assertTrue ( perms . user_can_edit ( self . submitter , self . item ) ) <EOL> self . item . definition = "<STR_LIT>" <EOL> self . item . save ( ) <EOL> self . assertTrue ( perms . user_can_edit ( self . submitter , self . item ) ) <EOL> self . item . definition = "<STR_LIT>" <EOL> self . item . save ( ) <EOL> sleep ( models . VERY_RECENTLY_SECONDS + <NUM_LIT:2> ) <EOL> self . assertTrue ( perms . user_can_edit ( self . submitter , self . item ) ) <EOL> reg , c = models . Status . objects . get_or_create ( <EOL> concept = self . item , <EOL> registrationAuthority = self . ra , <EOL> registrationDate = datetime . date ( <NUM_LIT> , <NUM_LIT:0> <NUM_LIT:4> , <NUM_LIT> ) , <EOL> state = models . STATES . standard <EOL> ) <EOL> self . assertFalse ( perms . user_can_edit ( self . submitter , self . item ) ) <EOL> def test_can_view_cache ( self ) : <EOL> self . viewer = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertTrue ( perms . user_can_view ( self . submitter , self . item ) ) <EOL> self . assertFalse ( perms . user_can_view ( self . viewer , self . item ) ) <EOL> self . item . definition = "<STR_LIT>" <EOL> self . item . save ( ) <EOL> self . assertTrue ( perms . user_can_view ( self . submitter , self . item ) ) <EOL> self . assertFalse ( perms . user_can_view ( self . viewer , self . item ) ) <EOL> self . item . definition = "<STR_LIT>" <EOL> self . item . save ( ) <EOL> sleep ( models . VERY_RECENTLY_SECONDS + <NUM_LIT:2> ) <EOL> self . assertTrue ( perms . user_can_view ( self . submitter , self . item ) ) <EOL> self . assertFalse ( perms . user_can_view ( self . viewer , self . item ) ) <EOL> reg , c = models . Status . objects . get_or_create ( <EOL> concept = self . item , <EOL> registrationAuthority = self . ra , <EOL> registrationDate = datetime . date ( <NUM_LIT> , <NUM_LIT:0> <NUM_LIT:4> , <NUM_LIT> ) , <EOL> state = models . STATES . standard <EOL> ) <EOL> self . assertTrue ( perms . user_can_view ( self . submitter , self . item ) ) <EOL> self . assertTrue ( perms . user_can_view ( self . viewer , self . item ) ) </s>
