<s> import datetime <EOL> from dateutil . relativedelta import relativedelta <EOL> import json <EOL> from django . contrib . auth . models import Permission <EOL> from django . core . urlresolvers import reverse <EOL> from django . db . models import Q <EOL> from timepiece . forms import DATE_FORM_FORMAT <EOL> from timepiece . tests import factories <EOL> from timepiece . tests . base import ViewTestMixin , LogTimeMixin <EOL> from timepiece . entries . models import Entry <EOL> from timepiece . reports . tests . base import ReportsTestBase <EOL> class TestBillableHours ( ViewTestMixin , LogTimeMixin , ReportsTestBase ) : <EOL> def setUp ( self ) : <EOL> super ( TestBillableHours , self ) . setUp ( ) <EOL> self . from_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:2> ) <EOL> self . to_date = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:4> ) <EOL> self . dates_data = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> self . url = reverse ( '<STR_LIT>' ) <EOL> self . perm = Permission . objects . filter ( codename = '<STR_LIT>' ) <EOL> self . admin = factories . User ( ) <EOL> self . admin . user_permissions = self . perm <EOL> def get_entries_data ( self ) : <EOL> query = Q ( end_time__gte = self . from_date , <EOL> end_time__lt = self . to_date + relativedelta ( days = <NUM_LIT:1> ) ) <EOL> return Entry . objects . date_trunc ( '<STR_LIT>' ) . filter ( query ) <EOL> def test_access_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> self . login_user ( self . admin ) <EOL> response = self . client . get ( self . url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> def test_access_no_permission ( self ) : <EOL> """<STR_LIT>""" <EOL> self . login_user ( self . user ) <EOL> response = self . client . get ( self . url ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT> ) <EOL> def test_response_data ( self ) : <EOL> """<STR_LIT>""" <EOL> self . bulk_entries ( ) <EOL> self . login_user ( self . admin ) <EOL> response = self . client . get ( self . url , data = { <EOL> '<STR_LIT>' : self . from_date . strftime ( DATE_FORM_FORMAT ) , <EOL> '<STR_LIT>' : self . to_date . strftime ( DATE_FORM_FORMAT ) , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : list ( Entry . objects . values_list ( '<STR_LIT:user>' , flat = True ) ) , <EOL> '<STR_LIT>' : list ( Entry . objects . values_list ( '<STR_LIT>' , <EOL> flat = True ) ) , <EOL> '<STR_LIT>' : list ( Entry . objects . values_list ( '<STR_LIT>' , <EOL> flat = True ) ) , <EOL> } ) <EOL> self . assertEqual ( response . status_code , <NUM_LIT:200> ) <EOL> entries_data = self . get_entries_data ( ) . order_by ( '<STR_LIT:user>' , '<STR_LIT:date>' ) <EOL> response_data = json . loads ( response . context [ '<STR_LIT:data>' ] ) <EOL> self . assertEqual ( response_data [ <NUM_LIT:1> ] [ <NUM_LIT:1> : ] , [ <NUM_LIT:9> , <NUM_LIT:9> ] ) <EOL> self . assertEqual ( response_data [ <NUM_LIT:2> ] [ <NUM_LIT:1> : ] , [ <NUM_LIT> , <NUM_LIT> ] ) </s>
