def test_getLevelByStaff(self): practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit= -122.081864) practice.save() user = create_user('practicemgr1', 'lin', 'xing', 'demo') #not a manager login result = get_level_by_staff(user, practice) self.assertEqual(result, 0) staff = OfficeStaff(user=user) staff.save() manager = Office_Manager(user=staff, practice=practice, manager_role=2) manager.save() #a manager login result = get_level_by_staff(staff.id, practice) self.assertEqual(result, 2)
def test_local_office(self): request = generateHttpRequest() #a provider call this method result = local_office(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['practices']), 0) #a office manager login but has not current practice organization_type = create_org_type() practice = ct_practice('name', organization_type) staff = OfficeStaff(user=request.user) staff.save() manager = Office_Manager(user=staff, practice=practice, manager_role=2) manager.save() assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 100 assn.save(request) result = local_office(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['practices']), 0) #a office manager login and has current practice staff.current_practice = practice result = local_office(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['practices']), 0)
def test_canAccessCallGroup(self): call_group = CallGroup(description='test', team='team') call_group.save() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0', call_group=call_group) practice.save() practice.call_groups.add(call_group) user = create_user('user-CallGroup2', 'us', 'er', 'demo') staff = OfficeStaff(user=user) staff.save() staff.practices.add(practice) #a staff call this method result = canAccessCallGroup(staff, long(call_group.pk)) self.assertEqual(result, False) #a manager call this method # manager = Office_Manager(user=staff, practice=practice, manager_role=1) # manager.save() # # result = canAccessCallGroup(manager, long(call_group.pk)) # self.assertEqual(result, True) #admin call this method admin = create_user('user-CallGroup', 'us', 'er', 'demo', '', '', '', '', Administrator) result = canAccessCallGroup(admin.user, call_group) self.assertEqual(result, True) Administrator.objects.all().delete()
def test_practice_info(self): organization_type = create_org_type() practice = ct_practice('name', organization_type) request = generateHttpRequest() #a provider login result = practice_info(request, practice.id) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data']['id'], practice.id) #a staff login staff = OfficeStaff(user=request.user) staff.save() manager = Office_Manager(user=staff, practice=practice, manager_role=2) manager.save() assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 100 assn.save(request) #invalid practice result = practice_info(request, 0) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'PF003') #valid practice result = practice_info(request, practice.id) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data']['id'], practice.id)
def test_checkoutUserManager(self): practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.save() user = create_user('staff', 'lin', 'xing', 'demo', '', '', '', '',) staff = OfficeStaff(user=user) staff.save() staff.practices.add(practice) provider = Provider.objects.create(username='******', first_name='heal', last_name='meister', address1="555 Bryant St.", city="Palo Alto", state="CA", lat=0.0, longit=0.0, office_lat=0.0, office_longit=0.0, is_active=True, tos_accepted=True, mobile_confirmed=True, mdcom_phone='123', mobile_phone='456') provider.user = provider # for our unique prov-user reln provider.save() # try provider result = user_is_mgr_of_practice(provider, practice) self.assertEqual(False, result) # try just staff result = user_is_mgr_of_practice(staff.user, practice) self.assertEqual(False, result) # now office manager (make staff an OM) om = Office_Manager.objects.create(user=staff, practice=practice, manager_role=1) result = user_is_mgr_of_practice(om.user.user, practice) self.assertEqual(True, result) result = user_is_mgr_of_practice(staff.user, practice) self.assertEqual(True, result)
def test_isCallGroupStaff(self): call_group = CallGroup(description='test', team='team') call_group.save() practice = PracticeLocation(practice_name='test', practice_longit='0.1', practice_lat='0.0',) practice.call_group = call_group practice.save() user = create_user('user5', 'us', 'er', 'demo') #a mhluser call this method result = isCallGroupStaff(user, call_group.pk) self.assertEqual(result, False) staff = OfficeStaff(user=user) staff.save() staff.practices.add(practice) #a staff call this method result = isCallGroupStaff(user, call_group.pk) self.assertEqual(result, True) #a manager call this method manager = Office_Manager(user=staff, practice=practice, manager_role=1) manager.save() result = isCallGroupStaff(user, call_group.pk) self.assertEqual(result, True)
def test_cancel_invite(self): invitation_id = 0 email = '*****@*****.**' request = generateHttpRequest() #an office staff login staff = OfficeStaff(user=request.user) staff.save() assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) result = cancel_invite(request, invitation_id) self.assertEqual(result.status_code, 403) #a provider login assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 1 assn.save(request) #404 not found invitation try: cancel_invite(request, invitation_id) except Http404: self.assertRaises(Http404()) code = 'abcdefg' usertype = 1 invite = Invitation(code=code, sender=request.user, recipient=email, userType=usertype) invite.save() result = cancel_invite(request, invite.pk) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data'], {}) self.assertEqual(Invitation.objects.count(), 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_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_display_scheduler_403(self): data403 = {} staff = OfficeStaff(user=self.user) staff.save() response = self.client.get(reverse('MHLogin.MHLCallGroups.Scheduler.views.display_scheduler', args=(self.call_group.id,)), data=data403) self.assertEqual(response.status_code, 403)
def test_community_providers(self): request = generateHttpRequest() #find 0 provider result = community_providers(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 0) #find 1 provider phy = Physician(user=request.provider) phy.save() result = community_providers(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 1) organization_type = create_org_type() practice = ct_practice('name', organization_type) assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 100 assn.save(request) staff = OfficeStaff(user=request.user, current_practice=practice) staff.save() result = community_providers(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 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_resend_invite(self): email = '*****@*****.**' invitation_id = 0 request = generateHttpRequest() #get method request.method = 'GET' result = resend_invite(request, invitation_id) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE002') #post method request.method = 'POST' #an office staff login staff = OfficeStaff(user=request.user) staff.save() assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) result = resend_invite(request, invitation_id) self.assertEqual(result.status_code, 403) #a provider login assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 1 assn.save(request) #invalid invitation id note = 'test' request.POST['note'] = note try: resend_invite(request, invitation_id) except Http404: self.assertRaises(Http404()) usertype = 1 #another email errEmail = '*****@*****.**' code = '12345' invite = Invitation(code=code, sender=request.user, recipient=errEmail, userType=usertype) invite.save() result = resend_invite(request, invite.pk) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data']['id'], invite.id) #use time setting request.POST['use_time_setting'] = True errEmail = '*****@*****.**' code = '12wsxs' invite = Invitation(code=code, sender=request.user, recipient=errEmail, userType=usertype) invite.save() result = resend_invite(request, invite.pk) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data']['id'], invite.id)
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 test_display_scheduler_403(self): staff = OfficeStaff(user=self.user) staff.save() staff.practices.add(self.practice) data403 = {} response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.'\ 'views_multicallgroup.display_scheduler', args=(self.practice.id, self.group.id)), data=data403) self.assertEqual(response.status_code, 403)
def done(self, request, form_list): inviteform = form_list[0] userform = form_list[1] invite = Invitation.objects.get(code=inviteform.cleaned_data['code'], userType=100) if len(form_list) > 2: practiceform = form_list[2] practice = practiceform.save(commit=False) practice.practice_lat = practiceform.cleaned_data['practice_lat'] practice.practice_longit = practiceform.cleaned_data['practice_longit'] practice.organization_type_id = RESERVED_ORGANIZATION_TYPE_ID_PRACTICE callgroup = CallGroup(description=practiceform.cleaned_data['practice_name']) callgroup.save() practice.call_group = callgroup practice.save() org_relation = OrganizationRelationship(organization=practice, parent_id=RESERVED_ORGANIZATION_ID_DOCTORCOM, create_time=time.time()) org_relation.save() manager_role = 2 else: practice = invite.assignPractice manager_role = 1 user = userform.save(commit=False) user.set_password(userform.cleaned_data['password1']) # use mhluser's address1, address2, city, state, zip to store "address" information, user.address1 = practice.practice_address1 user.address2 = practice.practice_address2 user.city = practice.practice_city user.state = practice.practice_state user.zip = practice.practice_zip user.lat = practice.practice_lat user.longit = practice.practice_longit user.tos_accepted = True if invite.recipient == request.POST['email']: user.email_confirmed = True user.save() staff = OfficeStaff(user=user, current_practice=practice) staff.save() staff.practices.add(practice) manager = Office_Manager(user=staff, practice=practice, manager_role=manager_role) manager.save() # TESTING_KMS_INTEGRATION create_default_keys(user, userform.cleaned_data['password1']) # Remove the invitation. invite.delete(createdUser=user, createdPractice=practice, send_notice=False) msg = render_to_string('MHLSignup/practice_notification_email.txt', {'practice_name': practice.practice_name, 'practice_id': practice.id, 'timestamp': datetime.datetime.now().strftime("%I:%M %m/%d/%Y")}) send_mail("new practice created", msg, '*****@*****.**', ["*****@*****.**"]) return HttpResponseRedirect(self.redirect_url)
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_display_scheduler_emptydata(self): dataEmpty = {} 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() response = self.client.get(reverse('MHLogin.MHLCallGroups.Scheduler.views.display_scheduler', args=(self.call_group.id,)), data=dataEmpty) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'schedule.html') self.assertEqual(-1, response.content.find('fc-event-inner')) # event tag
def test_isMultiCallGroupManager(self): #init practice and call group 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() practice.call_groups.add(call_group) user = create_user('user1', 'us', 'er', 'demo') #only mhluser call method result = isMultiCallGroupManager(user, practice.id, call_group.id) self.assertEqual(result, False) #staff call method staff = OfficeStaff(user=user) staff.save() result = isMultiCallGroupManager(user, call_group.id, practice.id) self.assertEqual(result, False) practice2 = PracticeLocation(practice_name='test2', practice_longit='0.1', practice_lat='0.0',) practice2.save() practice2.call_groups.add(call_group) #manager call method staff.practices.add(practice) staff.save() manager = Office_Manager(user=staff, practice=practice, manager_role=1) manager.save() result = isMultiCallGroupManager(user, call_group.id, practice.id) self.assertEqual(result, True) #manager with specialty call method specialty_name = 'Specialty A' specialty1 = Specialty() specialty1.name = specialty_name specialty1.practice_location = practice specialty1.number_selection = 3 specialty1.save() specialty1.call_groups.add(call_group) manager2 = Office_Manager(user=staff, practice=practice2, manager_role=1) manager2.save() result = isMultiCallGroupManager(user, call_group.id, practice.id) self.assertEqual(result, True)
def test_user_update_photo(self): request = generateHttpRequest() #get method request.method = 'GET' result = user_update_photo(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE002') #post method request.method = 'POST' #provider login and has no photo result = user_update_photo(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual( msg['photo'], ''.join([settings.MEDIA_URL, 'images/photos/avatar2.png'])) #staff login and has no photo staff = OfficeStaff(user=request.user) staff.save() assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) result = user_update_photo(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual( msg['photo'], ''.join([settings.MEDIA_URL, 'images/photos/staff_icon.jpg'])) #nurse login and has no photo nurse = Nurse(user=staff) nurse.save() result = user_update_photo(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual( msg['photo'], ''.join([settings.MEDIA_URL, 'images/photos/nurse.jpg'])) #user has photo, and new photo == old photo mhluser = MHLUser.objects.get(id=request.user.id) mhluser.photo = 'a.png' mhluser.save() result = user_update_photo(request) self.assertEqual(result.status_code, 200)
def test_staffHome(self): 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() response = self.client.post( reverse('MHLogin.MHLPractices.views.staffHome')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'Staff/staffHome.html')
def test_can_user_manage_this_org(self): user = create_user(get_random_username(), 'yang', 'peng', 'demo') admin = Administrator(user=user) admin.save() self.assertTrue( can_user_manage_this_org(self.organization.id, admin.user.id)["can_manage_org"]) self.user = create_user(get_random_username(), 'yang', 'peng', 'demo') staff = OfficeStaff() staff.user = self.user staff.office_lat = 0.0 staff.office_longit = 0.0 staff.current_practice = self.organization staff.save() staff.practices.add(self.organization) self.assertFalse( can_user_manage_this_org(self.organization.id, staff.user.id)["can_manage_org"]) Office_Manager.objects.create(user=staff, practice=self.organization, manager_role=1) self.assertTrue( can_user_manage_this_org(self.organization.id, staff.user.id)["can_manage_org"])
def test_display_scheduler_session(self): dataEmpty = {} 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() self.client.session[SessionHelper.CURRENT_CALLGROUP_ID] = self.group.id self.client.session.save() response = self.client.get(reverse('MHLogin.MHLCallGroups.Scheduler.'\ 'views_multicallgroup.display_scheduler', args=(self.practice.id, 0)), data=dataEmpty) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'schedule_multicallgroup.html')
def setUp(self): clean_db_datas() self.user = create_user(get_random_username(), 'yang', 'peng', 'demo') self.organization = create_organization() self.parent_organization = create_parent_organization() self.organization.save_parent_org(parent_org=self.parent_organization) staff = OfficeStaff() staff.user = self.user staff.office_lat = 0.0 staff.office_longit = 0.0 staff.current_practice = self.organization staff.save() staff.practices.add(self.organization) mgr = Office_Manager(user=staff, practice=self.organization, manager_role=2) mgr.save() self.provider = create_user(get_random_username(), "doc", "holiday", "demo", uklass=Provider) self.provider.current_practice = self.parent_organization self.provider.save() self.provider.practices.add(self.parent_organization)
def test_display_scheduler_403_group(self): dataEmpty = {} 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() group = CallGroup(description='test', team='team') group.save() response = self.client.post(reverse('MHLogin.MHLCallGroups.Scheduler.'\ 'views_multicallgroup.display_scheduler', args=(self.practice.id, group.id)), data=dataEmpty) self.assertEqual(response.status_code, 403)
def test_associate_staff(self): staff = OfficeStaff(user=self.user) staff.save() self.user = staff self.user.save() staffData = {'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=staffData) self.assertEqual(response.status_code, 400) msg = json.loads(response.content) self.assertEqual(msg['errno'], 'DM002')
def test_practice_profile_edit_manager(self): 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=1) manager.save() response = self.client.get( reverse('MHLogin.MHLPractices.views.practice_profile_edit')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'Profile/practice_profile_edit.html')
def test_associate_manager(self): staff2 = OfficeStaff(user=self.user, current_practice=self.practice) staff2.save() manager = Office_Manager(user=staff2, practice=self.practice, manager_role=2) manager.save() self.user = manager self.user.save() staff2Data = {'username': self.user.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=staff2Data) self.assertEqual(response.status_code, 200)
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_site_students(self): request = generateHttpRequest() staff = OfficeStaff(user=request.user) staff.save() #provider not staff assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) result = site_students(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'DM020') #get back provider and has no current site assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 1 assn.save(request) result = site_students(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 0) #provider has current site site = Site(name='test site', address1='test address', lat=0.0, longit=0.1) site.save() request.provider.current_site = site request.provider.save() result = site_students(request) self.assertEqual(result.status_code, 200) self.assertEqual(len(msg['data']['users']), 0) #Physician has current site request.provider.sites.add(site) request.provider.clinical_clerk = True request.provider.save() phy = Physician(user=request.provider) phy.save() result = site_students(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 1)
def test_display_scheduler_nopractice(self): dataEmpty = {} 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() practice2 = PracticeLocation(practice_name='test2', practice_longit='0.1', practice_lat='0.0',) practice2.save() manager.practice = practice2 manager.save() response = self.client.get(reverse('MHLogin.MHLCallGroups.Scheduler.'\ 'views_multicallgroup.display_scheduler', args=(practice2.id, 0)), data=dataEmpty) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'error_multicallgroup.html')
def done(self, request, form_list): inviteform = form_list[0] userform = form_list[1] user = userform.save(commit=False) user.set_password(userform.cleaned_data['password1']) user.tos_accepted = True invite = Invitation.objects.get(code=inviteform.cleaned_data['code'], userType=101) if invite.recipient == request.POST['email']: user.email_confirmed = True user.email = request.POST['email'] assignPractice = invite.assignPractice if assignPractice: # use mhluser's address1, address2, city, state, zip to store "address" information, user.address1 = assignPractice.practice_address1 user.address2 = assignPractice.practice_address2 user.city = assignPractice.practice_city user.state = assignPractice.practice_state user.zip = assignPractice.practice_zip user.lat = assignPractice.practice_lat user.longit = assignPractice.practice_longit user.save() staff = OfficeStaff(user=user, current_practice=assignPractice) staff.save() staff.practices.add(assignPractice) userType = request.POST['userType'] if userType == '3': nurse = Nurse(user=staff) nurse.save() if userType == '4': dietician = Dietician(user=staff) dietician.save() # TESTING_KMS_INTEGRATION create_default_keys(user, userform.cleaned_data['password1']) # Remove the invitation. invite = Invitation.objects.get(code=inviteform.cleaned_data['code'], userType=101) invite.delete(createdUser=user, send_notice=False) return HttpResponseRedirect(self.redirect_url)
def test_site_staff(self): request = generateHttpRequest() staff = OfficeStaff(user=request.user) staff.save() assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) #staff has not current site result = site_staff(request) self.assertEqual(result.status_code, 200) current_site = Site(name='test site', address1='test address', lat=0.0, longit=0.1) current_site.save() staff.current_site = current_site staff.save() #staff has current site result = site_staff(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 0) #return_python == true result = site_staff(request, True) msg = result['data']['users'] self.assertEqual(len(msg), 0)
def test_practice_main_view(self): #403 # response = self.client.post(reverse('MHLogin.MHLPractices.views.practice_main_view')) # self.assertEqual(response.status_code, 403) staff = OfficeStaff(user=self.user) staff.save() staff.practices.add(self.practice) #staff no current practice response = self.client.post( reverse('MHLogin.MHLPractices.views.practice_main_view')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'dashboard_office_staff.html') #staff and current practice staff.current_practice = self.practice staff.save() response = self.client.post( reverse('MHLogin.MHLPractices.views.practice_main_view')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'dashboard_office_staff.html') #manger manager = Office_Manager(user=staff, practice=self.practice, manager_role=2) manager.save() response = self.client.post( reverse('MHLogin.MHLPractices.views.practice_main_view')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'dashboard_office_manager.html') #manager and current site site = Site(name='test site', address1='test address', lat='0.4', longit='4.1') staff.current_site = site staff.save() response = self.client.post( reverse('MHLogin.MHLPractices.views.practice_main_view')) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'dashboard_office_manager.html')
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) mgr = Office_Manager(user=staff, practice=practice, manager_role=2) mgr.save()
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 setUp(self): clean_db_datas() org_setting = OrganizationSetting() org_setting.save() org_type = OrganizationType(name="Test Org Type", organization_setting=org_setting, is_public=True) org_type.save() self.org = create_organization() for i in range(10): user_name = "".join(["Staff1_", str(i)]) first_name = "".join(["Test1_", str(i)]) user = create_user(user_name, first_name, 'S', 'demo') self.staff = OfficeStaff() self.staff.user = user self.staff.office_lat = 0.0 self.staff.office_longit = 0.0 self.staff.save() self.org_staff.append(self.staff) # IntegrityError: column username is not unique # provider_name = "".join(["Pravider1_", str(i)]) # pro = create_user(provider_name, 'Provider', 'P', 'demo', uklass=Provider) # self.org_providers.append(pro) self.user = create_user(get_random_username(), 'staff', 'S', 'demo') staff = OfficeStaff() staff.user = self.user staff.office_lat = 0.0 staff.office_longit = 0.0 staff.save() self.staff = staff self.provider = create_user("Pravider2", 'Provider', 'P', 'demo', uklass=Provider) self.provider.save()
def test_associate_staff(self): staff = OfficeStaff(user=self.user) staff.save() self.user = staff self.user.save() staffData = { '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=staffData) self.assertEqual(response.status_code, 400) msg = json.loads(response.content) self.assertEqual(msg['errno'], 'DM002')
def test_display_scheduler_emptydata(self): dataEmpty = {} 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() response = self.client.get(reverse( 'MHLogin.MHLCallGroups.Scheduler.views.display_scheduler', args=(self.call_group.id, )), data=dataEmpty) self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'schedule.html') self.assertEqual(-1, response.content.find('fc-event-inner')) # event tag
def setUp(self): clean_db_datas() self.temp_CALL_ENABLE = settings.CALL_ENABLE self.temp_SEND_MAXIMUM_PER_DAY = settings.SEND_MAXIMUM_PER_DAY self.temp_SEND_CODE_WAITING_TIME = settings.SEND_CODE_WAITING_TIME self.temp_FAIL_VALIDATE_MAXIMUM_PER_HOUR = settings.FAIL_VALIDATE_MAXIMUM_PER_HOUR self.temp_VALIDATE_LOCK_TIMEE = settings.VALIDATE_LOCK_TIME settings.SEND_MAXIMUM_PER_DAY = 5 settings.SEND_CODE_WAITING_TIME = 2 settings.FAIL_VALIDATE_MAXIMUM_PER_HOUR = 3 settings.VALIDATE_LOCK_TIME = 2 self.provider = create_user(get_random_username(), "yang", "peng", "demo", uklass=Provider) self.provider.mobile_phone = '9563322588' self.provider.mobile_confirmed = True self.provider.email = '*****@*****.**' self.provider.email_confirmed = True self.provider.save() self.organization = create_organization() self.user = create_user(get_random_username(), "yang", "peng", "demo") staff = OfficeStaff() staff.user = self.user staff.pager = '9985622456' staff.office_lat = 0.0 staff.office_longit = 0.0 staff.current_practice = self.organization staff.save() self.staff = staff self.user_bro = create_user(get_random_username(), "yang", "peng", "demo") self.broker = Broker() self.broker.pager = '9985622456' self.broker.user = self.user_bro self.broker.office_lat = 0.0 self.broker.office_longit = 0.0 self.broker.save() self.user = create_user(get_random_username(), "yang", "peng", "demo") self.user.mobile_phone = '9563322488' self.user.mobile_confirmed = True self.user.email_confirmed = True self.user.save()
def done(self, request, form_list): inviteform = form_list[0] userform = form_list[1] user = userform.save(commit=False) user.set_password(userform.cleaned_data['password1']) user.tos_accepted = True invite = Invitation.objects.get(code=inviteform.cleaned_data['code'], userType=101) if invite.recipient == request.POST['email']: user.email_confirmed = True user.email = request.POST['email'] assignPractice = invite.assignPractice if assignPractice: # use mhluser's address1, address2, city, state, zip to store "address" information, user.address1 = assignPractice.practice_address1 user.address2 = assignPractice.practice_address2 user.city = assignPractice.practice_city user.state = assignPractice.practice_state user.zip = assignPractice.practice_zip user.lat = assignPractice.practice_lat user.longit = assignPractice.practice_longit user.save() staff = OfficeStaff(user=user, current_practice=assignPractice) staff.save() staff.practices.add(assignPractice) userType = request.POST['userType'] if userType == '3': nurse = Nurse(user=staff) nurse.save() if userType == '4': dietician = Dietician(user=staff) dietician.save() # TESTING_KMS_INTEGRATION create_default_keys(user, userform.cleaned_data['password1']) # Remove the invitation. invite = Invitation.objects.get(code=inviteform.cleaned_data['code'], userType=101) invite.delete(createdUser=user, send_notice=False) return HttpResponseRedirect(self.redirect_url)
def test_user_update_photo(self): request = generateHttpRequest() #get method request.method = 'GET' result = user_update_photo(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE002') #post method request.method = 'POST' #provider login and has no photo result = user_update_photo(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['photo'], ''.join([settings.MEDIA_URL, 'images/photos/avatar2.png'])) #staff login and has no photo staff = OfficeStaff(user=request.user) staff.save() assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) result = user_update_photo(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['photo'], ''.join([settings.MEDIA_URL, 'images/photos/staff_icon.jpg'])) #nurse login and has no photo nurse = Nurse(user=staff) nurse.save() result = user_update_photo(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['photo'], ''.join([settings.MEDIA_URL, 'images/photos/nurse.jpg'])) #user has photo, and new photo == old photo mhluser = MHLUser.objects.get(id=request.user.id) mhluser.photo = 'a.png' mhluser.save() result = user_update_photo(request) self.assertEqual(result.status_code, 200)
def test_cancelExistInvitation(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() #get method response = self.client.get( reverse('MHLogin.MHLPractices.views_ajax.cancelExistInvitation')) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg[1], _('A server error has occured.')) email = '*****@*****.**' user_type = 1 invite = Invitation(sender=self.user, recipient=email, assignPractice=self.practice, userType=user_type) invite.save() #there is no invite find data = {'email': '*****@*****.**', 'type': '0'} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.cancelExistInvitation'), data=data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg[1], _('A server error has occured.')) data = {'email': email, 'type': user_type} response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.cancelExistInvitation'), data=data) self.assertEqual(response.status_code, 200) msg = json.loads(response.content) self.assertEqual(msg[0], 'ok') self.assertEqual(Invitation.objects.count(), 0)
def test_practice_mgmt(self, start_thread): request = generateHttpRequest() #get method and provider request.method = 'GET' result = practice_mgmt(request) self.assertEqual(result.status_code, 200) #get method and staff staff = OfficeStaff(user=request.user) staff.save() assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 100 assn.save(request) result = practice_mgmt(request) self.assertEqual(result.status_code, 200) #post method and no practice request.method = 'POST' result = practice_mgmt(request) self.assertEqual(result.status_code, 400) #post method and have practice but not manager organization_type = create_org_type() practice = ct_practice('name', organization_type) request.POST['current_practice'] = practice.id result = practice_mgmt(request) self.assertEqual(result.status_code, 200) #post method and staff can not change current practice assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) result = practice_mgmt(request) self.assertEqual(result.status_code, 403) #post method and can change current practice assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 1 assn.save(request) request.provider.practices.add(practice) result = practice_mgmt(request) self.assertEqual(result.status_code, 200)
def test_site_students(self): request = generateHttpRequest() staff = OfficeStaff(user=request.user) staff.save() #provider not staff assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) result = site_students(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'DM020') #get back provider and has no current site assn = SmartPhoneAssn.all_objects.get(device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 1 assn.save(request) result = site_students(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 0) #provider has current site site = Site(name='test site', address1='test address', lat=0.0, longit=0.1) site.save() request.provider.current_site = site request.provider.save() result = site_students(request) self.assertEqual(result.status_code, 200) self.assertEqual(len(msg['data']['users']), 0) #Physician has current site request.provider.sites.add(site) request.provider.clinical_clerk = True request.provider.save() phy = Physician(user=request.provider) phy.save() result = site_students(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['users']), 1)
def test_views_invites(self): request = generateHttpRequest() #an office staff login staff = OfficeStaff(user=request.user) staff.save() assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) result = list_invites(request) self.assertEqual(result.status_code, 403) #a provider login assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 1 assn.save(request) #find 0 invitation result = list_invites(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['invitations']), 0) usertype = 1 #invite has assignPractice organization_type = create_org_type() practice = ct_practice('name', organization_type) code = '12345' email = '*****@*****.**' invite = Invitation(code=code, sender=request.user, recipient=email, userType=usertype, assignPractice=practice) invite.save() result = list_invites(request) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(len(msg['data']['invitations']), 1)
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 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_associate_manager(self): staff2 = OfficeStaff(user=self.user, current_practice=self.practice) staff2.save() manager = Office_Manager(user=staff2, practice=self.practice, manager_role=2) manager.save() self.user = manager self.user.save() staff2Data = { 'username': self.user.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=staff2Data) self.assertEqual(response.status_code, 200)
def test_update_mobile_phone(self): request = generateHttpRequest() staff = OfficeStaff(user=request.user) staff.save() #get method request.method = 'GET' result = update_mobile_phone(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE002') #post method request.method = 'POST' #invalid mobile phone number request.POST['mobile_phone'] = '1236' result = update_mobile_phone(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'GE031') #valid mobile phone number but someone has been used temp = settings.CALL_ENABLE settings.CALL_ENABLE = False mobile_phone = '8005550094' user = MHLUser(mobile_phone=mobile_phone, username='******', first_name='sa', last_name='as', password='******') user.save() request.POST['mobile_phone'] = mobile_phone result = update_mobile_phone(request) self.assertEqual(result.status_code, 400) msg = json.loads(result.content) self.assertEqual(msg['errno'], 'AM020') #valid mobile phone number and nobody use it mobile_phone2 = '8007750094' request.POST['mobile_phone'] = mobile_phone2 result = update_mobile_phone(request) self.assertEqual(result.status_code, 200) settings.CALL_ENABLE = temp
def test_practice_profile_edit_staff(self): staff = OfficeStaff(user=self.user) staff.current_practice = self.practice staff.save() staff.practices.add(self.practice) staff.save() response = self.client.post( reverse('MHLogin.MHLPractices.views.practice_profile_edit')) self.assertEqual(response.status_code, 403)
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_cancel_invite(self): invitation_id = 0 email = '*****@*****.**' request = generateHttpRequest() #an office staff login staff = OfficeStaff(user=request.user) staff.save() assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 101 assn.save(request) result = cancel_invite(request, invitation_id) self.assertEqual(result.status_code, 403) #a provider login assn = SmartPhoneAssn.all_objects.get( device_id=request.REQUEST['DCOM_DEVICE_ID']) assn.user_type = 1 assn.save(request) #404 not found invitation try: cancel_invite(request, invitation_id) except Http404: self.assertRaises(Http404()) code = 'abcdefg' usertype = 1 invite = Invitation(code=code, sender=request.user, recipient=email, userType=usertype) invite.save() result = cancel_invite(request, invite.pk) self.assertEqual(result.status_code, 200) msg = json.loads(result.content) self.assertEqual(msg['data'], {}) self.assertEqual(Invitation.objects.count(), 0)
def test_removeProvider(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() #practice has no call group response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.removeProvider')) self.assertEqual(response.status_code, 200) #practice has call group self.practice.call_group = self.call_group self.practice.save() response = self.client.post( reverse('MHLogin.MHLPractices.views_ajax.removeProvider')) self.assertEqual(response.status_code, 200)
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_getPrintableSchedule(self): #not a staff login and call this method #a staff login staff = OfficeStaff(user=self.user) staff.save() staff.practices.add(self.practice) staff.current_practice = self.practice staff.save() response = self.client.post( reverse( 'MHLogin.MHLCallGroups.Scheduler.views.getPrintableSchedule')) 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 test_isMultiCallGroupManager(self): #init practice and call group 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() practice.call_groups.add(call_group) user = create_user('user1', 'us', 'er', 'demo') #only mhluser call method result = isMultiCallGroupManager(user, practice.id, call_group.id) self.assertEqual(result, False) #staff call method staff = OfficeStaff(user=user) staff.save() result = isMultiCallGroupManager(user, call_group.id, practice.id) self.assertEqual(result, False) practice2 = PracticeLocation( practice_name='test2', practice_longit='0.1', practice_lat='0.0', ) practice2.save() practice2.call_groups.add(call_group) #manager call method staff.practices.add(practice) staff.save() manager = Office_Manager(user=staff, practice=practice, manager_role=1) manager.save() result = isMultiCallGroupManager(user, call_group.id, practice.id) self.assertEqual(result, True) #manager with specialty call method specialty_name = 'Specialty A' specialty1 = Specialty() specialty1.name = specialty_name specialty1.practice_location = practice specialty1.number_selection = 3 specialty1.save() specialty1.call_groups.add(call_group) manager2 = Office_Manager(user=staff, practice=practice2, manager_role=1) manager2.save() result = isMultiCallGroupManager(user, call_group.id, practice.id) self.assertEqual(result, True)
def test_changeCurrentPracticeForStaff(self, start_thread): practice = PracticeLocation( practice_address1='555 Pleasant Pioneer Grove', practice_address2='Trailer Q615', practice_city='Mountain View', practice_state='CA', practice_zip='94040-4104', practice_lat=37.36876, practice_longit=-122.081864) practice.save() user = create_user('practicemgr1', 'lin', 'xing', 'demo') staff = OfficeStaff(user=user) staff.save() result = changeCurrentPracticeForStaff(practice.id, user.pk) self.assertEqual(result, practice) try: changeCurrentPracticeForStaff(0, user.pk) except: PracticeLocation.DoesNotExist try: result = changeCurrentPracticeForStaff(practice.id, 0) except: MHLUser.DoesNotExist
def setUp(self): clean_db_datas() org_setting = OrganizationSetting() org_setting.save() org_type = OrganizationType(name="Test Org Type", organization_setting=org_setting, is_public=True) org_type.save() self.org = create_organization() for i in range(10): user_name = "".join(["Staff1_", str(i)]) first_name = "".join(["Test1_", str(i)]) user = create_user(user_name, first_name, 'S', 'demo') self.staff = OfficeStaff() self.staff.user = user self.staff.office_lat = 0.0 self.staff.office_longit = 0.0 self.staff.save() self.org_staff.append(self.staff) # IntegrityError: column username is not unique # provider_name = "".join(["Pravider1_", str(i)]) # pro = create_user(provider_name, 'Provider', 'P', 'demo', uklass=Provider) # self.org_providers.append(pro) self.user = create_user(get_random_username(), 'staff', 'S', 'demo') staff = OfficeStaff() staff.user = self.user staff.office_lat = 0.0 staff.office_longit = 0.0 staff.save() self.staff = staff self.provider = create_user("Pravider2", 'Provider', 'P', 'demo', uklass=Provider) self.provider.save()