def test_getEvents(self): staff = OfficeStaff(user=self.user) staff.save() staff.practices.add(self.practice) manager = Office_Manager(user=staff, practice=self.practice, manager_role=2) manager.save() errData = {} successDate = {'fromDate': datetime.datetime(2012, 12, 12), 'toDate': datetime.datetime(2012, 12, 17)} #get method response = self.client.get(reverse('MHLogin.MHLCallGroups.Scheduler.'\ 'views_multicallgroup.getEvents', args=(self.practice.id, self.group.id)), data=successDate) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'DateEntry.html') #error data response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.getEvents', args=(self.practice.id, self.group.id)), data=errData) self.assertEqual(response.status_code, 403) #error call group group2 = CallGroup(description='test', team='team') group2.save() response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.getEvents', args=(self.practice.id, group2.id)), data=errData) self.assertEqual(response.status_code, 403) #success data and find 0 event response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.getEvents', args=(self.practice.id, self.group.id)), data=successDate) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEqual(data['redoSize'], 0) self.assertEqual(data['undoSize'], 0) self.assertEqual(data['datas'], '[]') #success data and find 1 event event = EventEntry(creator=self.user, oncallPerson=self.user, callGroup=self.group, startDate=datetime.datetime(2012, 12, 1), endDate=datetime.datetime(2012, 12, 30), title='test event', oncallLevel='0', eventStatus=1, checkString='abc' ) event.save() response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.getEvents', args=(self.practice.id, self.group.id)), data=successDate) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEqual(data['redoSize'], 0) self.assertEqual(data['undoSize'], 0) d = json.loads(data['datas']) self.assertEqual(len(d), 1) self.assertEqual(d[0]['pk'], event.pk)
def test_checkUserCrossDay(self): call_group = CallGroup(description='test', team='team') call_group.save() user = User(username='******', email='*****@*****.**', password='******', first_name='li', last_name='ds') user.save() result = checkUserCrossDay(user) self.assertEqual(result, True) startDate = datetime.datetime.now() + datetime.timedelta(days=-10) endDate = datetime.datetime.now() + datetime.timedelta(days=10) event = EventEntry(creator=user, oncallPerson=user, callGroup=call_group, startDate=startDate, endDate=endDate, title='test event', oncallLevel='0', eventStatus=1, checkString='abc') event.save() result = checkUserCrossDay(user) self.assertEqual(result, False)
def test_rulesCheck(self): staff = OfficeStaff(user=self.user) staff.save() staff.practices.add(self.practice) staff.current_practice = self.practice staff.save() manager = Office_Manager(user=staff, practice=self.practice, manager_role=1) manager.save() provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider.save() checkString = 'Ca69J2X6l8' #init a schecule event startDate = datetime.datetime.now() + datetime.timedelta(days=2) endDate = datetime.datetime.now() + datetime.timedelta(days=3) event = EventEntry(creator=self.user, oncallPerson=provider, callGroup=self.call_group, startDate=startDate, endDate=endDate, title='test event', oncallLevel='0', eventStatus=1, checkString=checkString) event.save() #get method response = self.client.get( reverse('MHLogin.MHLCallGroups.Scheduler.views.rulesCheck', args=(self.call_group.id, ))) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'DateEntry.html') #post method data = { 'fromDate': '2012-12-10 12:00:00', 'toDate': '2012-12-14 12:00:00' } response = self.client.post(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.rulesCheck', args=(self.call_group.id, )), data=data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg[0].find('warning hole in coverage '), 0)
def generateOnCallList(callgroup, startday, weekstart, user): weeks = [[] for i in xrange(6)] oncall_qs = EventEntry.objects.filter(callGroup=callgroup, startDate__lt=startday + datetime.timedelta(42), endDate__gte=startday, eventStatus=1).order_by('startDate') helper = EventHelper(oncall_qs, weekstart) slots = [ EventEntry(startDate=datetime.datetime(1, 1, 1), endDate=datetime.datetime(1, 1, 1)) ] * 10 for i, week in enumerate(weeks): week.extend({} for i in xrange(7)) for j, day in enumerate(week): day['date'] = startday + datetime.timedelta(weeks=i, days=j) day['events'] = [] for event in helper.filter(day['date']): name = ' '.join([ event.oncallPerson.first_name, event.oncallPerson.last_name ]) e = { 'name': name, 'starttime': time_format(user, event.startDate), 'endtime': time_format(user, event.endDate), 'color': _getColor(name), } #24 hours = 100%, 12 = 50%, etc. delta = event.endDate - event.startDate width = delta.days * 100.0 + delta.seconds / 3600.0 * 100 / 24 e['left'] = event.startDate.hour * 100.0 / 24 + \ event.startDate.minute / 60.0 * 100 / 24 e['width'] = width try: e['status'] = 1 if isCallGroupMember( event.oncallPerson, event.callGroup.id) else 0 except: e['status'] = 0 for k, _ in enumerate(slots): date = event.startDate - datetime.timedelta( hours=event.startDate.hour, minutes=event.startDate.minute) if (event.startDate >= slots[k].endDate and 'top' not in e): newslot = k for l, slot in enumerate(slots[:k + 1]): if slot.startDate >= date and event.startDate >= slot.endDate: newslot = l e['top'] = -19 * (len(day['events']) - newslot) slots[newslot] = event day['events'].append(e) break day['date'] = day['date'].strftime('%d') return weeks
def test_rulesCheck(self): staff = OfficeStaff(user=self.user) staff.save() staff.practices.add(self.practice) staff.current_practice = self.practice staff.save() manager = Office_Manager(user=staff, practice=self.practice, manager_role=1) manager.save() provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider.save() checkString = 'Ca69J2X6l8' #init a schecule event timenow = datetime.datetime.now() startDate = timenow + datetime.timedelta(days=2) endDate = timenow + datetime.timedelta(days=3) event = EventEntry(creator=self.user, oncallPerson=provider, callGroup=self.call_group, startDate=startDate, endDate=endDate, title='test event', oncallLevel='0', eventStatus=1, checkString=checkString ) event.save() #get method response = self.client.get(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.rulesCheck', args=(self.practice.id, self.call_group.id))) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'DateEntry.html') #post method data = {'fromDate': '2012-12-10 12:00:00', 'toDate': '2012-12-14 12:00:00'} response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.rulesCheck', args=(self.practice.id, self.call_group.id)), data=data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) start = datetime.datetime.now() end = start + datetime.timedelta(days=14) self.assertTrue('warning hole in coverage' in msg[0])
def test_checkDSEventConsistency(self): #invalid data eventInvalid = '' result = checkDSEventConsistency(eventInvalid) self.assertEqual(result, 0) #valid data call_group = CallGroup(description='test', team='team') call_group.save() provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider.save() callgm = CallGroupMember(call_group=call_group, member=provider, alt_provider=1) callgm.save() checkString = 'Ca69J2X6l8' event = EventEntry(creator=provider, oncallPerson=provider, callGroup=call_group, startDate=datetime.datetime(2012, 12, 1), endDate=datetime.datetime(2012, 12, 30), title='test event', oncallLevel='0', eventStatus=1, checkString=checkString ) event.save() data = '[{"pk":' + str(event.pk) + ',"model":"Scheduler.evententry","fields":{"oncallPerson":"' + \ str(provider.id) + '","eventType":"0","startDate":"2013-01-01 08:00:00", \ "endDate":"2013-01-02 08:00:00","checkString":"5xTTV2zUPm"}}]' for newdsEventObj in serializers.deserialize("json", data): newdsEventObj.object.callGroup_id = call_group.id newdsEventObj.object.notifyState = 2 newdsEventObj.object.whoCanModify = 1 newdsEventObj.object.eventStatus = 1 result = checkDSEventConsistency(newdsEventObj) self.assertEqual(result, 1)
def test_checkUserCrossDay(self): call_group = CallGroup(description='test', team='team') call_group.save() user = User(username='******', email='*****@*****.**', password='******', first_name='li', last_name='ds') user.save() result = checkUserCrossDay(user) self.assertEqual(result, True) startDate = datetime.datetime.now() + datetime.timedelta(days= -10) endDate = datetime.datetime.now() + datetime.timedelta(days=10) event = EventEntry(creator=user, oncallPerson=user, callGroup=call_group, startDate=startDate, endDate=endDate, title='test event', oncallLevel='0', eventStatus=1, checkString='abc' ) event.save() result = checkUserCrossDay(user) self.assertEqual(result, False)
def filter(self, day): nextday = day + datetime.timedelta(days=1) nextday = datetime.datetime(day=nextday.day, month=nextday.month, year=nextday.year) day = datetime.datetime(day=day.day, month=day.month, year=day.year) offset = 7 - day.isoweekday() + self.weekstart if (offset == 0): offset = 7 endofweek = day + datetime.timedelta(days=offset) startofweek = endofweek - datetime.timedelta(days=7) events = [] for i, event in enumerate(self.events): if (self.done[i] or event.startDate > nextday or event.endDate <= day): pass elif (event.startDate < startofweek): if (day == startofweek): fakeevent = EventEntry(oncallPerson=event.oncallPerson) fakeevent.startDate = max(startofweek, event.startDate) fakeevent.endDate = min(endofweek, event.endDate) if (endofweek >= event.endDate): self.done[i] = True events.append(fakeevent) elif (event.endDate > endofweek and event.startDate >= day and event.startDate < endofweek): fakeevent = EventEntry(oncallPerson=event.oncallPerson) fakeevent.startDate = max(day, event.startDate) fakeevent.endDate = min(endofweek, event.endDate) fakeevent._createdday = day if (endofweek >= event.endDate): self.done[i] = True events.append(fakeevent) elif (event.startDate >= day and event.startDate < nextday): #if(event.startDate >= day and event.startDate <= nextday): events.append(event) return events
def filter(self, day): nextday = day + datetime.timedelta(days=1) nextday = datetime.datetime(day=nextday.day, month=nextday.month, year=nextday.year) day = datetime.datetime(day=day.day, month=day.month, year=day.year) offset = 7 - day.isoweekday() + self.weekstart if (offset == 0): offset = 7 endofweek = day + datetime.timedelta(days=offset) startofweek = endofweek - datetime.timedelta(days=7) events = [] for i, event in enumerate(self.events): if (self.done[i] or event.startDate > nextday or event.endDate <= day): pass elif (event.startDate < startofweek): if(day == startofweek): fakeevent = EventEntry(oncallPerson=event.oncallPerson) fakeevent.startDate = max(startofweek, event.startDate) fakeevent.endDate = min(endofweek, event.endDate) if(endofweek >= event.endDate): self.done[i] = True events.append(fakeevent) elif (event.endDate > endofweek and event.startDate >= day and event.startDate < endofweek): fakeevent = EventEntry(oncallPerson=event.oncallPerson) fakeevent.startDate = max(day, event.startDate) fakeevent.endDate = min(endofweek, event.endDate) fakeevent._createdday = day if(endofweek >= event.endDate): self.done[i] = True events.append(fakeevent) elif (event.startDate >= day and event.startDate < nextday): #if(event.startDate >= day and event.startDate <= nextday): events.append(event) return events
def test_bulkUpdateEvents(self): staff = OfficeStaff(user=self.user) staff.save() staff.practices.add(self.practice) staff.current_practice = self.practice staff.save() manager = Office_Manager(user=staff, practice=self.practice, manager_role=1) manager.save() provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider.save() checkString = 'Ca69J2X6l8' #init a schecule event event = EventEntry(creator=self.user, oncallPerson=provider, callGroup=self.call_group, startDate=datetime.datetime(2012, 12, 1), endDate=datetime.datetime(2012, 12, 30), title='test event', oncallLevel='0', eventStatus=1, checkString=checkString ) event.save() #get method response = self.client.get(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.bulkUpdateEvents', args=(self.practice.id, self.call_group.id))) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "bulkOperation.html") #post method #not save new event,provider is not in the call group newEventInvalidData = {'data': '[{"pk":' + str(event.pk) + ',"model":"Scheduler.evententry","fields":{"oncallPerson":"' + str(provider.id) + '","eventType":"0","startDate":"2012-12-19 08:00:00","endDate":"2012-12-20 08:00:00","checkString":"' + checkString + '"}}]', 'view': '{"name":"month","start":"2012-12-01 00:00:00","end":"2013-01-01 00:00:00"}'} response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.bulkUpdateEvents', args=(self.practice.id, self.call_group.id)), data=newEventInvalidData) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['error'][0].find(str(event.pk) + ', error updating object ' + checkString + ' obj '), 0) #save new event, provider is in the call group provider2 = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider2.save() cgm = CallGroupMember(call_group=self.call_group, member=provider2, alt_provider=1) cgm.save() checkString = 'Ca69J2X6l8' newEventInvalidData = {'data': '[{"pk":' + str(event.pk) + ',"model":"Scheduler.evententry","fields":{"oncallPerson":"' + str(provider2.id) + '","eventType":"0","startDate":"2012-12-19 08:00:00",\ "endDate":"2012-12-20 08:00:00","checkString":"' + checkString + '"}}]', 'view': '{"name":"month","start":"2012-12-01 00:00:00","end":"2013-01-01 00:00:00"}'} response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.bulkUpdateEvents', args=(self.practice.id, self.call_group.id)), data=newEventInvalidData) self.assertEqual(response.status_code, 200) self.assertEqual(EventEntry.objects.count(), 1) #403 call_group2 = CallGroup(description='test2', team='team') call_group2.save() response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.bulkUpdateEvents', args=(self.practice.id, call_group2.id)), data=newEventInvalidData) self.assertEqual(response.status_code, 403) #invlid checkstring event update checkString = 'xxxxxxs' newEventInvalidData = {'data': '[{"pk":' + str(event.pk) + ',"model":"Scheduler.evententry","fields":{"oncallPerson":"' + str(provider2.id) + '","eventType":"0","startDate":"2012-12-19 08:00:00","endDate":\ "2012-12-20 08:00:00","checkString":"' + checkString + '"}}]', 'view': '{"name":"month","start":"2012-12-01 00:00:00","end":"2013-01-01 00:00:00"}'} response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.bulkUpdateEvents', args=(self.practice.id, self.call_group.id)), data=newEventInvalidData) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['error'][0].find(str(event.pk) + ', update failed - invalid checkString xxxxxxs obj'), 0)
def test_removeProviderCallGroup(self): #user is a manager staff = OfficeStaff(user=self.user) staff.current_practice = self.practice staff.save() staff.practices.add(self.practice) manager = Office_Manager(user=staff, practice=self.practice, manager_role=2) manager.save() #invalid provider provider_invalid = {'prov_id': 'abc'} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.removeProvider'), data=provider_invalid) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['err'], _('The data is error. Please refresh page again.')) #init a provider in practices provider1 = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider1.save() provider1.practices.add(self.practice) provider_data = {'prov_id': provider1.id} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.removeProvider'), data=provider_data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg, 'ok') self.assertNotEqual(provider1.practices, self.practice) #init a new provider in current practice and assign event user2 = create_user( 'practicemgr2', 'lin2', 'xing2', 'demo', '', '', '', '', ) provider2 = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user2, office_lat=0.0, office_longit=0.0) provider2.save() provider2.practices.add(self.practice) startDate = datetime.datetime.now() + datetime.timedelta(-10) endDate = datetime.datetime.now() + datetime.timedelta(10) event = EventEntry(creator=user2, oncallPerson=user2, callGroup=self.group, startDate=startDate, endDate=endDate, title='test event', oncallLevel='0', eventStatus=1, checkString='abc') event.save() provider_data = {'prov_id': provider2.id} #init key because send mail generate_keys_for_users(output=DevNull()) response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.removeProvider'), data=provider_data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg, 'ok') self.assertNotEqual(provider2.practices, self.practice) #init a provider in practices and current practice provider3 = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider3.current_practice = self.practice provider3.save() provider3.practices.add(self.practice) provider_data = {'prov_id': provider3.id} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.removeProvider'), data=provider_data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg, 'ok') self.assertNotEqual(provider1.practices, self.practice) self.assertIsNone(provider1.current_practice)
def test_bulkUpdateEvents(self): staff = OfficeStaff(user=self.user) staff.save() staff.practices.add(self.practice) staff.current_practice = self.practice staff.save() manager = Office_Manager(user=staff, practice=self.practice, manager_role=1) manager.save() provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider.save() checkString = 'Ca69J2X6l8' #init a schecule event event = EventEntry(creator=self.user, oncallPerson=provider, callGroup=self.call_group, startDate=datetime.datetime(2012, 12, 1), endDate=datetime.datetime(2012, 12, 30), title='test event', oncallLevel='0', eventStatus=1, checkString=checkString) event.save() #get method response = self.client.get( reverse('MHLogin.MHLCallGroups.Scheduler.views.bulkUpdateEvents', args=(self.call_group.id, ))) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, "bulkOperation.html") #post method #not save new event,provider is not in the call group newEventInvalidData = { 'data': '[{"pk":' + str(event.pk) + ',"model":"Scheduler.evententry","fields":{"oncallPerson":"' + str(provider.id) + '","eventType":"0","startDate":"2012-12-19 08:00:00",\ "endDate":"2012-12-20 08:00:00","checkString":"' + checkString + '"}}]', 'view': '{"name":"month","start":"2012-12-01 00:00:00","end":"2013-01-01 00:00:00"}' } response = self.client.post(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.bulkUpdateEvents', args=(self.call_group.id, )), data=newEventInvalidData) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual( msg['error'][0].find( str(event.pk) + ', error updating object ' + checkString + ' obj '), 0) #save new event, provider is in the call group provider2 = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider2.save() cgm = CallGroupMember(call_group=self.call_group, member=provider2, alt_provider=1) cgm.save() checkString = 'Ca69J2X6l8' newEventInvalidData = { 'data': '[{"pk":' + str(event.pk) + ',"model":"Scheduler.evententry","fields":{"oncallPerson":"' + str(provider2.id) + '","eventType":"0","startDate":"2012-12-19 08:00:00",\ "endDate":"2012-12-20 08:00:00","checkString":"' + checkString + '"}}]', 'view': '{"name":"month","start":"2012-12-01 00:00:00","end":"2013-01-01 00:00:00"}' } response = self.client.post(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.bulkUpdateEvents', args=(self.call_group.id, )), data=newEventInvalidData) self.assertEqual(response.status_code, 200) self.assertEqual(EventEntry.objects.count(), 1) #403 call_group2 = CallGroup(description='test2', team='team') call_group2.save() response = self.client.post(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.bulkUpdateEvents', args=(call_group2.id, )), data=newEventInvalidData) self.assertEqual(response.status_code, 403) #invlid checkstring event update checkString = 'xxxxxxs' newEventInvalidData = { 'data': '[{"pk":' + str(event.pk) + ',"model":"Scheduler.evententry","fields":{"oncallPerson":"' + str(provider2.id) + '","eventType":"0","startDate":"2012-12-19 08:00:00",\ "endDate":"2012-12-20 08:00:00","checkString":"' + checkString + '"}}]', 'view': '{"name":"month","start":"2012-12-01 00:00:00","end":"2013-01-01 00:00:00"}' } response = self.client.post(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.bulkUpdateEvents', args=(self.call_group.id, )), data=newEventInvalidData) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual( msg['error'][0].find( str(event.pk) + ', update failed - invalid checkString xxxxxxs obj'), 0)
def test_getEvents(self): staff = OfficeStaff(user=self.user) staff.save() staff.practices.add(self.practice) manager = Office_Manager(user=staff, practice=self.practice, manager_role=2) manager.save() errData = {} successDate = { 'fromDate': datetime.datetime(2012, 12, 12), 'toDate': datetime.datetime(2012, 12, 17) } #get method response = self.client.get(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.getEvents', args=(self.call_group.id, )), data=successDate) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'DateEntry.html') #error data response = self.client.post(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.getEvents', args=(self.call_group.id, )), data=errData) self.assertEqual(response.status_code, 403) #success data and find 0 event response = self.client.post(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.getEvents', args=(self.call_group.id, )), data=successDate) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEqual(data['redoSize'], 0) self.assertEqual(data['undoSize'], 0) self.assertEqual(data['datas'], '[]') #success data and find 0 event and call group in form successDateForm = { 'fromDate': datetime.datetime(2012, 12, 12), 'toDate': datetime.datetime(2012, 12, 17), 'callGroup': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.getEvents', args=(self.call_group.id, )), data=successDateForm) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEqual(data['redoSize'], 0) self.assertEqual(data['undoSize'], 0) self.assertEqual(data['datas'], '[]') #success data and find 1 event event = EventEntry(creator=self.user, oncallPerson=self.user, callGroup=self.call_group, startDate=datetime.datetime(2012, 12, 1), endDate=datetime.datetime(2012, 12, 30), title='test event', oncallLevel='0', eventStatus=1, checkString='abc') event.save() response = self.client.post(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.getEvents', args=(self.call_group.id, )), data=successDate) self.assertEqual(response.status_code, 200) data = json.loads(response.content) self.assertEqual(data['redoSize'], 0) self.assertEqual(data['undoSize'], 0) d = json.loads(data['datas']) self.assertEqual(len(d), 1) self.assertEqual(d[0]['pk'], event.pk) #error call group call_group2 = CallGroup(description='test', team='team') call_group2.save() response = self.client.post(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.getEvents', args=(call_group2.id, )), data=errData) self.assertEqual(response.status_code, 403)