<s> 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 . test import TestCase <EOL> from django . test . client import Client <EOL> from helpdesk . models import Queue , Ticket <EOL> from helpdesk import settings <EOL> class PerQueueStaffMembershipTestCase ( TestCase ) : <EOL> IDENTIFIERS = ( <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> def setUp ( self ) : <EOL> """<STR_LIT>""" <EOL> self . HELPDESK_ENABLE_PER_QUEUE_STAFF_PERMISSION = settings . HELPDESK_ENABLE_PER_QUEUE_STAFF_PERMISSION <EOL> settings . HELPDESK_ENABLE_PER_QUEUE_STAFF_PERMISSION = True <EOL> self . client = Client ( ) <EOL> User = get_user_model ( ) <EOL> self . superuser = User . objects . create ( <EOL> username = '<STR_LIT>' , <EOL> is_staff = True , <EOL> is_superuser = True , <EOL> ) <EOL> self . superuser . set_password ( '<STR_LIT>' ) <EOL> self . superuser . save ( ) <EOL> for identifier in self . IDENTIFIERS : <EOL> queue = self . __dict__ [ '<STR_LIT>' % identifier ] = Queue . objects . create ( <EOL> title = '<STR_LIT>' % identifier , <EOL> slug = '<STR_LIT>' % identifier , <EOL> ) <EOL> user = self . __dict__ [ '<STR_LIT>' % identifier ] = User . objects . create ( <EOL> username = '<STR_LIT>' % identifier , <EOL> is_staff = True , <EOL> ) <EOL> user . set_password ( identifier ) <EOL> user . save ( ) <EOL> p = Permission . objects . get ( codename = queue . permission_name [ <NUM_LIT:9> : ] ) <EOL> user . user_permissions . add ( p ) <EOL> for ticket_number in range ( <NUM_LIT:1> , identifier + <NUM_LIT:1> ) : <EOL> Ticket . objects . create ( <EOL> title = '<STR_LIT>' % ( ticket_number , identifier ) , <EOL> queue = queue , <EOL> ) <EOL> Ticket . objects . create ( <EOL> title = '<STR_LIT>' % ( ticket_number , identifier , identifier ) , <EOL> queue = queue , <EOL> assigned_to = user , <EOL> ) <EOL> def tearDown ( self ) : <EOL> """<STR_LIT>""" <EOL> settings . HELPDESK_ENABLE_PER_QUEUE_STAFF_PERMISSION = self . HELPDESK_ENABLE_PER_QUEUE_STAFF_PERMISSION <EOL> def test_dashboard_ticket_counts ( self ) : <EOL> """<STR_LIT>""" <EOL> for identifier in self . IDENTIFIERS : <EOL> self . client . login ( username = '<STR_LIT>' % identifier , password = identifier ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> len ( response . context [ '<STR_LIT>' ] ) , <EOL> identifier , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> len ( response . context [ '<STR_LIT>' ] ) , <EOL> <NUM_LIT:1> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> response . context [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] , <EOL> identifier * <NUM_LIT:2> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , <EOL> identifier * <NUM_LIT:2> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> len ( response . context [ '<STR_LIT>' ] ) , <EOL> <NUM_LIT:3> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> len ( response . context [ '<STR_LIT>' ] ) , <EOL> <NUM_LIT:2> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> response . context [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT>' ] + <EOL> response . context [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ '<STR_LIT>' ] , <EOL> <NUM_LIT:6> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] + <EOL> response . context [ '<STR_LIT>' ] [ '<STR_LIT>' ] [ <NUM_LIT:1> ] [ <NUM_LIT:1> ] , <EOL> <NUM_LIT:6> , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_ticket_list_per_queue_user_restrictions ( self ) : <EOL> """<STR_LIT>""" <EOL> for identifier in self . IDENTIFIERS : <EOL> self . client . login ( username = '<STR_LIT>' % identifier , password = identifier ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> len ( response . context [ '<STR_LIT>' ] ) , <EOL> identifier * <NUM_LIT:2> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> len ( response . context [ '<STR_LIT>' ] ) , <EOL> <NUM_LIT:1> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> response . context [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , <EOL> Queue . objects . get ( title = "<STR_LIT>" % identifier ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( reverse ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> len ( response . context [ '<STR_LIT>' ] ) , <EOL> <NUM_LIT:6> , <EOL> '<STR_LIT>' <EOL> ) <EOL> def test_ticket_reports_per_queue_user_restrictions ( self ) : <EOL> """<STR_LIT>""" <EOL> for identifier in self . IDENTIFIERS : <EOL> self . client . login ( username = '<STR_LIT>' % identifier , password = identifier ) <EOL> response = self . client . get ( <EOL> reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> ) <EOL> self . assertEqual ( <EOL> len ( response . context [ '<STR_LIT:data>' ] ) , <EOL> <NUM_LIT:2> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> sum ( [ sum ( user_tickets [ <NUM_LIT:1> : ] ) for user_tickets in response . context [ '<STR_LIT:data>' ] ] ) , <EOL> identifier * <NUM_LIT:2> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> len ( response . context [ '<STR_LIT>' ] ) , <EOL> <NUM_LIT:2> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> response . context [ '<STR_LIT>' ] [ <NUM_LIT:1> ] , <EOL> "<STR_LIT>" % identifier , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> response = self . client . get ( <EOL> reverse ( '<STR_LIT>' , kwargs = { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> ) <EOL> self . assertEqual ( <EOL> len ( response . context [ '<STR_LIT:data>' ] [ <NUM_LIT:0> ] ) , <EOL> <NUM_LIT:3> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> sum ( [ sum ( user_tickets [ <NUM_LIT:1> : ] ) for user_tickets in response . context [ '<STR_LIT:data>' ] ] ) , <EOL> <NUM_LIT:6> , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( <EOL> len ( response . context [ '<STR_LIT>' ] ) , <EOL> <NUM_LIT:3> , <EOL> '<STR_LIT>' <EOL> ) </s>
