def setUpClass(cls): cls.request = Client() pl = PracticeLocation.objects.create(practice_lat=0.0, practice_longit=0.0) cls.provider = Provider(username="******", first_name="tester", last_name="meister", office_lat=0.0, office_longit=0.0) cls.provider.set_password("maestro") cls.provider.save() cls.provider2 = Provider(username="******", first_name="doc", last_name="holiday", office_lat=0.0, office_longit=0.0) cls.provider2.set_password("holiday") cls.provider2.save() cls.userm = MHLUser(username="******", first_name="important", last_name="manager", is_active=True) cls.userm.set_password("monkey") cls.userm.save() cls.userstaff = OfficeStaff(current_practice=pl) cls.userstaff.user = cls.userm cls.userstaff.save() generate_keys_for_users(output=DevNull()) # needed by our login VMBox_Config(owner=cls.provider).save() VMBox_Config(owner=cls.provider2).save() VMBox_Config(owner=cls.userstaff).save()
def test_getMembers(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() #0 member found response = self.client.post(reverse('MHLogin.MHLCallGroups.views.getMembers', args=(self.call_group.id,))) self.assertEqual(response.status_code, 200) #1 member found provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider.save() member = CallGroupMember(call_group=self.call_group, member=provider, alt_provider=1) member.save() response = self.client.post(reverse('MHLogin.MHLCallGroups.views.getMembers', args=(self.call_group.id,))) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1) self.assertEqual(msg[0][0], provider.id) #403 call_group2 = CallGroup(description='test2', team='team') call_group2.save() response = self.client.post(reverse('MHLogin.MHLCallGroups.views.getMembers', args=(call_group2.id,))) self.assertEqual(response.status_code, 403)
def test_getCurrentPractice(self): practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.save() user = create_user('practicemgr1', 'lin', 'xing', 'demo') #a mhluser login and call this method result = getCurrentPractice(user) self.assertEqual(result, '') #a provider login and call this method provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider.current_practice = practice provider.save() result = getCurrentPractice(user) self.assertEqual(result, 'test') #a staff login and call this method staff = OfficeStaff(user=user) staff.current_practice = practice staff.save() result = getCurrentPractice(user) self.assertEqual(result, 'test')
def test_checkeUserInCallGroup(self): call_group = CallGroup(description='test', team='team') call_group.save() request = HttpRequest() user = create_user('practicemgr1', 'lin', 'xing', 'demo') provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider.save() mem = CallGroupMember(call_group=call_group, member=provider, alt_provider=1) mem.save() request.method = 'POST' request.POST['userId'] = user.pk response = checkeUserInCallGroup(request, call_group.id) self.assertEqual(response.content, '"ok"') call_group2 = CallGroup(description='test', team='team') call_group2.save() response = checkeUserInCallGroup(request, call_group2.id) self.assertEqual(response.content, '"err"')
def test_validateNewEvent(self): #invalid data eventInvalid = '' result = validateNewEvent(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() data = '[{"pk":null,"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 = validateNewEvent(newdsEventObj) self.assertEqual(result, 1)
def test_getCurrentPractice(self): practice = PracticeLocation( practice_name='test', practice_longit='0.1', practice_lat='0.0', ) practice.save() user = create_user('practicemgr1', 'lin', 'xing', 'demo') #a mhluser login and call this method result = getCurrentPractice(user) self.assertEqual(result, '') #a provider login and call this method provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider.current_practice = practice provider.save() result = getCurrentPractice(user) self.assertEqual(result, 'test') #a staff login and call this method staff = OfficeStaff(user=user) staff.current_practice = practice staff.save() result = getCurrentPractice(user) self.assertEqual(result, 'test')
def test_addProviderToPractice(self, start_thread): #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 assoc id assocID = {'assoc_id': 'a'} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.addProviderToPractice'), data=assocID) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['err'], _('A server error has occurred.')) #valid assoc id to_user = create_user( 'p2', 'lin2', 'xing2', 'demo', '', '', '', '', ) provider = Provider(username='******', first_name='first', last_name="last", email='*****@*****.**', user=self.user, office_lat=0.0, office_longit=0.0) provider.save() pend = Pending_Association(from_user=self.user, to_user=to_user, practice_location=self.practice, created_time=datetime.datetime.now()) pend.save() assocID = {'assoc_id': pend.id} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.addProviderToPractice'), data=assocID) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg, 'ok') self.assertEqual( Log_Association.objects.get(association_id=pend.id).action, 'ACC') self.assertEqual(Pending_Association.objects.count(), 0) self.assertEqual( self.practice in Provider.objects.get(pk=provider.pk).practices.all(), True) mems = CallGroupMember.objects.filter(call_group=self.call_group) self.assertEqual(len(mems), 1)
def test_get_all_providers_and_staffs(self): request = generateHttpRequest() #get method request.method = 'GET' result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE002') #post method request.method = 'POST' #find 0 any type user result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['users']), 0) #has 1 nppa user = create_user('np1', 'abc', '', 'demo') provider = Provider(user=user, username='******', first_name='abc', last_name='', office_lat=0.0, office_longit=0.0) provider.save() nppa = NP_PA(user=provider) nppa.save() request.POST['name'] = unicode('abc') result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['users']), 1) self.assertEqual(msg['users'][0]['first_name'], 'abc') phy = Physician(user=provider) phy.save() result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['users']), 2) self.assertEqual(msg['users'][0]['first_name'], 'abc') #staff organization_type = create_org_type() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0', mdcom_phone='8005550085', organization_type=organization_type) practice.save() staff = OfficeStaff(user=request.user, current_practice=practice) staff.save() staff.practices.add(practice) request.POST['name'] = unicode(request.user.first_name) result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) self.assertEqual(len(msg['users']), 2) self.assertEqual(msg['users'][0]['first_name'], 'abc')
def setUpClass(cls): clean_db_datas() cls.call_group = CallGroup.objects.create(description='test', team='team') cls.user = create_user('practicemgr1', 'lin', 'xing', 'demo') cls.user1 = create_user('practicemgr2', 'yang', 'peng', 'demo') cls.user2 = create_user('practicemgr234', 'yang1', 'peng1', 'demo') practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0', call_group = cls.call_group,) practice.save() practice1 = PracticeLocation(practice_name='test1', practice_longit='0.1', practice_lat='0.0', call_group = cls.call_group,) practice1.save() OrganizationRelationship.objects.create(organization=practice,\ parent=practice1,create_time=int(time.time()),billing_flag=True) cls.practice = practice cls.practice1 = practice1 provider = Provider(user=cls.user1, office_lat=0.0, office_longit=0.0, current_practice = practice) provider.save() provider.practices.add(practice) provider.practices.add(practice1) cls.provider = provider cls.provider2 = Provider(username="******", first_name="doc", last_name="holiday", office_lat=0.0, office_longit=0.0) cls.provider2.set_password("holiday") cls.provider2.save() VMBox_Config(owner=cls.provider2).save() staff = OfficeStaff() staff.user = cls.user staff.office_lat = 0.0 staff.office_longit = 0.0 staff.current_practice = practice staff.save() staff.practices.add(practice) cls.event = EventEntry(creator=cls.user, oncallPerson=cls.user1, callGroup=cls.call_group, startDate=datetime.datetime(2012, 12, 1), endDate=datetime.datetime.now()+datetime.timedelta(days = 2), title='test event', oncallLevel='0', eventStatus=1, checkString='abc' ) cls.event.save() mgr = Office_Manager(user=staff, practice=practice, manager_role=2) mgr.save() generate_keys_for_users(output=DevNull())
def test_rejectAssociation(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 assoc id assocID = {'assoc_id': 'a'} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.rejectAssociation'), data=assocID) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual( msg['err'], _('The data is error. Please refresh the page again.')) #valid assoc id to_user = create_user( 'p2', 'lin2', 'xing2', 'demo', '', '', '', '', ) provider = Provider(username='******', first_name='first', last_name="last", email='*****@*****.**', user=self.user, office_lat=0.0, office_longit=0.0) provider.save() pend = Pending_Association(from_user=self.user, to_user=to_user, practice_location=self.practice, created_time=datetime.datetime.now()) pend.save() assocID = {'assoc_id': pend.id} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.rejectAssociation'), data=assocID) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg, 'OK') self.assertEqual( Log_Association.objects.get(association_id=pend.id).action, 'REJ') self.assertEqual(Pending_Association.objects.count(), 0)
def test_getMembers(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() #0 member found response = self.client.post( reverse('MHLogin.MHLCallGroups.views_multicallgroup.getMembers', args=( self.practice.id, self.call_group.id, ))) self.assertEqual(response.status_code, 200) #1 member found provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider.save() member = CallGroupMember(call_group=self.call_group, member=provider, alt_provider=1) member.save() response = self.client.post( reverse('MHLogin.MHLCallGroups.views_multicallgroup.getMembers', args=( self.practice.id, self.call_group.id, ))) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1) self.assertEqual(msg[0][0], provider.id) #403 call_group2 = CallGroup(description='test2', team='team') call_group2.save() response = self.client.post( reverse('MHLogin.MHLCallGroups.views_multicallgroup.getMembers', args=( self.practice.id, call_group2.id, ))) self.assertEqual(response.status_code, 403)
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 setUp(self): clean_db_datas() self.user = create_user(get_random_username(), "yang", "peng", "demo") self.user.mobile_phone = 9563322588 self.user.mobile_confirmed = True self.user.email_confirmed = True self.user.save() self.provider = Provider(user=self.user, office_lat=0.0, office_longit=0.0, pager='8001234567') self.provider.save()
def setUpClass(cls): clean_db_datas() user = create_user( 'practicemgr1', 'lin', 'xing', 'demo', '', '', '', '', ) cls.user = user call_group = CallGroup(description='test', team='team') call_group.save() cls.group = call_group practice = PracticeLocation( practice_name='Test Org', practice_longit='0.1', practice_lat='0.0', ) practice.save() cls.practice = practice provider = Provider() provider.user = cls.user provider.office_lat = 0.0 provider.office_longit = 0.0 provider.current_practice = practice provider.save() provider.practices.add(practice) cls.provider = provider practice.call_groups.add(call_group) cls.practice = practice
def test_associate_provider(self): provider = Provider(office_lat=0.0, office_longit=0.0, user=self.user) provider.save() self.user = provider self.user.save() providerData = {'username': self.user.user.username, 'password': '******', 'device_id': 'e2c73b2b28f7466da855005ef48cdeaa', 'app_version': '1.00.22', 'platform': 'iPad', } response = self.client.post(reverse('MHLogin.apps.smartphone.v1.views_device.associate'), data=providerData) self.assertEqual(response.status_code, 200)
def test_isCallGroupMember(self): call_group = CallGroup(description='test', team='team') call_group.save() user = create_user('user6', 'us', 'er', 'demo') result = isCallGroupMember(user, call_group.id) self.assertEqual(result, False) provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider.save() call_groupm = CallGroupMember(call_group=call_group, member=provider, alt_provider=1) call_groupm.save() result = isCallGroupMember(provider, call_group.id) self.assertEqual(result, True)
def test_associate_provider(self): provider = Provider(office_lat=0.0, office_longit=0.0, user=self.user) provider.save() self.user = provider self.user.save() providerData = { 'username': self.user.user.username, 'password': '******', 'device_id': 'e2c73b2b28f7466da855005ef48cdeaa', 'app_version': '1.00.22', 'platform': 'iPad', } response = self.client.post( reverse('MHLogin.apps.smartphone.v1.views_device.associate'), data=providerData) self.assertEqual(response.status_code, 200)
def setUpClass(cls): clean_db_datas() cls.user = create_user(get_random_username(), 'lin', 'xing', 'demo') cls.user1 = create_user(get_random_username(), 'y', 'p', 'demo') cls.user2 = create_user(get_random_username(), 'y', 'p', 'demo') cls.to_user = create_user(get_random_username(), "tian", "thj", "demo", "555 Bryant St.", "Palo Alto", "CA", "") practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.save() practice1 = PracticeLocation(practice_name='test1', practice_longit='0.1', practice_lat='0.0',) practice1.save() OrganizationRelationship.objects.create(organization=practice,\ parent=practice1,create_time=int(time.time()),billing_flag=True) cls.practice = practice cls.practice1 = practice1 assoc = Pending_Association() assoc.from_user = cls.user1 assoc.to_user = cls.to_user assoc.practice_location = practice assoc.created_time = datetime.datetime(2013, 5, 14, 12, 30) assoc.resent_time = datetime.datetime(2013, 5, 14, 13, 30) assoc.save() cls.assoc = assoc provider = Provider(user=cls.to_user, office_lat=0.0, office_longit=0.0, current_practice = practice) provider.save() cls.provider = provider staff = OfficeStaff() staff.user = cls.user staff.office_lat = 0.0 staff.office_longit = 0.0 staff.current_practice = practice staff.save() staff.practices.add(practice) mgr = Office_Manager(user=staff, practice=practice, manager_role=2) mgr.save()
def test_addPrvoderIn(self): prov = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) prov.save() 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() data = {'to_user': prov.id} response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.addPrvoderIn', args=(self.practice.id, self.group.id)), data=data) msg = json.loads(response.content) self.assertEqual(response.status_code, 200) self.assertEqual(0, msg['err'].find('Congratulations'))
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 generateHttpRequest(): # Fix for 2030 - should rename function, it does more than just generate request # TODO: for requests should use Django's test Client(), see IVR unittests for # example of view unittests using Django's test client request handling features. env = Client()._base_environ() user = create_mhluser() request = HttpRequest() request.META['REMOTE_ADDR'] = env['REMOTE_ADDR'] key = strengthen_key('demo') split1, split2 = split_user_key('demo') db_key = os.urandom(32) xor = XOR.new(base64.b64decode(split2)) dbsplit = base64.b64encode(xor.encrypt(db_key)) assn = SmartPhoneAssn( user=user, device_serial='', version='1.22', platform='iPad', user_type=1, ) assn.save(request) assn.update_secret(split1, key) assn.update_db_secret(dbsplit, db_key) request.REQUEST = {} request.META['HTTP_DCOM_DEVICE_ID'] = request.REQUEST[ 'DCOM_DEVICE_ID'] = assn.device_id request.session = dict() request.user = user providers = Provider.objects.filter(user=user) if not providers: provider = Provider(user=request.user, office_lat=0.0, office_longit=0.0) provider.save() request.provider = provider request.role_user = provider return request
def test_addAssociation(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() #provider id user = create_user( 'p', 'lin2', 'xing2', 'demo', '', '', '', '', ) provider = Provider(username='******', first_name='first', last_name="last", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider.save() data = {'prov_id': provider.user.id, 'userType': 1} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.addAssociation'), data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg[0], 'ok') self.assertEqual(Pending_Association.objects.count(), 1) self.assertEqual( Pending_Association.objects.get(to_user=provider.user).from_user, self.user) self.assertEqual(Log_Association.objects.count(), 1)
def test_checkeUserInCallGroup(self): call_group = CallGroup(description='test', team='team') call_group.save() request = HttpRequest() user = create_user('practicemgr1', 'lin', 'xing', 'demo') provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider.save() mem = CallGroupMember(call_group=call_group, member=provider, alt_provider=1) mem.save() request.method = 'POST' request.POST['userId'] = user.pk response = checkeUserInCallGroup(request, call_group.id) self.assertEqual(response.content, '"ok"') call_group2 = CallGroup(description='test', team='team') call_group2.save() response = checkeUserInCallGroup(request, call_group2.id) self.assertEqual(response.content, '"err"')
def test_new_event(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() #get method response = self.client.get(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.bulkNewEvents', 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 provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider.save() checkString = 'Ca69J2X6l8' newEventInvalidData = {'data': '[{"pk":null,"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.bulkNewEvents', 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], checkString + ', error saving new object') #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":null,"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.bulkNewEvents', 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.bulkNewEvents', args=(self.practice.id, call_group2.id)), data=newEventInvalidData) self.assertEqual(response.status_code, 403)
def generateHttpRequest(): # Fix for 2030 - should rename function, it does more than just generate request # TODO: for requests should use Django's test Client(), see IVR unittests for # example of view unittests using Django's test client request handling features. env = Client()._base_environ() user = create_mhluser() request = HttpRequest() request.META['REMOTE_ADDR'] = env['REMOTE_ADDR'] key = strengthen_key('demo') split1, split2 = split_user_key('demo') db_key = os.urandom(32) xor = XOR.new(base64.b64decode(split2)) dbsplit = base64.b64encode(xor.encrypt(db_key)) assn = SmartPhoneAssn( user=user, device_serial='', version='1.22', platform='iPad', user_type=1, ) assn.save(request) assn.update_secret(split1, key) assn.update_db_secret(dbsplit, db_key) request.REQUEST = {} request.META['HTTP_DCOM_DEVICE_ID'] = request.REQUEST['DCOM_DEVICE_ID'] = assn.device_id request.session = dict() request.user = user providers = Provider.objects.filter(user=user) if not providers: provider = Provider(user=request.user, office_lat=0.0, office_longit=0.0) provider.save() request.provider = provider request.role_user = provider return request
def test_getPenddings(self): request = HttpRequest() user = create_user('practicemgr1', 'lin', 'xing', 'demo') call_group = CallGroup(description='test', team='team') call_group.save() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.save() from_user = create_user('from user', 'lin', 'xing', 'demo') to_user = create_user('to user', 'lin', 'xing', 'demo') to_user = Provider(username='******', first_name='tes3', last_name="meister3", email='*****@*****.**', user=to_user, office_lat=0.0, office_longit=0.0) to_user.save() #0 pending find request.user = to_user response = getPenddings(request) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 0) #1 pending find pend = CallGroupMemberPending(from_user=from_user, to_user=to_user, practice=practice, call_group=call_group, accept_status=0, created_time=datetime.datetime.now()) pend.save() request.user = to_user response = getPenddings(request) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1)
def test_isCallGroupMember(self): call_group = CallGroup(description='test', team='team') call_group.save() user = create_user('user6', 'us', 'er', 'demo') result = isCallGroupMember(user, call_group.id) self.assertEqual(result, False) provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider.save() call_groupm = CallGroupMember(call_group=call_group, member=provider, alt_provider=1) call_groupm.save() result = isCallGroupMember(provider, call_group.id) self.assertEqual(result, True)
class ValidationPageTest(TestCase): def setUp(self): clean_db_datas() self.user = create_user(get_random_username(), "yang", "peng", "demo") self.user.mobile_phone = 9563322588 self.user.mobile_confirmed = True self.user.email_confirmed = True self.user.save() self.provider = Provider(user=self.user, office_lat=0.0, office_longit=0.0, pager='8001234567') self.provider.save() def tearDown(self): clean_db_datas() def testValidationPage(self): self.client.post('/login/', { 'username': self.provider.user.username, 'password': '******' }) response = self.client.post( reverse('MHLogin.Validates.views.validationPage')) self.assertEqual(response.status_code, 302) self.client.logout() self.client.post('/login/', { 'username': self.provider.user.username, 'password': '******' }) response = self.client.get( reverse('MHLogin.Validates.views.validationPage')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'Validates/validation.html') self.client.logout()
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 setUpClass(cls): clean_db_datas() cls.user = create_user('practicemgr1', 'lin', 'xing', 'demo') cls.user1 = create_user('practicemgr11', 'y', 'p', 'demo') cls.broker = create_user("broker1", "bro", "1", "demo", "123 Main St.", "Phoenix", "AZ", uklass=Broker) practice = PracticeLocation( practice_name='test', practice_longit='0.1', practice_lat='0.0', ) practice.save() practice1 = PracticeLocation( practice_name='test1', practice_longit='0.1', practice_lat='0.0', ) practice1.save() OrganizationRelationship.objects.create(organization=practice,\ parent=practice1, create_time=int(time.time()), billing_flag=True) cls.practice = practice staff = OfficeStaff() staff.user = cls.user staff.office_lat = 0.0 staff.office_longit = 0.0 staff.current_practice = practice staff.save() staff.practices.add(practice) cls.provider = Provider(user=cls.user1, office_lat=0.0, office_longit=0.0, current_practice=practice) cls.provider.mdcom_phone = '5948949899' cls.provider.save() # mgr = Office_Manager(user=staff, practice=practice, manager_role=2) mgr.save()
def test_addProviderInGroup(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() provider1 = Provider(username='******', first_name='tes provider1', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider1.save() data1 = {'to_user': provider1.id} msg1 = '''This user is not in your practice now. We have sent an invitation to him/her for confirm to join this call group. (He/She will not join your practice by accept this invitation.)''' #provider1 not in practice response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.addProviderInGroup', args=(self.practice.id, self.group.id)), data=data1) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['err'], msg1) #add provider2 in practice in this case provider2 = Provider(username='******', first_name='tes provider2', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider2.save() provider2.practices.add(self.practice) provider2.current_practice = self.practice provider2.save() data2 = {'to_user': provider2.id} msg2 = 'Congratulations! We have added this member to call group. You can:' response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.addProviderInGroup', args=(self.practice.id, self.group.id)), data=data2) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['err'], msg2)
def setUpClass(cls): clean_db_datas() user = create_user('practicemgr1', 'lin', 'xing', 'demo', '', '', '', '',) cls.user =user call_group = CallGroup(description='test', team='team') call_group.save() cls.group = call_group practice = PracticeLocation(practice_name='Test Org', practice_longit='0.1', practice_lat='0.0',) practice.save() cls.practice = practice provider = Provider() provider.user = cls.user provider.office_lat = 0.0 provider.office_longit = 0.0 provider.current_practice = practice provider.save() provider.practices.add(practice) cls.provider = provider practice.call_groups.add(call_group) cls.practice = practice
def setUpClass(cls): clean_db_datas() cls.user = create_user('practicemgr1', 'lin', 'xing', 'demo') practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0', ) practice.save() practice1 = PracticeLocation(practice_name='test1', practice_longit='0.1', practice_lat='0.0', ) practice1.save() OrganizationRelationship.objects.create(organization=practice,\ parent=practice1,create_time=int(time.time()),billing_flag=True) cls.practice = practice cls.practice1 = practice1 staff = OfficeStaff() staff.user = cls.user staff.office_lat = 0.0 staff.office_longit = 0.0 staff.current_practice = practice staff.save() staff.practices.add(practice) user1 = create_user('Provoder1', 'pro1', 'pro1', 'demo') provider = Provider(user=user1) provider.office_lat = 0.0 provider.office_longit = 0.0 provider.current_practice = practice1 provider.save() provider.practices.add(practice1) cls.provider = provider mgr = Office_Manager(user=staff, practice=practice, manager_role=2) mgr.save()
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_redo(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() #403 call_group2 = CallGroup(description='test2', team='team') call_group2.save() response = self.client.post( reverse('MHLogin.MHLCallGroups.Scheduler.views.redo', args=(call_group2.id, ))) self.assertEqual(response.status_code, 403) response = self.client.post( reverse('MHLogin.MHLCallGroups.Scheduler.views.redo', args=(self.call_group.id, ))) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['count'], 0) #create a new event, and redo provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0, current_practice=self.practice) provider.save() provider.practices.add(self.practice) cgm = CallGroupMember(call_group=self.call_group, member=provider, alt_provider=1) cgm.save() checkString = 'Ca69J2X6l8' newEventInvalidData = { 'data': '[{"pk":null,"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"}' } new_event = self.client.post(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.bulkNewEvents', args=(self.call_group.id, )), data=newEventInvalidData) response = self.client.post( reverse('MHLogin.MHLCallGroups.Scheduler.views.redo', args=(self.call_group.id, ))) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['undoSize'], 1) self.assertEqual(msg['redoSize'], 0) self.assertEqual(EventEntry.objects.count(), 1) #create a new and change event 1 time event = EventEntry.objects.get(checkString=checkString) #update updateEventInvalidData = { 'data': '[{"pk":' + str(event.pk) + ',"model":"Scheduler.evententry","fields":{"oncallPerson":"' + str(provider.id) + '","eventType":"0","startDate":"2012-12-20 08:00:00","endDate":"2012-12-21 08:00:00",\ "eventStatus":1,"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=updateEventInvalidData) response = self.client.post( reverse('MHLogin.MHLCallGroups.Scheduler.views.redo', args=(self.call_group.id, ))) msg = json.loads(response.content) self.assertEqual(msg['redoSize'], 0) self.assertEqual(msg['undoSize'], 2) self.assertEqual(msg['operateList'], [])
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_joincallgroup(self): from_user = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) from_user.save() to_user = Provider(username='******', first_name='tes3', last_name="meister3", email='*****@*****.**', office_lat=0.0, office_longit=0.0) to_user.save() call_group_team = 'team' call_group = CallGroup(description='test', team=call_group_team) call_group.save() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.save() practice.call_groups.add(call_group) #init http request request = HttpRequest() request.session = dict() request.session['MHL_Users'] = {} request.session['MHL_UserIDs'] = 'OfficeStaff' #test get method request.method = 'GET' #test get method and accept type type = 'Accept' response = joinCallGroup(request, type) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, '"err"') #test get method and reject type type = 'Reject' response = joinCallGroup(request, type) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, '"err"') #test method post request.method = 'POST' accept_group = CallGroupMemberPending(from_user=from_user, to_user=to_user, practice=practice, call_group=call_group, created_time=datetime.datetime.now()) accept_group.save() request.POST['id'] = accept_group.id request.session['MHL_Users']['Provider'] = to_user #accept 1 provider in call group type = 'Accept' response = joinCallGroup(request, type) self.assertEqual(response.status_code, 200) ret_data = json.loads(response.content) self.assertEqual(ret_data["success"], True) self.assertEqual(ret_data["message"], \ _('You have successfully joined %s call group.')\ %(call_group_team)) cgm = CallGroupMemberPending.objects.get(pk=accept_group.id) self.assertEqual(cgm.accept_status, 1) #reject 1 provider in call group cgmReject = CallGroupMemberPending(from_user=from_user, to_user=to_user, practice=practice, call_group=call_group, created_time=datetime.datetime.now()) cgmReject.save() request.POST['id'] = cgmReject.id type = 'Reject' response = joinCallGroup(request, type) self.assertEqual(response.status_code, 200) ret_data = json.loads(response.content) self.assertEqual(ret_data["success"], True) self.assertEqual(ret_data["message"], \ _('You have declined %s\'s invitation.')\ %(call_group_team)) cgm = CallGroupMemberPending.objects.get(pk=cgmReject.id) self.assertEqual(cgm.accept_status, 2)
def _add_providers(self): for user in self.prov_data: self.pusr = None self.mhu = None self.prov = None pusr = Provider(username=user["username"], first_name=user["first_name"], last_name=user["last_name"]) pusr.is_active = pusr.is_staff = pusr.tos_accepted = True pusr.set_password("demo") pusr.address1 = user['addr1'] pusr.address2 = user['addr2'] pusr.city = user['city'] pusr.state = user['state'] pusr.zip = user['zipcode'] pusr.is_active = pusr.is_staff = pusr.tos_accepted = pusr.mobile_confirmed = pusr.email_confirmed = True pusr.phone = user['phone'] pusr.mobile_phone = user['mobile_phone'] pusr.skill = "" pusr.is_superuser = True pusr.office_address = user["office_address1"] pusr.office_address2 = "" pusr.office_phone = user["office_phone"] pusr.office_city = user["office_city"] pusr.office_state = user["office_state"] pusr.office_zip = user["office_zip"] pusr.forward_mobile = user["forward_mobile"] pusr.forward_office = user["forward_office"] pusr.forward_other = user["forward_other"] pusr.forward_vmail = user["forward_vmail"] pusr.forward_voicemail = user["forward_voicemail"] pusr.forward_anssvc = user["forward_anssvc"] pusr.mdcom_phone = user["mdcom_phone"] pusr.mdcom_phone_sid = user["mdcom_phone_sid"] pusr.status_verified = user["status_verified"] pusr.clinical_clerk = "" pusr.office_lat = 37.36876 pusr.office_longit = -122.081864 pusr.save() pusr.user = pusr user["id"] = pusr.id pusr.practices = user["practices"] pusr.save() vmbox = VMBox_Config(owner=pusr) vmbox.save() self.providers.append(pusr)
def test_getProviderByEmailOrNameInCallGroup(self): #user is a manager staff = OfficeStaff(user=self.user) staff.current_practice = self.practice staff.save() staff.practices.add(self.practice) #get method response = self.client.get( reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' )) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['err'], _('A server error has occurred.')) #post method searchOptions = { 'email': '', 'fullname': '', 'firstName': '', 'lastName': '', 'username': '', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchOptions) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 0) #find 1 provider user = create_user( 'provider1', 'lin', 'xing', 'demo', '', '', '', '', ) provider1 = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', user=user, office_lat=0.0, office_longit=0.0) provider1.save() #input option first name searchFirstName = { 'email': '', 'fullname': 'tes', 'firstName': 'tes', 'lastName': '', 'username': '', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchFirstName) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1) #input option last name searchLastName = { 'email': '', 'fullname': '', 'firstName': '', 'lastName': 'meister', 'username': '', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchLastName) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1) #input option user name searchUsername = { 'email': '', 'fullname': '', 'firstName': '', 'lastName': '', 'username': '******', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchUsername) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1) #input option email searchEmail = { 'email': '*****@*****.**', 'fullname': '', 'firstName': 'tes', 'lastName': '', 'username': '', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchEmail) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1) pend = CallGroupMemberPending(from_user=self.user, to_user=provider1, practice=self.practice, call_group=self.call_group, created_time=datetime.datetime.now()) pend.save() searchLastName = { 'email': '', 'fullname': '', 'firstName': '', 'lastName': 'meister', 'username': '', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchLastName) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1) searchLastName = { 'email': '', 'fullname': '', 'firstName': '', 'lastName': '', 'username': '', 'call_group': self.call_group.id } response = self.client.post(reverse( 'MHLogin.MHLPractices.views_ajax.getProviderByEmailOrNameInCallGroup' ), data=searchLastName) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(len(msg), 1)
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_new_event(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() #get method response = self.client.get( reverse('MHLogin.MHLCallGroups.Scheduler.views.bulkNewEvents', 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 provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider.save() checkString = 'Ca69J2X6l8' newEventInvalidData = {'data': '[{"pk":null,"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.bulkNewEvents', args=(self.call_group.id, )), data=newEventInvalidData) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['error'][0], checkString + ', error saving new object') #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":null,"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.bulkNewEvents', 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.bulkNewEvents', args=(call_group2.id, )), data=newEventInvalidData) self.assertEqual(response.status_code, 403)
def test_redo(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() #403 call_group2 = CallGroup(description='test2', team='team') call_group2.save() response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.redo', args=(self.practice.id, call_group2.id))) self.assertEqual(response.status_code, 403) response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.redo', args=(self.practice.id, self.call_group.id))) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['count'], 0) #create a new event, and redo provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0, current_practice=self.practice) provider.save() provider.practices.add(self.practice) cgm = CallGroupMember(call_group=self.call_group, member=provider, alt_provider=1) cgm.save() checkString = 'Ca69J2X6l8' newEventInvalidData = {'data': '[{"pk":null,"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"}'} new_event = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.bulkNewEvents', args=(self.practice.id, self.call_group.id)), data=newEventInvalidData) response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.redo', args=(self.practice.id, self.call_group.id))) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg['undoSize'], 1) self.assertEqual(msg['redoSize'], 0) self.assertEqual(EventEntry.objects.count(), 1) #create a new and change event 1 time event = EventEntry.objects.get(checkString=checkString) #update updateEventInvalidData = {'data': '[{"pk":' + str(event.pk) + ',"model":"Scheduler.evententry","fields":{"oncallPerson":"' + str(provider.id) + '","eventType":"0","startDate":"2012-12-20 08:00:00",\ "endDate":"2012-12-21 08:00:00","eventStatus":1,"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=updateEventInvalidData) response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.views_multicallgroup.redo', args=(self.practice.id, self.call_group.id))) msg = json.loads(response.content) self.assertEqual(msg['redoSize'], 0) self.assertEqual(msg['undoSize'], 2) self.assertEqual(msg['operateList'], [])
def generate_users(request): if (not settings.DEBUG): return HttpResponseRedirect(reverse('MHLogin.Administration.views.home')) context = get_context(request) if (request.method == 'GET'): context["form"] = GenerateUsersForm() return render_to_response('qa_tools/genereate_users.html', context) else: form = GenerateUsersForm(request.POST) if form.is_valid(): current_practice = form.cleaned_data["practices"] user_type = int(form.cleaned_data["user_types"]) number = int(form.cleaned_data["number"]) user_name_start = form.cleaned_data["user_name_start"] generate_user = None for i in range(number): username = "******" % (user_name_start, i) first_name = "%s_f_%d" % (user_name_start, i) last_name = "%s_f_%d" % (user_name_start, i) email = "*****@*****.**" % (username) password = "******" if USER_TYPE_DOCTOR == user_type \ or USER_TYPE_NPPA == user_type \ or USER_TYPE_MEDICAL_STUDENT == user_type: provider = Provider( username=username, first_name=first_name, last_name=last_name, email=email, email_confirmed=True, lat=current_practice.practice_lat, longit=current_practice.practice_longit, address1=current_practice.practice_address1, address2=current_practice.practice_address2, city=current_practice.practice_city, state=current_practice.practice_state, zip=current_practice.practice_zip, current_practice=current_practice, is_active=1, office_lat=current_practice.practice_lat, office_longit=current_practice.practice_longit, mdcom_phone="8004664411" ) provider.save() provider.set_password(password) provider.practices.add(current_practice) provider.user_id = provider.pk provider.save() if USER_TYPE_DOCTOR == user_type: #Physician ph = Physician(user=provider) ph.save() elif USER_TYPE_NPPA == user_type: #NP/PA/Midwife np = NP_PA(user=provider) np.save() elif USER_TYPE_MEDICAL_STUDENT == user_type: ph = Physician(user=provider) ph.save() create_default_keys(provider.user, password) # Generating the user's voicemail box configuration config = VMBox_Config(pin='') config.owner = provider config.save() generate_user = provider elif USER_TYPE_OFFICE_MANAGER == user_type \ or USER_TYPE_NURSE == user_type \ or USER_TYPE_DIETICIAN == user_type: mhluser = MHLUser( username = username, first_name = first_name, last_name = last_name, email = email, email_confirmed = True, is_active = 1, address1 = current_practice.practice_address1, address2 = current_practice.practice_address2, city = current_practice.practice_city, state = current_practice.practice_state, zip = current_practice.practice_zip, lat = current_practice.practice_lat, longit = current_practice.practice_longit ) mhluser.save() mhluser.set_password(password) staff = OfficeStaff( user=mhluser, current_practice=current_practice ) staff.user = mhluser staff.current_practice = current_practice staff.save() staff.practices.add(current_practice) staff.save() if USER_TYPE_OFFICE_MANAGER == user_type: manager = Office_Manager(user=staff, practice=current_practice) manager.save() if USER_TYPE_NURSE == user_type: nurse = Nurse(user=staff) nurse.save() elif USER_TYPE_DIETICIAN == user_type: dietician = Dietician(user=staff) dietician.save() generate_user = mhluser log_str = 'Generate user %d: for %s' % (i, str(generate_user)) logger.debug(log_str) print log_str return render_to_response('qa_tools/genereate_users_success.html', context) else: context["form"] = form return render_to_response('qa_tools/genereate_users.html', context)
def _add_providers(self): for user in self.prov_data: self.pusr = None self.mhu = None self.prov = None pusr = Provider(username=user["username"], first_name=user["first_name"], last_name=user["last_name"]) pusr.is_active = pusr.is_staff = pusr.tos_accepted = True pusr.set_password("demo") pusr.address1 = user['addr1'] pusr.address2 = user['addr2'] pusr.city = user['city'] pusr.state = user['state'] pusr.zip = user['zipcode'] pusr.is_active = pusr.is_staff = pusr.tos_accepted = pusr.mobile_confirmed = pusr.email_confirmed = True pusr.phone = user['phone'] pusr.mobile_phone = user['mobile_phone'] pusr.skill = "" pusr.is_superuser = True pusr.office_address = user["office_address1"] pusr.office_address2 = "" pusr.office_phone = user["office_phone"] pusr.office_city = user["office_city"] pusr.office_state = user["office_state"] pusr.office_zip = user["office_zip"] pusr.forward_mobile = user["forward_mobile"] pusr.forward_office = user["forward_office"] pusr.forward_other = user["forward_other"] pusr.forward_vmail = user["forward_vmail"] pusr.forward_voicemail = user["forward_voicemail"] pusr.forward_anssvc = user["forward_anssvc"] pusr.mdcom_phone = user["mdcom_phone"] pusr.mdcom_phone_sid = user["mdcom_phone_sid"] pusr.status_verified = user["status_verified"] pusr.clinical_clerk = "" pusr.office_lat = 37.36876 pusr.office_longit = -122.081864 pusr.save() pusr.user = pusr user["id"] = pusr.id pusr.practices = user["practices"] pusr.save() vmbox = VMBox_Config(owner=pusr) vmbox.save() self.providers.append(pusr)
def test_sendNewProviderEmail(self): #user is a manager staff = OfficeStaff(user=self.user) staff.current_practice = self.practice staff.save() staff.practices.add(self.practice) #office staff call this method #get method response = self.client.get( reverse('MHLogin.MHLPractices.views_ajax.sendNewProviderEmail')) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual( msg['err'], _('A server error has occurred when you send a email. ' 'Please refresh page again.')) #invalid data data = {'userType': '33', 'msg': 'abc', 'recipient': '*****@*****.**'} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.sendNewProviderEmail'), data=data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual( msg['err']['userType'][0], 'Select a valid choice. 33 is not one ' 'of the available choices.') email = '*****@*****.**' provider1 = Provider(username='******', first_name='tes', last_name="meister", email=email, office_lat=0.0, office_longit=0.0) provider1.save() #invalid email data = {'userType': 1, 'msg': 'abc', 'recipient': email} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.sendNewProviderEmail'), data=data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual( msg['err'], _('This email address is already associated with a DoctorCom account.' )) #valid email and send a mail email = '*****@*****.**' data = {'userType': 2, 'msg': 'abc', 'recipient': email} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.sendNewProviderEmail'), data=data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg, 'ok') self.assertEqual(Invitation.objects.count(), 1) self.assertEqual(Invitation.objects.get(recipient=email).userType, 1) manager = Office_Manager(user=staff, practice=self.practice, manager_role=2) manager.save() #valid email and send a mail manager login email = '*****@*****.**' data = {'userType': 2, 'msg': 'abc', 'recipient': email} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.sendNewProviderEmail'), data=data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg, 'ok') self.assertEqual(Invitation.objects.count(), 2) self.assertEqual(Invitation.objects.get(recipient=email).userType, 1)
def test_page_user(self): request = generateHttpRequest() user_id = 0 #get method request.method = 'GET' result = page_user(request, user_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE002') #post method request.method = 'POST' #invlid form data request.POST['number'] = '' result = page_user(request, user_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE031') #valid form data request.POST['number'] = '12345' #not found user result = page_user(request, user_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE010') #user not a provider or an office staff user_id = create_mhluser() result = page_user(request, user_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE010') #a provider and has no pager Provider.objects.all().delete() provider = Provider(user=request.user, office_lat=0.0, office_longit=0.0) provider.save() result = page_user(request, provider.user.id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'TE002') #a provider and has pager Provider.objects.all().delete() provider = Provider(user=request.user, office_lat=0.0, office_longit=0.0, pager='8001234567') provider.save() result = page_user(request, provider.user.id) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data'], {}) #an office staff and has no pager staff = OfficeStaff(user=create_mhluser()) staff.save() result = page_user(request, staff.user.id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'TE002') #an office staff and has pager staff = OfficeStaff(user=create_mhluser(), pager='8001234567') staff.save() result = page_user(request, staff.user.id) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data'], {})
def test_checkProviderInCallGroup(self): staff = OfficeStaff(user=self.user) staff.save() staff.practices.add(self.practice) manager = Office_Manager(user=staff, practice=self.practice, manager_role=1) manager.save() #1 provider in practice provider = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider.save() dataProv = {'id': provider.id} response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.'\ 'views_multicallgroup.checkProviderInCallGroup', args=(self.practice.id, self.group.id)), data=dataProv) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, '"inpracitce"') #1 provider in 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.group, member=provider2, alt_provider=1) cgm.save() data2 = {'id': provider2.id} response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.'\ 'views_multicallgroup.checkProviderInCallGroup', args=(self.practice.id, self.group.id)), data=data2) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, '"member"') #1 provider in pending list provider3 = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider3.save() pending = CallGroupMemberPending(from_user=self.user, to_user=provider3, practice=self.practice, call_group=self.group, accept_status=0, created_time=datetime.datetime.now()) pending.save() data3 = {'id': provider3.id} response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.'\ 'views_multicallgroup.checkProviderInCallGroup', args=(self.practice.id, self.group.id)), data=data3) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, '"pending"') #1 provider not in practcie or call group practice2 = PracticeLocation(practice_name='teste', practice_longit='0.1', practice_lat='0.0',) practice2.save() provider4 = Provider(username='******', first_name='tes', last_name="meister", email='*****@*****.**', office_lat=0.0, office_longit=0.0) provider4.save() provider4.practices.add(practice2) data4 = {'id': provider4.id} response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.'\ 'views_multicallgroup.checkProviderInCallGroup', args=(self.practice.id, self.group.id)), data=data4) self.assertEqual(response.status_code, 200) self.assertEqual(response.content, '"ok"')
def test_page_user(self): request = generateHttpRequest() user_id = 0 #get method request.method = 'GET' result = page_user(request, user_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE002') #post method request.method = 'POST' #invlid form data request.POST['number'] = '' result = page_user(request, user_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE031') #valid form data request.POST['number'] = '12345' #not found user result = page_user(request, user_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE010') #user not a provider or an office staff user_id = create_mhluser() result = page_user(request, user_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE010') #a provider and has no pager Provider.objects.all().delete() provider = Provider(user=request.user, office_lat=0.0, office_longit=0.0) provider.save() result = page_user(request, provider.user.id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'TE002') #a provider and has pager Provider.objects.all().delete() provider = Provider(user=request.user, office_lat=0.0, office_longit=0.0, pager='8001234567') provider.save() result = page_user(request, provider.user.id) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data'], {}) #an office staff and has no pager staff = OfficeStaff(user=create_mhluser()) staff.save() result = page_user(request, staff.user.id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'TE002') #an office staff and has pager staff = OfficeStaff(user=create_mhluser(), pager='8001234567') staff.save() result = page_user(request, staff.user.id) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data'], {})
def generate_users(request): if (not settings.DEBUG): return HttpResponseRedirect( reverse('MHLogin.Administration.views.home')) context = get_context(request) if (request.method == 'GET'): context["form"] = GenerateUsersForm() return render_to_response('qa_tools/genereate_users.html', context) else: form = GenerateUsersForm(request.POST) if form.is_valid(): current_practice = form.cleaned_data["practices"] user_type = int(form.cleaned_data["user_types"]) number = int(form.cleaned_data["number"]) user_name_start = form.cleaned_data["user_name_start"] generate_user = None for i in range(number): username = "******" % (user_name_start, i) first_name = "%s_f_%d" % (user_name_start, i) last_name = "%s_f_%d" % (user_name_start, i) email = "*****@*****.**" % (username) password = "******" if USER_TYPE_DOCTOR == user_type \ or USER_TYPE_NPPA == user_type \ or USER_TYPE_MEDICAL_STUDENT == user_type: provider = Provider( username=username, first_name=first_name, last_name=last_name, email=email, email_confirmed=True, lat=current_practice.practice_lat, longit=current_practice.practice_longit, address1=current_practice.practice_address1, address2=current_practice.practice_address2, city=current_practice.practice_city, state=current_practice.practice_state, zip=current_practice.practice_zip, current_practice=current_practice, is_active=1, office_lat=current_practice.practice_lat, office_longit=current_practice.practice_longit, mdcom_phone="8004664411") provider.save() provider.set_password(password) provider.practices.add(current_practice) provider.user_id = provider.pk provider.save() if USER_TYPE_DOCTOR == user_type: #Physician ph = Physician(user=provider) ph.save() elif USER_TYPE_NPPA == user_type: #NP/PA/Midwife np = NP_PA(user=provider) np.save() elif USER_TYPE_MEDICAL_STUDENT == user_type: ph = Physician(user=provider) ph.save() create_default_keys(provider.user, password) # Generating the user's voicemail box configuration config = VMBox_Config(pin='') config.owner = provider config.save() generate_user = provider elif USER_TYPE_OFFICE_MANAGER == user_type \ or USER_TYPE_NURSE == user_type \ or USER_TYPE_DIETICIAN == user_type: mhluser = MHLUser( username=username, first_name=first_name, last_name=last_name, email=email, email_confirmed=True, is_active=1, address1=current_practice.practice_address1, address2=current_practice.practice_address2, city=current_practice.practice_city, state=current_practice.practice_state, zip=current_practice.practice_zip, lat=current_practice.practice_lat, longit=current_practice.practice_longit) mhluser.save() mhluser.set_password(password) staff = OfficeStaff(user=mhluser, current_practice=current_practice) staff.user = mhluser staff.current_practice = current_practice staff.save() staff.practices.add(current_practice) staff.save() if USER_TYPE_OFFICE_MANAGER == user_type: manager = Office_Manager(user=staff, practice=current_practice) manager.save() if USER_TYPE_NURSE == user_type: nurse = Nurse(user=staff) nurse.save() elif USER_TYPE_DIETICIAN == user_type: dietician = Dietician(user=staff) dietician.save() generate_user = mhluser log_str = 'Generate user %d: for %s' % (i, str(generate_user)) logger.debug(log_str) print log_str return render_to_response('qa_tools/genereate_users_success.html', context) else: context["form"] = form return render_to_response('qa_tools/genereate_users.html', context)
def testUpdateRefer(self): provider = Provider(username="******", first_name="upre", last_name="test", office_lat=0.0, office_longit=0.0) provider.set_password("maestro") provider.save() provider2 = Provider(username="******", first_name="doc", last_name="holiday", office_lat=0.0, office_longit=0.0) provider2.set_password("holiday") provider2.save() sender = provider msg = Message(sender=sender, sender_site=None, subject="pandas") msg.urgent = False msg.message_type = 'NM' msg.callback_number = '2561234561' msg.save() body = "i am indeed a talking panda. how are you?" msg_body = MessageBody(message=msg, body=body) msg_body.save() refer = MessageRefer() refer.message = msg refer.first_name = 'msg' refer.middle_name = 'refer' refer.last_name = 'again' refer.gender = 'M' refer.status = 'NO' refer.phone_number = 8529631475 refer.alternative_phone_number = 1472583695 refer.save() msgRe = MessageRecipient() msgRe.message = msg msgRe.user = provider2 msgRe.save() generate_keys_for_users(output=DevNull()) VMBox_Config(owner=provider).save() VMBox_Config(owner=provider2).save() response = self.client.get(reverse( 'MHLogin.api.v1.views_messaging.updateRefer', args=(refer.uuid,)), **self.extra) self.assertEqual(response.content, err_GE002().content, response.status_code) response = self.client.post(reverse( 'MHLogin.api.v1.views_messaging.updateRefer', args=(refer.uuid,)), \ data={'status': 'NO'}, **self.extra) self.assertEqual(response.status_code, 200, response.status_code) m = json.loads(response.content) self.assertEqual(len(m), 2)
def test_get_all_providers_and_staffs(self): request = generateHttpRequest() #get method request.method = 'GET' result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE002') #post method request.method = 'POST' #find 0 any type user result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['users']), 0) #has 1 nppa user = create_user('np1', 'abc', '', 'demo') provider = Provider(user=user, username='******', first_name='abc', last_name='', office_lat=0.0, office_longit=0.0) provider.save() nppa = NP_PA(user=provider) nppa.save() request.POST['name'] = unicode('abc') result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['users']), 1) self.assertEqual(msg['users'][0]['first_name'], 'abc') phy = Physician(user=provider) phy.save() result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['users']), 2) self.assertEqual(msg['users'][0]['first_name'], 'abc') #staff organization_type = create_org_type() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0', mdcom_phone='8005550085', organization_type=organization_type) practice.save() staff = OfficeStaff(user=request.user, current_practice=practice) staff.save() staff.practices.add(practice) request.POST['name'] = unicode(request.user.first_name) result = get_all_providers_and_staffs(request) self.assertEqual(result.status_code, 200) self.assertEqual(len(msg['users']), 2) self.assertEqual(msg['users'][0]['first_name'], 'abc')